0
0
Pythonprogramming~20 mins

Numeric values (int and float behavior) in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Numeric Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of mixed int and float arithmetic
What is the output of this Python code?
Python
result = 5 + 3.0 * 2
print(result)
A16.0
B11
C16
D11.0
Attempts:
2 left
💡 Hint
Remember that multiplying an int by a float results in a float.
Predict Output
intermediate
2:00remaining
Integer division vs float division
What is the output of this code snippet?
Python
a = 7 // 2
b = 7 / 2
print(a, b)
A3 3.5
B3.5 3
C3 3
D3.5 3.5
Attempts:
2 left
💡 Hint
// is floor division, / is true division.
Predict Output
advanced
2:00remaining
Float precision in arithmetic
What is the output of this code?
Python
x = 0.1 + 0.2
print(x == 0.3)
ATrue
BTypeError
CFalse
DSyntaxError
Attempts:
2 left
💡 Hint
Floating point numbers can have small precision errors.
Predict Output
advanced
2:00remaining
Type and value after mixed operations
What is the type and value of variable 'result' after running this code?
Python
result = int(4.7) + float(3)
A<class 'float'> and 7
B<class 'int'> and 7.0
C<class 'int'> and 7
D<class 'float'> and 7.0
Attempts:
2 left
💡 Hint
int(4.7) converts 4.7 to 4, float(3) converts 3 to 3.0.
🧠 Conceptual
expert
2:00remaining
Behavior of float('inf') in arithmetic
Which option correctly describes the output of this code?
Python
import math
x = float('inf')
y = x - 1000
print(y == x)
AFalse
BTrue
CRaises OverflowError
DRaises ValueError
Attempts:
2 left
💡 Hint
Infinity minus any finite number is still infinity.