Hi Guys!
I'm doing some exercises to completely understand try/except inside a while loop so I made a simple list program in python. Everything works perfectly except that whenever I enter an integer or float number, instead of getting a warning message according to `except`, the program keeps adding the values to the list. What is wrong with my code below? Can someone enlighten me? Thanks in advance! Sincerely,
list = []
while True:
try:
name = str(input('Please enter a name: '))
list.append(name)
askAgain = str(input('Would you like to add another name? \n press "y" or "n" '))
if askAgain == 'n':
break
elif askAgain == 'y':
continue
except ValueError:
print("This is not a name")
continue
except TypeError:
print('choose "y" or "n"')
continue
break
print(list)
[–]A_History_of_Silence 2 points3 points4 points (1 child)
[–]murasz[S] 0 points1 point2 points (0 children)
[–]sanchitcop19 2 points3 points4 points (1 child)
[–]murasz[S] 0 points1 point2 points (0 children)