Skip to content

Instantly share code, notes, and snippets.

@cauesooouza
Created October 13, 2021 19:33
Show Gist options
  • Save cauesooouza/857f10f3df8c8ba1bed36b4d8ac838c5 to your computer and use it in GitHub Desktop.
Save cauesooouza/857f10f3df8c8ba1bed36b4d8ac838c5 to your computer and use it in GitHub Desktop.
Practice Python - Exercise 01 - Character Input
#Create a program that asks the user to enter their name and their age. Print out a message addressed to them that tells them the year that they will turn 100 years old.
#Extras:
#Add on to the previous program by asking the user for another number and printing out that many copies of the previous message. (Hint: order of operations exists in Python)
#Print out that many copies of the previous message on separate lines. (Hint: the string "\n is the same as pressing the ENTER button)
#first import 'datetime' to discover the current year
import datetime
def reaching_hundred():
#we will took the name from user
name = input('Enter your name: ')
print('Hello,',name)
#we will took the age from the user
age = input('Enter your age: ')
#if the user put something wrong, like 'tweny three' the code will blow up and we will receive 'TRACEBACK'
#to this doenst happen we will handling exceptions
try:
#int function convert string to integer, and that will verify if the user put 'tweeny' instead of '20'
age = int(age)
except:
#if user put wrong, the program will ask to put number and then reboot
print('Please put just number on age(ex: 23)')
reaching_hundred()
#here we will took the current year
year = datetime.datetime.now().year
#calculation to discover year that user will be hundred years
hundred_years = (year-age)+100
print('You will be 100 old in',hundred_years)
quit()
reaching_hundred()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment