Answer to Question #279518 in Python for NeroTamil

Question #279518

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



1
Expert's answer
2021-12-14T07:19:40-0500
# 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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS