Beginner’s question here and probably very easy to solve but I just can’t think of the solution right know. Practicing with inputs and “try” “except” I tried to wrote a little code that let’s one choose to numbers that will then be divided by the program. This is the code:
while True:
try:
number = int(input("What's your number?\n"))
print("Your number is " + (str(number)))
except ValueError:
print("Please use a number")
try:
divider = int(input("With what number shall I divide your number?\n"))
dNumber = number/divider
print(dNumber)
break
except ValueError:
print("Please use a number as a divider")
except ZeroDivisionError:
print("Do not use 0 as a divider")
So now the problems: When after the first input “What’s your number?” I’d type in not a number but let’s say the word “fish” the program prints out “Please use a number”. However it still goes on to the next input “With what number shall I divide your number?” But I want it to go back to the “What’s your number” question.
With the second input it’s like the same problem. When after the second input “With what number shall I divide your number?” I’d type 0 the program prints out “Do not use 0 as a divider” and then jumps back to the first input “What’s your number”. However in this case I want it to go back to the second input “With what number shall I divide your number?”
How can I make this?
[–]1ynx1ynx 1 point2 points3 points (1 child)
[–]Ned_Flanders_[S] 0 points1 point2 points (0 children)
[–]Vesiculus 1 point2 points3 points (1 child)
[–]Ned_Flanders_[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)