Editor

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 lesson

This 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 feet

You 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

All Python exercises · 50 practice problems · Python Fundamentals quiz