I have a question about how to warn user to input 'string' instead of 'integer'
but it seems that I cannot iterate the loop if user input is integer and ask again please enter string
Example from here
http://pythontutor.com/visualize.html#mode=edit
catNames = []
while True:
print("Enter the name of cat " + str(len(catNames) + 1) + ' (Or enter nothing to stop):' )
while True:
name = input()
try:
name = int(name)
except ValueError:
print('please enter string')
pass
if name == '':
break
catNames = catNames + [name] # list concatenation
print('The cat names are :')
for i in catNames:
print(' ' + i)
namewill never break the outer while loop because input name is in another scope and the inner loop has nothing that breaks it, because if it gets aValueErrorthen it passes and runs again.