Reputation: 821
I need some help on returning to the top of the loop in python I know about the break statement but I do not know if its helpful at all.
Here is my code:
import random
Which_Dice= input("What dice do you want? 4,6 or 12")
if input(Which_Dice)!=("4","6","12"):
print("Please input the number 4,6 or 12")
elif int(Which_Dice)== 4:
print(int(Which_Dice), "sided dice thrown", "score",random.randint(0,5))
elif int(Which_Dice)== 6:
print(int(Which_Dice), "sided dice thrown", "score",random.randint(0,7))
elif int(Which_Dice)==12:
print(int(Which_Dice), "sided dice thrown", "score",random.randint(0,13))
Upvotes: 0
Views: 621
Reputation: 11
There is no loop in your code but maybe this will help?
def callme():
Which_Dice= input("What dice do you want? 4,6 or 12")
.
.
callme()
callme()
or look into for or while loops.
Upvotes: 1
Reputation: 20359
If what you want to do is run that part of your program over and over (effectively jumping back up to the top), you can use a while true loop to accomplish that:
import random
while True:
Which_Dice= input("What dice do you want? 4,6 or 12")
if input(Which_Dice)!=("4","6","12"):
print("Please input the number 4,6 or 12")
elif int(Which_Dice)== 4:
print(int(Which_Dice), "sided dice thrown", "score",random.randint(0,5))
elif int(Which_Dice)== 6:
print(int(Which_Dice), "sided dice thrown", "score",random.randint(0,7))
elif int(Which_Dice)==12:
print(int(Which_Dice), "sided dice thrown", "score",random.randint(0,13))
Upvotes: 1