Skip to content

Instantly share code, notes, and snippets.

@Gwith
Created August 11, 2016 16:52
Show Gist options
  • Select an option

  • Save Gwith/0cbd6aa65b553e5d2d082dd3db3359c8 to your computer and use it in GitHub Desktop.

Select an option

Save Gwith/0cbd6aa65b553e5d2d082dd3db3359c8 to your computer and use it in GitHub Desktop.
# Calculate when user will be 100 years old
import datetime #import datetime to grab year.
def age():
name = input("What is your name?\n") #grab input of user 'name'
name = name.replace(name[0], name[0].upper()) #replace first letter with capitol
try:
age = int(input("What is your age?\n")) #grab user age and change to int
except ValueError:
print("You need to enter in a numerical digit")
now = datetime.datetime.now() #grab current date
year = str((now.year - age) + 100) #calculate user will be 100
print('Your name is ' + name + ' and your age is ' + str(age) +'.')
print(name + " will be 100 years old in the year " + year)
age()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment