Module 1: Advanced Practice

Deepen your understanding of types, conversions, and variable manipulation.

Type Conversion Challenge

Sometimes you need to change a value's type. Example: combining a number with text requires converting the number to a string first. Which function converts a value to an integer?

user_age_str = "25" # Age stored as text
years_until_next_decade = 10 - ???(user_age_str) % 10 # Calculation needs integer
print(years_until_next_decade)

Select the function needed to make the calculation work:

String Concatenation

You can combine strings using the `+` operator. To combine strings with other types (like numbers), you must first convert the number to a string using `str()`. Try creating a welcome message below.

name = "Bob"
visits = 5
# Your code below
Output will appear here...

Variable Reassignment

Variables can be assigned new values, even of different types (dynamic typing)! Predict the *final* output of the code below.

data = 10
data = data + 5 # data is now 15
data = "Result: " + str(data) # data is reassigned to a string
print(data)

What will be printed?

Variable Naming Conventions

Python prefers `snake_case` for variable names (lowercase words separated by underscores). Click the variable name(s) below that follow this convention.

Advanced Variable Missions

Apply your knowledge of types, conversion, and concatenation!

Mission 1: String to Integer Calc

Imagine `input()` gives you a string. Convert the `score_str` to an integer, add 10 to it, and store the result in `final_score`. Then print `final_score`.

score_str = "150" # Simulating input
# Your code below

Mission 2: Formatted Report

Create a `report` string using the variables provided. The final string should be exactly: "Sensor: temp_sensor Reading: 22.5 C". Remember to convert the float!

sensor_name = "temp_sensor"
reading_value = 22.5
# Your code below

Mission 3: Reassign and Combine

Reassign the `status` variable to the string "Updated". Then, create a `log_entry` string combining the original `item_id` (as a string) and the *new* `status`, like: "ID: 101 Status: Updated". Print the `log_entry`.

item_id = 101
status = "Pending"
# Your code below

Advanced Practice Complete!

Great job solidifying your understanding of types and variables! You handled conversions and reassignments well.
Watch the video lesson for more context, or return to the course menu.