I would like to input values into my_list. However, the values should only be integers. Also, if any other key than 'q' is entered, the input should show a message. However, if q is entered, the program should stop taking input and print the list.
In this program, the validation for q isn't working. Any other value than integer throws the same message 'Enter integer values only'. This happens even when the input is 'q'. Why does this happen? And what is the solution for this?
my_list = []
print("Enter q once done")
while True:
try:
my_list.append(int(input()))
except:
if input == 'q':
break
else:
print("Give integer values only")
continue
print(my_list)
inputis a built-in function, it is not a pointer to the input entered by the user. Just store it in a variable.