Question

What kind of error does this program contain?

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

print("You are " + age + " years old.")

(1 point)
Responses

division by zero

division by zero

syntax error

syntax error

logic error

logic error

data type mismatch

data type mismatch
Skip to navigation

1 answer

The program contains a data type mismatch error.

The issue arises on the line:

print("You are " + age + " years old.")

Here, age is an integer (the result of int(input(...))), but the + operator is being used to concatenate it with a string. This will result in a TypeError because you cannot directly concatenate a string and an integer in Python.

To fix this, you could convert age back to a string using str(age), like this:

print("You are " + str(age) + " years old.")

So the correct answer is data type mismatch.

Similar Questions
  1. What kind of error does this program contain?age = int(input("Enter your age: ")) print("You are TE + age + years old.") (1
    1. answers icon 1 answer
  2. What kind of error does this program contain?age = int(input("Enter your age: ")) print("You are + str(age) " years old.") (1
    1. answers icon 1 answer
  3. What kind of error does this program contain?age = int(input("Enter your age: ")) print("You are " + str(age) " years old.") (1
    1. answers icon 1 answer
  4. What kind of error does this program contain?age = int(input("Enter your age: ")) print("You are " + age + " years old.") (1
    1. answers icon 1 answer
more similar questions