Develop a program that takes as input a series of positive integers and outputs, starting from the second input, whether each input is larger than, less than or equal to the largest integer entered until that input. The program should terminate if a negative integer is provided.
In the example below, 3 is the first input. When the second input, 4, is entered, the program outputs “GREATER THAN 3” since 4 > 3, and waits for the next input. For the next input, 5, the program outputs “GREATER THAN 4” since 5 > 4 (the largest integer entered until that point). This continues until -1 is entered.
Eg:
Input:
3
4
5
6
1
6
-1
Output:
GREATER THAN 3
GREATER THAN 4
GREATER THAN 5
LESS THAN 6
EQUAL TO 6
# Python 3.9.5
start_number = int(input())
while True:
next_number = int(input())
if next_number < 0 or start_number < 0:
break
elif next_number == start_number:
print('EQUAL TO ' + str(next_number))
start_number = int(next_number)
elif next_number < start_number:
print('LESS THAN ' + str(start_number))
elif next_number > start_number:
print('GREATER THAN ' + str(start_number))
start_number = int(next_number)
Comments
Leave a comment