-
Notifications
You must be signed in to change notification settings - Fork 0
/
die.py
58 lines (41 loc) · 1.92 KB
/
die.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
46
47
48
49
50
51
52
53
54
55
56
#Make a die function that returns a random number
from random import randint #import python function random-you have to tell it to do this. Randint takes two variables and picks one randomly.
def die (): #defines function die
roll=randint (1,6)
print(roll)
#Make a function called custom_die that takes a range and prints a random #number in that range
def custom_die(num1, num2): #num1 and num2 are the buckets you hold your variables in
roll=randint(num1, num2) #this tells computer to pick anything between
#determine if max or min
if roll == num1: #num1 is min in range
print(num1, "Critical fail!") #feeding print statement multiple arguments.
#Can also be if roll == num1:
#print("{r} Critical fail".format(r=roll))
# do the dot format like this, instead of commas or pluses "{name} is {age} and is from
#{place}".format(name=name, age=age, place=place)
elif roll == num2: #num2 is max in range
print(num2, "Critical hit!")
else: #if neither, print only the number.
print(roll)
def main():
print("Welcome to Die Roller. Enter q to exit.")
entree = "" #empty string, must make it not equal q.
while entree != "q":
entree = input("How many dice do you want to roll?")
if entree.lower() == "q": #this converts all input to lowercase. .upper also a thing
#exit the program. can avoid repeat in line 34 with a function.
exit()
#Convert input string to integer. Called casting.
#it's not q, it has to be total rolls, assign to total_rolls
total_rolls= int(entree)
#How big are the dice? Can nest int and input, to convert from string.
entree = input("How many sides on the dice?")
if entree == "q":
#exit the program
exit()
#already checked to see entree wasn't q, now turn that entree into an int
max_num= int(entree)
#Roll that many dice. You'll need a FOR LOOP here.
for something in range(0,total_rolls):
custom_die(1, max_num) #this prints the number
main()