20.8k views
4 votes
Create a program that will find and display the largest of a list of positive numbers entered by the user. The user should indicate that he/she has finished entering numbers by entering a 0.

1 Answer

5 votes

Answer:

This program is written using Python Programming language,

The program doesn't make use of comments (See explanation section for line by line explanation)

Program starts here

print("Enter elements into the list. Enter 0 to stop")

newlist = []

b = float(input("User Input: "))

while not b==0:

newlist.append(b)

b = float(input("User Input: "))

newlist.sort()

print("Largest element is:", newlist[-1])

Step-by-step explanation:

This line gives the user instruction on how to populate the list and how to stop

print("Enter elements into the list. Enter 0 to stop")

This line creates an empty list

newlist = []

This line enables the user to input numbers; float datatype was used to accommodate decimal numbers

b = float(input("User Input: "))

The italicized gets input from the user until s/he enters 0

while not b==0:

newlist.append(b)

b = int(input("User Input: "))

This line sorts the list in ascending order

newlist.sort()

The last element of the sorted list which is the largest element is printed using the next line

print("Largest element is:", newlist[-1])

User Eric Holk
by
5.5k points