Skip to content

Commit

Permalink
Creating A Rolling Dice mechanism with Random Module
Browse files Browse the repository at this point in the history
The user will inputing the number between 1 and 6 and the program will generate a result of the dice in a list
  • Loading branch information
ibrahimfe committed May 5, 2023
1 parent 93ba3a7 commit 8d184ee
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
16 changes: 16 additions & 0 deletions dice_rolling/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
}
]
}
7 changes: 7 additions & 0 deletions dice_rolling/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"."
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
39 changes: 39 additions & 0 deletions dice_rolling/dice_rolling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Import Module Section
import random

# Constant
DICE = {1, 2, 3, 4, 5, 6}


# Main Program
def main():
num_dice_count = input("How much dice you want to roll? : ")
num_dice = parse_input(num_dice_count)

print(roll_dice(num_dice))


# Determine The input
def parse_input(input_string):
if int(input_string) in DICE:
return int(input_string)
else:
print("Please enter a number between 1 and 6")
raise SystemExit(1)


# Rolling the dice with random module
def roll_dice(num_dice):
roll_result = []
for i in range(num_dice):
a = random.randint(1, 6)
roll_result.append(a)
return roll_result


# Generating Ascii Letters for Text-based user Interface
def generate_face_dices_diagram():
pass


main()

0 comments on commit 8d184ee

Please sign in to comment.