186k views
5 votes
Write a program that reads integers from the user and stores them in a list. Your

program should continue reading values until the user enters 0. Then it should display
all of the values entered by the user (except for the 0) in order from smallest to largest,
with one value appearing on each line. Use either the sort method or the sorted
function to sort the list.

1 Answer

3 votes

Answer:

The program in Python is as follows:

numList = []

num = int(input())

while num != 0:

numList.append(num)

num = int(input())

numList.sort()

for num in numList:

print(num)

Step-by-step explanation:

This initializes the list

numList = []

This gets input from the user

num = int(input())

This loop is repeated until the user enters 0

while num != 0:

This appends the user input to the list

numList.append(num)

This gets another input from the user

num = int(input())

This sorts the list in ascending order

numList.sort()

This iteration prints the list elements, each on a line

for num in numList:

print(num)

User The Sheek Geek
by
3.3k points