sides=int(input("Please enter the amount of sides on the dice: "))
times=int(input("Please enter the number of times you want to repeat: "))
I want to repeat those two lines until the user input an int number for each request.
Thanks
sides=int(input("Please enter the amount of sides on the dice: "))
times=int(input("Please enter the number of times you want to repeat: "))
I want to repeat those two lines until the user input an int number for each request.
Thanks
Reading loosely,
def get_int(prompt):
while True:
try:
return int(input(prompt))
except ValueError: # wasn't an int
pass
sides = get_int("Please enter the amount of sides on the dice: ")
times = get_int("Please enter the number of times you want to repeat: ")
but if you strictly want to repeat both statements until both get an int value,
while True:
s1 = input("Please enter the amount of sides on the dice: ")
s2 = input("Please enter the number of times you want to repeat: ")
try:
sides = int(s1)
times = int(s2)
break
except ValueError:
pass
sides=0;times=0
while(sides == 0 and times == 0):
sides=int(input("Please enter the amount of sides on the dice: "))
times=int(input("Please enter the number of times you want to repeat: "))