Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- current_year = 2016
- year_of_birth = int(raw_input('Enter Year Of Birth: '))
- age = current_year - year_of_birth
- mytext = 'You are %s years old.'
- print(mytext % age)
- if age < 18:
- print('YOU SHALL NOT PASS!')
- else:
- print('Welcome To The Portal.')
- from datetime import date
- current_year = date.today().year
- def ask_for_birth_year():
- while True:
- try:
- return int(raw_input('Enter Year Of Birth: '))
- except ValueError:
- print('This is not a number, try again.')
- def ask_for_birth_year():
- while True:
- try:
- nb = int(raw_input('Enter Year Of Birth: '))
- if nb < 0: # can be any condition you want, to say 'nb' is invalid
- print('Invalid year')
- else: # if we arrive here, 'nb' is a positive number, we can stop asking
- break
- except ValueError:
- print('This is not a number, try again.')
- return nb
- mytext = 'You are %d years old.'
- if __name__ == '__main__':
- # do stuff
- #at the beginning
- LIMIT_AGE = 18
- #your 'if' statement
- if age < LIMIT_AGE:
- ...
- from datetime import date
- LIMIT_AGE = 18
- def ask_for_birth_year():
- while True:
- try:
- nb = int(raw_input('Enter Year Of Birth: '))
- if nb < 0:
- print('Invalid year')
- else:
- break
- except ValueError:
- print('This is not a number, try again.')
- return nb
- def print_message(age):
- mytext = 'You are %d years old.'
- print(mytext % age)
- if age < LIMIT_AGE:
- print('YOU SHALL NOT PASS!')
- else:
- print('Welcome To The Portal.')
- if __name__ == '__main__':
- year_of_birth = ask_for_birth_year()
- current_year = date.today().year
- age = current_year - year_of_birth
- print_message(age)
- from datetime import date
- current_year = date.today().year
- year_of_birth = int(raw_input('Enter Year Of Birth: '))
- age = current_year - year_of_birth
- print('You are %s years old.' % age)
- if age < 18:
- print('YOU SHALL NOT PASS!')
- else:
- print('Welcome To The Portal.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement