-1

I wanna do this but i got 3 issues a s I commented:

age = input("How old are you ? ")
if type(age) != int: # this line does't work
    restart = input("invalid input. Do you want to restart ? [y/n]")
    if restart == "y" :
        #restart the program
    else :
        #exit the program

1 Answers1

1

Use a try-except block to check the conversion of the input (str) to int

age = input("How old are you ? ")
try:
    age = int(age)
except ValueError:
    restart = input("invalid input. Do you want to restart ? [y/n]")
    if restart == "y" :
        #restart the program
    else :
        #exit the program
frab
  • 1,162
  • 1
  • 4
  • 14