How to sum numbers from input?
问题 I am working on the following problem. Write a program that continually prompts for positive integers and stops when the sum of numbers entered exceeds 1000. But my code stop early if a negative integer is entered. The numbers will not sum. My code: x = int(input("Enter an integer:")) total = 0 sum = 0 while (0 <= x): if sum <= 1000: x += 1 sum += (int(input("Enter an integer:"))) elif sum >= 1000: break 回答1: x = 0 total = 0 sum = 0 while sum <= 1000: x = int(input("Enter an integer:")) if x