Editor

Fix the ValueError

Beginner · Fix the bug · from How to Read Python Error Messages and Fix Common Bugs

From the lesson: How to Read Python Error Messages and Fix Common Bugs

When beginners see a red error message, their first instinct is panic. The screen fills with scary-looking text, and they think they broke something badly. But here's the truth: error messages are your best friend. They tell you exactly what went wrong and where.

Read the lesson

This code crashes when trying to convert a price string to an integer. Fix it so it prints:

Price in cents: 999

The price is "9.99" dollars, and we want to convert it to cents (multiply by 100 and round to an integer).

price_str = '9.99'
price_cents = int(price_str) * 100
print(f'Price in cents: {price_cents}')

More error messages exercises

All Python exercises · 50 practice problems · Control Flow quiz