Python Programming - Console Input/Output - Discussion

Discussion Forum : Console Input/Output - General Questions (Q.No. 71)
71.
How can you prompt the user to enter a series of numbers until they enter a negative number, and then print the sum of the positive numbers?
positive_sum(get_positive_numbers())
sum_positive_numbers(input("Enter numbers (negative to stop): "))
total = 0; while True: num = int(input("Enter a number: ")); if num < 0: break; total += num; print(total)
print("Sum of positives:", calculate_positive_sum(get_input_numbers()))
Answer: Option
Explanation:
To prompt the user to enter a series of numbers until they enter a negative number, and then print the sum of the positive numbers, use a while loop with a break condition.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.