If you receive non-numeric characters to create the list, you will be prompted again, but the code will return to the beginning. How can I ask you to re-enter the part where the error occurred?
while True:
try:
num1=int (input ("first digit input")
num2=int (input ("second digit input")
num3=int (input ("third digit")
except ValueError:
print (not a number). Re-enter.")
def integer_input(msg):
while True:
try:
n = int(input(msg))
break
except ValueError:
print ("Enter an integer")
return n
num1 = integer_input ("Enter the first digit :")
I think we can do it like this.
© 2024 OneMinuteCode. All rights reserved.