Write a loop to read as many as numbers till you enter '-99' (if your input is -99 go out from the loop), and find a) how many numbers Less than 50. b) how many numbers Greater than 100. c) how many +ve numbers d) how many -ve numbers e) how many numbers in between 51 and 99.
时间: 2024-03-06 11:50:00 浏览: 72
Sure, here's the code to solve your problem:
```python
# Initializing variables
num_less_than_50 = 0
num_greater_than_100 = 0
num_positive = 0
num_negative = 0
num_between_51_and_99 = 0
# Loop to read input numbers
while True:
num = int(input("Enter a number (or -99 to exit): "))
if num == -99:
break
# Checking conditions
if num < 50:
num_less_than_50 += 1
elif num > 100:
num_greater_than_100 += 1
if num > 0:
num_positive += 1
elif num < 0:
num_negative += 1
if num > 51 and num < 99:
num_between_51_and_99 += 1
# Printing the results
print("Numbers less than 50:", num_less_than_50)
print("Numbers greater than 100:", num_greater_than_100)
print("Positive numbers:", num_positive)
print("Negative numbers:", num_negative)
print("Numbers between 51 and 99:", num_between_51_and_99)
```
You can run this code and enter numbers as many times as you want until you enter -99. The program will then display how many numbers are less than 50, greater than 100, positive, negative, and between 51 and 99.
阅读全文