+ 1

Force to input whole number in python

Hi guys, how do i force user to input whole number? Example i want someone to put their exam score in the program of course it must be whole number right? Not 16 point something. So how?

10th Mar 2021, 12:06 AM
Kakai
Kakai - avatar
2 Antworten
+ 3
while True: inp = input() if inp.isdigit(): break print("you must enter a whole number") inp = int(inp)
10th Mar 2021, 12:14 AM
visph
visph - avatar
0
All right, thanks visph
10th Mar 2021, 12:15 AM
Kakai
Kakai - avatar