278,366 views
44 votes
44 votes
In pycharm, write a program that prompts the user for their name and age. Your program should then tell the user the year they were born. Here is a sample execution of the program with the user input in bold:

User Massimo Costa
by
2.5k points

1 Answer

16 votes
16 votes

Answer: See below

Step-by-step explanation:

#method to calculate the year of birth

def year_of_birth(age):

return 2020-age

if __name__=="__main__": # executing the code using this format if the file is run directly.

#Asking the user to enter his or her name

your_name = input("What is your name?")

#Asking user to enter his or her age

your_age = int(input("How old are you?"))

#Computing the year of birth using the fuction year_of_birth and store the result in your born in variable

your_born_in=year_of_birth(your_age)

#Displaying our results

print("Hello", your_name + "!", "You are born in " + str(your_born_in) + ".");

Happy coding!

User DHerls
by
2.9k points