LearnFrenzy
Sign in Take a free test

Python Basics and Syntax · Find the Error · Question 8

Error: joining a string and a number Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 8 Back to Exercise

The program below stops with an error. Which statement correctly describes the problem?

main.py
age = 21
print("Age: " + age)
  • A NameError: age is not defined
  • B SyntaxError: missing comma
  • C It prints Age: 21
  • D TypeError: + cannot join a str and an int; use str(age), a comma or an f-string Correct
Correct Answer: Option D

Python never converts types silently here. Fixes: "Age: " + str(age), print("Age:", age) or f"Age: {age}".

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links