0
0
Pythonprogramming~20 mins

Type conversion (int, float, string) in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Type Conversion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
ATypeError
B127.56
C127
D124
Attempts:
2 left
💡 Hint
Remember int() converts float to integer by dropping decimals.
Predict Output
intermediate
2:00remaining
String to int conversion with invalid input
What error does this code raise?
Python
x = '12.3'
y = int(x)
print(y)
AValueError
BTypeError
CSyntaxError
DNo error, prints 12
Attempts:
2 left
💡 Hint
int() cannot convert strings with decimal points directly.
Predict Output
advanced
2: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)
A"7.89"
B"78"
C"77"
D"79"
Attempts:
2 left
💡 Hint
int(val) drops decimals, round(val) rounds normally.
Predict Output
advanced
2: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)
A0 False
BTrue 1
CTypeError
D1 True
Attempts:
2 left
💡 Hint
Boolean True converts to 1 as int, and 'True' as string.
🧠 Conceptual
expert
2: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)
A[1, 2, 3]
B[1, 2.5, 3]
C[1, 3, 3]
DValueError
Attempts:
2 left
💡 Hint
float(x) converts string to float, int() drops decimals.