Computer Science, asked by akentengkelvin793, 2 months ago

Write a program that reads integers from the user and stores them in a list.
Yourprogram 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.

Answers

Answered by Equestriadash
0

Source c‎ode: [in Python]

\tt l\ =\ list()\\while\ True:\\{\ \ \ \ \ }n\ =\ int(in put("Enter\ an\ integer:\ "))\\{\ \ \ \ \ }if\ n\ !=\ 0:\\{\ \ \ \ \ }{\ \ \ \ \ }l.append(n)\\{\ \ \ \ \ }else:\\{\ \ \ \ \ }{\ \ \ \ \ }break\\for\ i\ in\ sorted(l):\\{\ \ \ \ \ }print(i)\\

Explanation:

A list is initialized to store the integers that will be entered by the user. A \tt while loop is passed to continuously retrieve integers from the user using the \tt in put() function, through the \tt int() data type. A conditional statement is passed to check if the integer is 0 or not. If it is not 0, it gets added to the list using the \tt append() method. If it is 0, the loop stops. Once the loop stops, a \tt for loop is passed to traverse through the sorted version of the list using the \tt sorted() function and the integers are displayed.

Answered by amanpanday2811
0

Answer:

List from user

Explanation-

Python Lists are just like dynamically sized arrays, declared in other languages (vector in C++ and Array List in Java). In simple language, a list is a collection of things, enclosed in [ ] and separated by commas. Lists are the simplest containers that are an integral part of the Python language. Lists need not be homogeneous always which makes it the most powerful tool in Python. A single list may contain Data Types like Integers, Strings, as well as Objects. Lists are mutable, and hence, they can be altered even after their creation. A list may contain duplicate values with their distinct positions and hence, multiple distinct or duplicate values can be passed as a sequence at the time of list creation. In order to access the list items refer to the index number. Use the index operator [ ] to access an item in a list. The index must be an integer. Nested lists are accessed using nested indexing.

Code-

# creating an empty list

lst = []

# number of elements as input

n = int(input("Enter number of elements : "))

# iterating till the range

for i in range(0, n):

   ele = int(input())

   lst.append(ele) # adding the element  

print(lst)

For more refers to-

https://brainly.in/question/7697308?referrer=searchResults

https://brainly.in/question/3380898?referrer=searchResults

#SPJ3

Similar questions