Как разрешить пользователю добавлять или удалять новые элементы в списке?

Идиома Python для этого - newList = oldList[:]

0
задан Abdullah Alejel 24 March 2019 в 02:20
поделиться

1 ответ

Для добавления и удаления вы можете иметь цикл, который постоянно просит пользователя добавлять и удалять номера и отображать обновленную статистику, например,

.
while True:
    action = int(input("Input -1 if you want to add to the list again. Or -2 if you want to remove from the list"))

    if action == -1:
        print("Enter what you want to be added ")
        add = int(input(""))
        temperatureList.append(add)
        print(temperatureList)
        sm = sum(temperatureList)

        avg = sm / weather

        print("SUM = ", sm)

        print("AVERAGE = ", avg)
    elif action == -2:
        if len(temperatureList) > 1:
            del temperatureList[-1]
            print(temperatureList)
            sm = sum(temperatureList)
            avg = sm / weather
            print("SUM = ", sm)
            print("AVERAGE = ", avg)
        else:
            print("Everything removed from the list")
0
ответ дан Devesh Kumar Singh 24 March 2019 в 02:20
поделиться
Другие вопросы по тегам:

Похожие вопросы: