-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdice.py
45 lines (37 loc) · 1.19 KB
/
dice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import random
import datetime
import os
os.system('cls' if os.name == 'nt' else 'clear')
while True:
# Init variables
total = 0
amountOfRolls = 0
# Ask how many times to roll
rolls = input("Roll Die x Times: ")
# Options for input
if(rolls == "q" or rolls == "quit"):
print("You have quit the program")
exit()
elif(rolls == "c" or rolls == "clear"):
os.system('cls' if os.name == 'nt' else 'clear')
# Roll dice
else:
try:
# Roll dice 'rolls' amount of times
for x in range(0, int(rolls)):
dice = random.randrange(1, 6, 1)
total += dice
amountOfRolls += 1
print(dice)
# Print results
print()
print(datetime.datetime.now())
print("Your total roll =", total)
print("Your average roll =", total/amountOfRolls)
print()
# Print this when there isn't a number entered
except ValueError:
print("Please enter a number")
# Print other errors
except Exception as e:
print(e)