Fix the Bug: String + Number Crash
Beginner · Fix the bug · from Python Variables and Data Types: A Practical Introduction
From the lesson: Python Variables and Data Types: A Practical Introduction
Imagine you're shipping a package. You fill out a label that asks for the weight. You write "heavy" instead of a number. The shipping system crashes - it can't calculate a price from the word "heavy."
Read the lessonThis code is supposed to print a user's profile summary, but it crashes with a TypeError. Fix the code so it prints:
Name: Alice
Age: 25
Height: 5.6 feetYou may fix it any way you like (f-strings, str() conversion, etc.).
name = "Alice"
age = 25
height = 5.6
print("Name: " + name)
print("Age: " + age)
print("Height: " + height + " feet")
More Variables and Data Types exercises
- Create Variables of Each TypeBeginner
- Temperature ConverterBeginner
- Predict the Output: Truthy or Falsy?Beginner
- Swap Two VariablesBeginner
- Type Conversion ChainBeginner
All Python exercises · 50 practice problems · Python Fundamentals quiz