python_exercises/thinkcspy/Chapter-13-Exercises/readposint.py

11 lines
357 B
Python
Raw Normal View History

2023-12-13 09:43:40 -07:00
def readposint(num):
try:
val = int(num)
if val > 0:
2023-12-13 09:46:56 -07:00
print("You entered '{}'. That's a positive number!".format(val))
2023-12-13 09:43:40 -07:00
else:
2023-12-13 09:46:56 -07:00
print("'{}' is not a positive number.".format(val))
2023-12-13 09:43:40 -07:00
except Exception:
print("'{}' is not a number.".format(num))
readposint(input("Please enter a positive number: "))