Цель программы - спросить у пользователя, сколько предметов одежды они собирают в каждый день 3-х дневной (выходной) одежды, сделайте это снова во второй уикенд, затем сравните два выходных дня (одежда в день).Python typeerror int object not itable, проблема с функцией суммы (я думаю)
Вот мой код:
import math
num_clothes = int()
weekend_total = int()
weekend_avg = float()
total_clothes = int()
total_avg = float()
index = int()
index = 1
while index <= 2:
index = 1
while index <= 3:
num_clothes = int(input("How many articles of clothing did you collect today? "))
index = index + 1
weekend_total = sum(num_clothes)
weekend_avg = weekend_total/3
print("Total Collected:\t", weekend_total)
print("Weekend Average:\t", weekend_avg)
index = index + 1`1
total_clothes = sum(weekend_total)
total_avg = total_clothes/6
print("Total Number of Clothing Collected:\t", total_clothes)
print("Average Collected:\t", total_avg)
А вот ошибка я получаю:
Traceback (most recent call last):
File "G:\ITCS 1140\labs\python\lab 9.py", line 17, in <module>
weekend_total = sum(num_clothes)
TypeError: 'int' object is not iterable
Я пытаюсь сделать num_clothes в список и добавить все значения его с суммой (num_clothes).
, поэтому я просто попытался сделать второй, и я получил сообщение об ошибке: Traceback (последний последний звонок): Файл «G: \ ITCS 1140 \ labs \ python \ lab 9.py», строка 16, в num_clothes.append (int (ввод («Сколько предметов одежды вы собрали сегодня? "))) AttributeError: объект 'int' не имеет атрибута 'append' –
Вы изменили свой тип num_clothes на list() вместо int()? Я обновил этот пример. – coelhudo
hooray вы его исправили !!!! –