Answer to Question #349712 in Python for Darkninja

Question #349712

# Accept integer number and store it to a list until user input is 0.

# Display the content of the list and size of the list.

# Display the highest and lowest numbers.


1
Expert's answer
2022-06-10T08:30:19-0400
# Accept integer number and store it to a list until user input is 0.
numbers = []
number_gathering = True
while number_gathering is True:
    try:
        current_number = int(input())
        while current_number != 0:
            print(current_number)
            numbers.append(current_number)
            current_number = int(input())
        number_gathering = False
    # If input is not an integer displays an error and continues execution
    except ValueError:
        print("ValueError: Value must be an integer!")
else:
    # Display the content of the list and size of the list.
    print("Content of list:", numbers)
    print("Size of list:", len(numbers))
    # Display the highest and lowest numbers if the list is not empty
    if len(numbers) != 0:
        print("Highest number of list:", min(numbers))
        print("Lowest number of list:", max(numbers))
    else:
        print("There are no highest and lowest numbers, because the list is empty") 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS