Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. def get_non_negative_int(prompt):
  2.     while True:
  3.         try:
  4.             value = int(input(prompt))
  5.         except ValueError:
  6.             print("Sorry, I didn't understand that.")
  7.             continue
  8.  
  9.         if value < 0:
  10.             print("Sorry, your response must not be negative.")
  11.             continue
  12.         else:
  13.             break
  14.     return value
  15.  
  16. age = get_non_negative_int("Please enter your age: ")
  17. kids = get_non_negative_int("Please enter the number of children you have: ")
  18. salary = get_non_negative_int("Please enter your yearly earnings, in dollars: ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement