Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. current_year = 2016
  2. year_of_birth = int(raw_input('Enter Year Of Birth: '))
  3. age = current_year - year_of_birth
  4. mytext = 'You are %s years old.'
  5. print(mytext % age)
  6. if age < 18:
  7. print('YOU SHALL NOT PASS!')
  8. else:
  9. print('Welcome To The Portal.')
  10.  
  11. from datetime import date
  12. current_year = date.today().year
  13.  
  14. def ask_for_birth_year():
  15. while True:
  16. try:
  17. return int(raw_input('Enter Year Of Birth: '))
  18. except ValueError:
  19. print('This is not a number, try again.')
  20.  
  21. def ask_for_birth_year():
  22. while True:
  23. try:
  24. nb = int(raw_input('Enter Year Of Birth: '))
  25. if nb < 0: # can be any condition you want, to say 'nb' is invalid
  26. print('Invalid year')
  27. else: # if we arrive here, 'nb' is a positive number, we can stop asking
  28. break
  29. except ValueError:
  30. print('This is not a number, try again.')
  31. return nb
  32.  
  33. mytext = 'You are %d years old.'
  34.  
  35. if __name__ == '__main__':
  36. # do stuff
  37.  
  38. #at the beginning
  39. LIMIT_AGE = 18
  40.  
  41. #your 'if' statement
  42. if age < LIMIT_AGE:
  43. ...
  44.  
  45. from datetime import date
  46.  
  47.  
  48. LIMIT_AGE = 18
  49.  
  50.  
  51. def ask_for_birth_year():
  52. while True:
  53. try:
  54. nb = int(raw_input('Enter Year Of Birth: '))
  55. if nb < 0:
  56. print('Invalid year')
  57. else:
  58. break
  59. except ValueError:
  60. print('This is not a number, try again.')
  61. return nb
  62.  
  63.  
  64. def print_message(age):
  65. mytext = 'You are %d years old.'
  66. print(mytext % age)
  67. if age < LIMIT_AGE:
  68. print('YOU SHALL NOT PASS!')
  69. else:
  70. print('Welcome To The Portal.')
  71.  
  72.  
  73. if __name__ == '__main__':
  74. year_of_birth = ask_for_birth_year()
  75. current_year = date.today().year
  76. age = current_year - year_of_birth
  77. print_message(age)
  78.  
  79. from datetime import date
  80. current_year = date.today().year
  81. year_of_birth = int(raw_input('Enter Year Of Birth: '))
  82. age = current_year - year_of_birth
  83. print('You are %s years old.' % age)
  84. if age < 18:
  85. print('YOU SHALL NOT PASS!')
  86. else:
  87. print('Welcome To The Portal.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement