Code Labs: Data Types

Master Typecasting, Strings, Integers, Reals and Booleans.

Interactive Engine

Use the interactive terminal below to test typecasting.

> Waiting to compile...

The Crucible

Prove your knowledge of casting and data types.

Bronze (Integers)

The String Trap

This program asks for your age and tries to add 1 to it. However, it crashes with a TypeError! Remember: input() always captures data as a String.

Task: Wrap the input() command inside an int() cast to fix the crash. For example: int(input("..."))

> Output will appear here...
Silver (Reals/Floats)

The Missing Decimals

This receipt calculator asks for a price. We cast it to an int(), but if the user types 10.50, it crashes because an Integer cannot hold a decimal point!

Task: Change the cast from int() to the correct Python keyword for a Real number: float(). Run the code and test it with a decimal number like 10.50.

> Output will appear here...
Gold (Booleans)

Boolean Logic States

Calculations that involve >, <, or == secretly output a Boolean. You can store a Boolean calculation directly inside a variable!

Task: Complete the boolean logic so that `access_granted` becomes True ONLY IF the `password` exactly equals "Secret123". The console must print exactly True when you do.

> Output will appear here...