+1

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

+3

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

+2

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

+2

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

+1

It is not possible on SL sorry

+1

https://www.sololearn.com/discuss/1175214/?ref=app