Bird
0
0

Given data = ['10', '20', '30'], which code converts all to integers and sums them?

hard📝 Application Q9 of 15
Python - Variables and Dynamic Typing
Given data = ['10', '20', '30'], which code converts all to integers and sums them?
Atotal = sum(str(x) for x in data)
Btotal = sum(float(x) for x in data)
Ctotal = sum(int(x) for x in data)
Dtotal = sum(bool(x) for x in data)
Step-by-Step Solution
Solution:
  1. Step 1: Convert each string to integer

    int(x) converts strings like '10' to integer 10.
  2. Step 2: Sum all converted integers

    sum() adds all integers to get total.
  3. Final Answer:

    total = sum(int(x) for x in data) -> Option C
  4. Quick Check:

    Sum integers converted from strings [OK]
Quick Trick: Use sum(int(x) for x in list) to sum string numbers [OK]
Common Mistakes:
MISTAKES
  • Using float() when int() needed
  • Using str() returns strings, not numbers
  • Using bool() sums True/False values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes