M.Sc Python Programming Assignments
Assignment 1
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.
Code:
import datetime
def calculate_year_of_turning_100(age):
current_year = datetime.datetime.now().year
year_of_turning_100 = current_year + (100 - age)
return year_of_turning_100
name = input("Enter your name: ")
age = int(input("Enter your age: "))
year_of_turning_100 = calculate_year_of_turning_100(age)
message = f"Hello, {name}! You will turn 100 years old in the year {year_of_turning_100}."
print(message)
Output:
Enter your name: Ravi
Enter your age: 20
Hello, Ravi! You will turn 100 years old in the year 2103.