-
-
Save akshaynawale/097e373da6236acdb9b8e3be501a2353 to your computer and use it in GitHub Desktop.
Character input solution for practicepython.org exercise 1
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
import sys | |
from datetime import date | |
# taking persons name | |
name: str = input("Please enter your name: ") | |
age_str: str = input("Please enter your age in whole number (e.g. 28): ") | |
# validate age and convert it into integer | |
# removing the leading and traliing spaces | |
age_str = age_str.strip() | |
# try to convert the string into int | |
try: | |
age: int = int(age_str) | |
except ValueError: | |
print(f"unable to convert string {age_str} to integer value please provide valid integer age value") | |
sys.exit(1) | |
except: | |
print(f"unknown error occured when trying to convert age string {age_str} to integer") | |
sys.exit(1) | |
year = date.today().year | |
life_remaining = 100 - age | |
year = year + life_remaining | |
print(f"Name: {name}\nAge: {age}\nYou will be 100 years old in year: {year}\nDont Waste Your Time") | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment