Ask Question
13 April, 18:55

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.

+1
Answers (1)
  1. 13 April, 19:16
    0
    mylist = [] #Create an empty list

    i = 0 # initialize counter to 0

    b = int (input ("Enter into list: ")) # prompt user for input

    while not (b = = 0) : #test if input is not 0

    mylist. append (b) #insert input into list if it's not 0

    i = i + 1 #increment counter

    b = int (input ("Enter into list: ")) #prompt user for input

    #save sorted list in a newlist

    newlist = sorted (mylist)

    #print element on separate lines

    for ind in newlist:

    print (ind)

    #End of program

    Explanation:

    Line 1 of the program creates an empty list named mylist

    Line 2, initializes a counter variable i to 0

    Line 3 prompts user for input

    Line 4 to 7 iterates until user input is 0

    Line 9 sorts the list and saves the sorted list into a new list

    Line 11 & 12 prints the each element of the list on separate lines
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a program that reads integers from the user and stores them in a list. Your program should continue reading values until the user ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers