Challenge - 5 Problems
Runtime Type Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of variable type changes?
Consider the following Python code where a variable changes its type during execution. What will be printed?
Python
x = 10 print(type(x)) x = 'hello' print(type(x))
Attempts:
2 left
💡 Hint
Remember that Python variables can hold values of any type and can change types anytime.
✗ Incorrect
Initially, x is assigned an integer 10, so type(x) is int. Then x is assigned a string 'hello', so type(x) becomes str.
❓ Predict Output
intermediate2:00remaining
What is the final type of variable after reassignment?
Look at this code where a variable is reassigned multiple times. What is the type of variable 'data' at the end?
Python
data = 3.14 print(type(data)) data = [1, 2, 3] print(type(data)) data = {'a': 1} print(type(data))
Attempts:
2 left
💡 Hint
Check the type after each assignment carefully.
✗ Incorrect
The variable 'data' first holds a float, then a list, then a dictionary. Each print shows the current type.
❓ Predict Output
advanced2:00remaining
What is the output when variable type changes inside a function?
What will this code print when a variable changes type inside a function?
Python
def change_var(): var = 5 print(type(var)) var = 'changed' print(type(var)) change_var()
Attempts:
2 left
💡 Hint
Variables inside functions behave the same way as outside in terms of type changes.
✗ Incorrect
Inside the function, var starts as int, then changes to str. Both types print accordingly.
❓ Predict Output
advanced2:00remaining
What error occurs when using variable before assignment after type change?
What error will this code raise when a variable is used before assignment after changing its type?
Python
x = 10 print(x) x = x + '5' print(x)
Attempts:
2 left
💡 Hint
Think about what happens when you add an integer and a string.
✗ Incorrect
Adding int and str causes a TypeError because Python cannot combine these types directly.
🧠 Conceptual
expert2:00remaining
How does Python handle variable types at runtime?
Which statement best describes how Python handles variable types during program execution?
Attempts:
2 left
💡 Hint
Think about how you can assign different types to the same variable name in Python.
✗ Incorrect
Python is dynamically typed, meaning variables can hold any type and change type during execution.