Type Conversion Chain
Beginner · Write the code · 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 lessonYou're given a string price_text containing "49" and an integer quantity of 3.
1. Convert price_text to an integer
2. Calculate the total (price times quantity)
3. Print the result in this exact format:
3 items at $49 each = $147 totalYou must use the original variables - don't hardcode the numbers in your print statement.
price_text = "49"
quantity = 3
# Step 1: Convert price_text to an integer
# Step 2: Calculate the total
# Step 3: Print the formatted result
More Variables and Data Types exercises
- Create Variables of Each TypeBeginner
- Temperature ConverterBeginner
- Predict the Output: Truthy or Falsy?Beginner
- Fix the Bug: String + Number CrashBeginner
- Swap Two VariablesBeginner
All Python exercises · 50 practice problems · Python Fundamentals quiz