Last active
July 30, 2019 16:10
-
-
Save therealprocyon/54aff74e3f51ea94da5db99155de3f44 to your computer and use it in GitHub Desktop.
Bad code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import datetime | |
def get_age_validation(): | |
while True: | |
try: | |
age = input("Enter your age as an integer: ") | |
age = int(age) | |
return age | |
except ValueError as e: | |
if not age: | |
print("Age value can't be empty.") | |
else: | |
print("Not a valid integer.\n\n" + | |
"Try to enter your age again\n\n") | |
def older_than_hundred(): | |
print("It seems you're 100 or older than 100.\n\n" + | |
"This program can't run in that case...") | |
exit(1) | |
def year_when_hundred(age, name): | |
year = datetime.date.today().year + (100 - age) | |
print("Hey, " + name + " the year you'll turn 100 is: " + str(year)) | |
def main(): | |
name = input("Enter your name: ") | |
age = get_age_validation() | |
if age >= 100: | |
older_than_hundred() | |
year_when_hundred(age, name) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment