0% found this document useful (5 votes)
2K views

4.18 LAB Smallest and Largest Numbers in A List

The document describes a program that takes user input of multiple integers separated by lines and adds them to a list as long as they are greater than zero. It then outputs the smallest and largest integers found in that list. The program takes the first input as the initial minimum and maximum values, then compares each subsequent input to update minimum and maximum as needed, before printing the final minimum and maximum values separated by a space.

Uploaded by

CHRIS D
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (5 votes)
2K views

4.18 LAB Smallest and Largest Numbers in A List

The document describes a program that takes user input of multiple integers separated by lines and adds them to a list as long as they are greater than zero. It then outputs the smallest and largest integers found in that list. The program takes the first input as the initial minimum and maximum values, then compares each subsequent input to update minimum and maximum as needed, before printing the final minimum and maximum values separated by a space.

Uploaded by

CHRIS D
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

4.

18 LAB: Smallest and largest numbers in a list


Write a program that reads a list of integers into a
list as long as the integers are greater than zero,
then outputs the smallest and largest integers in
the list.

Ex: If the input is:

10
5
3
21
2
-6
the output is:

2 21
You can assume that the list of integers will have
at least 2 values.
n = int(input())

min = n

max = n

while(n>0):

if(min>n):

min = n

if(max<n):

max = n

n = int(input())

print(min, max)

You might also like