Feb-25-2018, 12:56 PM
I am solving a basic example using while loop in which user enters a number and program prints a countdown from that number to zero. But the catch is that program will inform you if user enters an unexpected number or string. For checking if input number in an integer i use //a = isinstance(x, int)//. The program is working only for condition if i enter a negative integer but not executing else statement when i entered float or string.
1 2 3 4 5 6 7 8 9 |
x = int ( input ( "Enter a positive integer for countdown" )) print (x) a = isinstance (x, int ) if a = = True and x> = 0 : while x! = 0 : x - = 1 print (x) else : print ( "Please enter a positive integer" ) |