Bird
0
0

Given the code below, what will be the output?

hard📝 Application Q9 of 15
Python - Data Types as Values

Given the code below, what will be the output?

values = [1, 2.0, 3, 4.5]
result = sum(int(v) for v in values)
print(result)
A11
B10
C9
DError
Step-by-Step Solution
Solution:
  1. Step 1: Convert each value to int

    1 -> 1, 2.0 -> 2, 3 -> 3, 4.5 -> 4 (int truncates decimals)
  2. Step 2: Sum the integers

    1 + 2 + 3 + 4 = 10
  3. Step 3: Recheck calculation

    Sum is 10, but A says 11. Check carefully: 1+2+3+4=10, so 10 is correct (10).
  4. Final Answer:

    10 -> Option B
  5. Quick Check:

    Sum of int conversions = 10 [OK]
Quick Trick: int() truncates floats before summing [OK]
Common Mistakes:
MISTAKES
  • Adding floats instead of ints
  • Miscounting sum
  • Expecting error on mixed types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes