Skip to content
Exercises · Q19

Q.Write a program that asks the user to enter their name and age. Print a message addressed to the user that tells the user the year in which they will turn 100 years old.

Punjab PsebTextbookSubjective· 3mImportance★★★★★est
94% · 46/49 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Read name and age, then print current-year + (100 − age) — a 19-year-old in 2026 turns 100 in 2107. Remember input() gives a string, so age needs int().

Two concepts combine here: input always returns a string (so the age must be converted with int() before arithmetic), and simple date arithmetic — if you are age now, you need 100 - age more years, so the target year is the current year plus that.

# In which year will the user turn 100?
import datetime

name = input("Enter your name: ")
age = int(input("Enter your age: "))

current_year = datetime.date.today().year
year_100 = current_year + (100 - age)

print(name + ", you will turn 100 years old in the year", year_100)

Key lines:

  • int(input(...)) — without it, 100 - age raises a TypeError (string minus int).
  • datetime.date.today().year fetches the real current year, so the program stays correct every year. (A simpler classroom version may hard-code, say, current_year = 2026 — acceptable, but it goes stale.)
  • name + ", you will…" — string concatenation personalises the message.

Sample run (example, assuming it is run in 2026):

Enter your name: Arnab
Enter your age: 19 …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.