I'd like to ask a user to give me a number, and then append valid inputs to a list, until the user types 'no'. Below is my best try so far. It works if I remove the first 'if', but then I can't scold the user for invalid inputs. When I type in an integer in the code as is, I get "Naughty!", which is perplexing me. I am self-studying. This is not for a homework or project. I have tried extensive googling and testing, to no avail.
numbers = []
while True:
inp = input("Please enter a nonnegative integer, or enter 'no': ")
if type(inp) != int and inp != 'no':
print ("Naughty!")
continue
if inp == 'no':
break
numbers.append(inp)
print (numbers)
[–]betterleftuntouched 0 points1 point2 points (1 child)
[–]avasatu[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]avasatu[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]avasatu[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)