Challenge - 5 Problems
Type Conversion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of mixed type conversions
What is the output of this Python code?
Python
a = '123' b = 4.56 c = int(float(a)) + int(b) print(c)
Attempts:
2 left
💡 Hint
Remember int() converts float to integer by dropping decimals.
✗ Incorrect
The string '123' is converted to float 123.0, then to int 123. The float 4.56 is converted to int 4 by dropping decimals. Sum is 123 + 4 = 127.
❓ Predict Output
intermediate2:00remaining
String to int conversion with invalid input
What error does this code raise?
Python
x = '12.3' y = int(x) print(y)
Attempts:
2 left
💡 Hint
int() cannot convert strings with decimal points directly.
✗ Incorrect
Trying to convert '12.3' directly to int causes ValueError because it's not a valid integer string.
❓ Predict Output
advanced2:00remaining
Output of chained conversions and operations
What is the output of this code?
Python
val = 7.89 result = str(int(val)) + str(round(val)) print(result)
Attempts:
2 left
💡 Hint
int(val) drops decimals, round(val) rounds normally.
✗ Incorrect
int(7.89) is 7, round(7.89) is 8, concatenated as strings gives '78'.
❓ Predict Output
advanced2:00remaining
Result of converting boolean to int and string
What is the output of this code?
Python
flag = True num = int(flag) text = str(flag) print(num, text)
Attempts:
2 left
💡 Hint
Boolean True converts to 1 as int, and 'True' as string.
✗ Incorrect
int(True) is 1, str(True) is 'True'. So print outputs: 1 True
🧠 Conceptual
expert2:00remaining
Understanding type conversion behavior
Which option correctly describes the output of this code snippet?
Python
data = ['1', '2.5', '3'] converted = [int(float(x)) for x in data] print(converted)
Attempts:
2 left
💡 Hint
float(x) converts string to float, int() drops decimals.
✗ Incorrect
Each string is converted to float then to int, so '2.5' becomes 2, resulting list is [1, 2, 3].