475,569 views
45 votes
45 votes
The program should determine the largest integer seen. what should xxx be, if the input values are any integers (negative and non-negative)? all variables are ints and have unknown initial values.

User Anyany Pan
by
3.1k points

1 Answer

21 votes
21 votes

Answer: See below.

largest = None

smallest = None

while True:

num = input("Enter a number: ")

if num == "done":

break

try:

num = int(num)

except:

print("Invalid input")

continue

if largest is None:

largest = num

elif num > largest:

largest = num

if smallest is None:

smallest = num

elif num < smallest:

smallest = num

print("Maximum is", largest)

print("Minimum is", smallest)

Step-by-step explanation:

The program should determine the largest integer seen. what should xxx be, if the-example-1
User Chad Johnson
by
3.3k points