Knowee
Questions
Features
Study Tools

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. Note: for this exercise, the expectation is that you explicitly write out the year (and therefore be out of date the next year).

Question

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. Note: for this exercise, the expectation is that you explicitly write out the year (and therefore be out of date the next year).

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple program that does what you asked for:

import datetime

# Get the current year
current_year = datetime.datetime.now().year

# Ask the user for their name
name = input("Please enter your name: ")

# Ask the user for their age
age = int(input("Please enter your age: "))

# Calculate the year when the user will turn 100
year = current_year + (100 - age)

# Print out the message
print("Hello, " + name + ". You will turn 100 years old in the year " + str(year) + ".")

This program first gets the current year using the datetime module. Then it asks the user to enter their name and age. It calculates the year when the user will turn 100 by adding the difference between 100 and the user's age to the current year. Finally, it prints out a message telling the user when they will turn 100.

This problem has been solved

Similar Questions

Write a program that asks the user how old he/she is, currently, then prints out the year (e.g. 2059) when that same user will turn 100 years old. View keyboard shortcutsEditViewInsertFormatToolsTable12ptParagraph

Complete the main method in the AgeChecker class by Declaring and instantiating a Scanner objectPrint the "What is your age?" message to the consoleDeclaring the int age variable, assigning it the output of nextInt()If the value of age is greater than 40 then print "You are old". Otherwise, print "You are young"

In a school a class teacher wants to estimate age of the students in years, months and days. Date of birth will be given as input by the user in the format years-months-days. write a python program to estimate age of the student in the asked format. (Example: If the input is "1997-10-12", then the output of the program should be "26 years, 1 months, 13 days " )Input Format:Years-months-daysOutput Format:total years, total months, total days

Write a sample code, that initializes an instance of a person and sets it age to 18!

You are creating an application to display the user’s age at some time in the future. You begin typing your code:When you run the script, you get an error:You begin correcting your code:What should you type in the blank space? (Please type the value only ONCE as an answer. Please type your answer all in lower case. Example: word)1 point

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.