Reputation: 1
so im having an issue with my basic code as i cant get it to give me a second output. Basically, i have a code where i need to type a number between 1 and 20. if the input is outside of that range then i have got it to let me try again. the issue is, that when i try to input for the second attempt, it just ends the code after the input rather than giving feedback.ni will show u my code here.
number = int (input ("Write a number between 1 and 20"))
if number > 20:
input ("Please input again")
elif number < 1:
input ("Please input again")
else:
print ("thank you")
Upvotes: 0
Views: 37
Reputation: 123
You must using loop and condition. You can try this code...
number=int(input("Write a number between 1 and 20: "))
while (number>20 or number<1):
number=int(input("Please input again: "))
if number>=1 and number<=20:
print ("Thank you")
break
Upvotes: 2
Reputation: 2476
You can do an infinite loop and stop it, when you get the right input. Like this:
While True:
number = int (input ("Write a number between 1 and 20"))
if number > 20:
input ("Please input again")
elif number < 1:
input ("Please input again")
else:
print ("thank you")
break
Upvotes: 1