You have a list of numbers and you want to compute the sum of all positive numbers only. Which control structure can be most beneficial to achieve this?

  • Conditional Statement
  • For Loop
  • List Comprehension
  • While Loop
To compute the sum of all positive numbers in a list, a conditional statement can be most beneficial. You can iterate through the list of numbers and use a conditional statement to check if each number is positive before adding it to the sum. This allows you to selectively sum the positive numbers in the list.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *