crzcas

Counting people by age

Dec 29th, 2020
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. # Counting people by age.
  2. child = 0
  3. early = 0
  4. prime = 0
  5. mature = 0
  6. elderly = 0
  7. tries = 0
  8. print("Counting people by age.")
  9. print("Child = 0-14     early = 15-24     prime = 25-54     mature = 55-65     elderly = 66 and over")
  10. print("Enter age for 10 people.")
  11.  
  12. keep_running = False
  13. while (keep_running == False) and (tries < 10):
  14.     tries = tries + 1
  15.     age = int(input ("Enter age in years, person " + str(tries) + " > "))
  16.     if age > 0 and age <= 14:
  17.         child = child + 1
  18.     elif age > 14 and age <= 24:
  19.         early = early +1
  20.     elif age > 24 and age <= 54:
  21.         prime = prime + 1
  22.     elif age > 54 and age <= 65:
  23.         mature = mature + 1
  24.     elif age > 65:
  25.         elderly = elderly + 1
  26.     else:
  27.         print("I do not understand. Please run again")
  28.        
  29.  
  30. else:
  31.     print("child = " + str(child) + "   early = " + str(early) + "   prime = " + str(prime) + "   mature = " + str(mature) + "   eldery = " + str(elderly))
Advertisement
Add Comment
Please, Sign In to add comment