livepython.net

150. Fix a TypeError in a Birthday Message

EasyExceptions

Overview

Read the error, find the line, and fix the cause.

Problem Statement

The program reads a name and an age, and should print a birthday message. But it crashes with:

TypeError: can only concatenate str (not "int") to str

Fix it, so that for Sunny and 13 it prints:

Happy birthday, Sunny! You are 13 today.

Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Input

One value per line, in this order: the name, then the age. Example:

Sunny
13

Output

The output for that example:

Happy birthday, Sunny! You are 13 today.

The tests try 3 different inputs.

Learn this firstChapter 17 · Python Exceptions: Read Errors and Know Their Types
solution.py
name = input()
age = int(input())
print("Happy birthday, " + name + "! You are " + age + " today.")

EXPECTED OUTPUT

1Happy birthday, Sunny! You are 13 today.

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.