0% found this document useful (0 votes)
100 views

Python

The document describes a Python program that repeatedly prompts a user to enter integer numbers until the user enters "done". It prints the largest and smallest numbers entered, and handles invalid input by printing an error message and skipping non-integer values. The program defines variables to track the largest and smallest numbers, uses a while loop to repeatedly get input, converts values to integers, updates the tracking variables, prints numbers, and breaks once "done" is entered.

Uploaded by

Ricardo Mejía
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views

Python

The document describes a Python program that repeatedly prompts a user to enter integer numbers until the user enters "done". It prints the largest and smallest numbers entered, and handles invalid input by printing an error message and skipping non-integer values. The program defines variables to track the largest and smallest numbers, uses a while loop to repeatedly get input, converts values to integers, updates the tracking variables, prints numbers, and breaks once "done" is entered.

Uploaded by

Ricardo Mejía
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Lineas de Programacion

5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is
entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number
catch it with a try/except and put out an appropriate message and ignore the number. Enter the numbers from the
book for problem 5.1 and Match the desired output as shown.

largest = None
smallest = None
while True:
try:
i = raw_input("Enter a number: ")
num= int(i)
if num>largest:
largest=num
if num<smallest:
smallest=num
print num
except:
if num == "done" : break
else:
print"invalid input"
print "Maximum is", largest
print "Minimum is", smallest
Desired output

invalid input
Maximum is 7
Minimum is 4

You might also like