165k views
1 vote
Pls help me solve.

Enter a number: 50
Enter a number: 11
Enter a number: 66
Enter a number: 23
Enter a number: 53

Sum: 203
Numbers Entered: 5

Pls help me solve. Enter a number: 50 Enter a number: 11 Enter a number: 66 Enter-example-1
User Slartidan
by
8.5k points

1 Answer

5 votes

Answer:

Here's an example program in Python that should accomplish the task you described:

```

sum = 0

count = 0

while True:

num = input("Enter a number: ")

if num == "":

break

sum += float(num)

count += 1

if sum > 200:

print("Sum:", sum)

print("Numbers Entered:", count)

break

```

This program initializes two variables `sum` and `count` to zero. It then enters an infinite loop that repeatedly asks the user to input a number. The program checks if the input is an empty string, indicating that the user has finished entering numbers, and breaks out of the loop if so.

Otherwise, the program adds the input number to the sum variable, increments the count variable, and checks if the sum is greater than 200. If it is, the program prints out the sum and count, and breaks out of the loop.

Note that this program assumes that the user will only input numbers, and not any other characters. If the user inputs invalid data, the program will raise an error.

User Dogan Askan
by
8.4k points

No related questions found