How can I make the user keep typing in number?

I want to make it so when the user type in a string, it will keep asking them to type in a number or an integer. https://code.sololearn.com/cu0R3eonkX6E/?ref=app

2/10/2020 5:38:21 PM

kindon T

5 Answers

New Answer


My favourite pattern looks about like this: while True: inp = input() if inp.isdigit(): break


https://code.sololearn.com/caib2ngcNs9x/?ref=app But it doesn't work here at SL because the user input can be entered only once.


while True: try: num = float(input('Number: ')) break except: print('wrong input!') continue print(num)


It is not possible on SL sorry