Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_non_negative_int(prompt):
- while True:
- try:
- value = int(input(prompt))
- except ValueError:
- print("Sorry, I didn't understand that.")
- continue
- if value < 0:
- print("Sorry, your response must not be negative.")
- continue
- else:
- break
- return value
- age = get_non_negative_int("Please enter your age: ")
- kids = get_non_negative_int("Please enter the number of children you have: ")
- salary = get_non_negative_int("Please enter your yearly earnings, in dollars: ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement