简体   繁体   中英

How to append a number from user input to list?

total = 0
count = 0
average = 0
lst = []
while True:
    inp = input("Enter number: ")
    try:
        if inp == "done":
            break
        value = float(inp)
        total = total + value
        count = count + 1
        average = total / count
    except ValueError:
        print("Invalid Input")
print(total, count, average)

Starting from the above code, I want to write a program that saves to a list only the numbers read from input. For example, if the user inputs a sequence such as 3, 4, 7, abc, the resulting list should be: [3, 4, 7].

Thank you!

total = 0
count = 0
average = 0
lst = []
while True:
    inp = input("Enter number: ")
    try:
        if inp == "done":
            break
        value = float(inp)
        total = total + value
        count = count + 1
        average = total / count
    except ValueError:
        print("Invalid Input")
print(total, count, average)

Starting from the above code, I want to write a program that saves to a list only the numbers read from input. For example, if the user inputs a sequence such as 3, 4, 7, abc, the resulting list should be: [3, 4, 7].

Thank you!

total = 0
count = 0
average = 0
lst = []
while True:
    inp = input("Enter number: ")
    try:
        if inp == "done":
            break
        value = float(inp)
        total = total + value
        count = count + 1
        average = total / count
    except ValueError:
        print("Invalid Input")
print(total, count, average)

Starting from the above code, I want to write a program that saves to a list only the numbers read from input. For example, if the user inputs a sequence such as 3, 4, 7, abc, the resulting list should be: [3, 4, 7].

Thank you!

total = 0
count = 0
average = 0
lst = []
while True:
    inp = input("Enter number: ")
    try:
        if inp == "done":
            break
        value = float(inp)
        total = total + value
        count = count + 1
        average = total / count
    except ValueError:
        print("Invalid Input")
print(total, count, average)

Starting from the above code, I want to write a program that saves to a list only the numbers read from input. For example, if the user inputs a sequence such as 3, 4, 7, abc, the resulting list should be: [3, 4, 7].

Thank you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM