Jun-20-2018, 12:59 PM
1 import random
2
3
4 dice1 = random.randint(1,6)
5 dice2 = random.randint(1,6)
6 dice3 = random.randint(1,6)
7 dice4 = random.randint(1,6)
8
9
10 choise = input ("Welcome to my game! Wana play? yes/no")
11 if choise.lower() == "yes":
12 print ("-----------------------------------------")
13 elif choise != "yes":
14 print ("-----------------------------------------")
15 print ("Okay, goodbye.")
16 exit()
17
18
19 if dice1 == dice2:
20 print ("Unlucky, you scored 0.")
21 elif dice1 != dice2:
22 print ("You rolled a",dice1,"and a",dice2,"that makes",dice1 + dice2,)
23 choise2 = input ("Wana have one more go? yes/no")
24
25
26 if choise2.lower() == "yes":
27 print ("You rolled a",dice3,"and a",dice4,"that makes",dice3 + dice4,)
28 print ("All together that makes",dice1 + dice2 + dice3 +dice4,)
29 elif choise2 != "yes":
30 print ("Okay, goodbye.")
On line 16 I want to be able to end the program if they say no (so it doesn't carry on) without actually having to do exit(). What is the proper way I should do it?
2
3
4 dice1 = random.randint(1,6)
5 dice2 = random.randint(1,6)
6 dice3 = random.randint(1,6)
7 dice4 = random.randint(1,6)
8
9
10 choise = input ("Welcome to my game! Wana play? yes/no")
11 if choise.lower() == "yes":
12 print ("-----------------------------------------")
13 elif choise != "yes":
14 print ("-----------------------------------------")
15 print ("Okay, goodbye.")
16 exit()
17
18
19 if dice1 == dice2:
20 print ("Unlucky, you scored 0.")
21 elif dice1 != dice2:
22 print ("You rolled a",dice1,"and a",dice2,"that makes",dice1 + dice2,)
23 choise2 = input ("Wana have one more go? yes/no")
24
25
26 if choise2.lower() == "yes":
27 print ("You rolled a",dice3,"and a",dice4,"that makes",dice3 + dice4,)
28 print ("All together that makes",dice1 + dice2 + dice3 +dice4,)
29 elif choise2 != "yes":
30 print ("Okay, goodbye.")
On line 16 I want to be able to end the program if they say no (so it doesn't carry on) without actually having to do exit(). What is the proper way I should do it?