Lesson 23 +25 XP

Project 1: Greeting Machine

Project 1: Greeting Machine

Your first Python program: ask for a name and age, then greet the user with a message.

The goal

Read the user's name and age with input(), then print a friendly message that says how old they will be next year.

What you practice

  • print() output
  • input() user input
  • Casting with int()
  • f-string formatting

Starter code

name = input("What is your name? ")
age = int(input("How old are you? "))

next_year = age + 1
print(f"Hello {name}, next year you will be {next_year}!")

Step-by-step

  1. Run the starter and answer the questions.
  2. Add a line that also prints type(age) to see what input() returns.
  3. Wrap the age conversion in a try/except that catches a bad number.
  4. Print a goodbye message at the end.
  5. Re-run and test with both valid and invalid ages.

Checklist

  • [ ] The name is read with input()
  • [ ] The age is converted with int()
  • [ ] The message uses an f-string
  • [ ] Next year's age is correct
  • [ ] A try/except handles bad input
  • [ ] The program runs without errors

TL;DR

  • input() always returns text.
  • Convert with int() before doing math.
  • f-strings make messages clean.