所以我陷入了家庭作业问题,如果到目前为止我所做的是错误的,我只需要一些指导或批评。但提示是";创建一个将创建服装对象的程序。衣服对象必须具有以下内容属性:最低温度、最高温度和正式级别。创建后一份衣服清单,输入当前温度和你要参加的活动的形式。然后,根据正式程度输出可接受的服装列表">
这就是我目前所拥有的,但我不知道我是否不能根据我的类实例将用户输入排序到列表中
class Clothing:
def __init__(self, fit: str, mintemp: int, maxtemp: int, formalitylvl: str):
self.fit = fit
self.mintemp = mintemp
self.maxtemp = maxtemp
self.formalitylvl = formalitylvl
if __name__ == '__main__':
listofclothes = []
listofclothes.append(Clothing("coat", 0, 60, "yes"))
listofclothes.append(Clothing("dress", 0, 100, "yes"))
listofclothes.append(Clothing("T-shirt", 40, 100, "no"))
listofclothes.append(Clothing("Hoodie", 0, 60, "no"))
listofclothes.append(Clothing("jean shorts", 60, 100, "no"))
catalog = int(input("please enter the number of clothing pieces you want to catalog: "))
for i in range(catalog):
str("please enter the clothing item: ")
int(input("Please enter the minimmum temp you would wear the item:"))
int(input("Please enter the maximum temp you would wear the item:"))
str(input("Is the item formal: "))
您走在了正确的轨道上!您应该将input
保存到变量中,而不是在循环时重置输入:
type = input(str("please enter the clothing item: "))
min_temp = int(input("Please enter the minimmum temp you would wear the item:"))
max_temp = int(input("Please enter the maximum temp you would wear the item:"))
is_formal = str(input("Is the item formal: "))
现在,loop
在衣服上检查哪个是正确的:
output_list = []
for item in listofclothes:
if (item.fit == type and item.mintemp == min_temp and item.maxtemp == max_temp and item.formalitylvl == is_formal):
output_list.append(item)
我已经删除了你的catalog
范围,因为你的作业中没有提到它。此外,这不是你应该循环的内容。你应该绕过衣服的list
!
编辑:为fit
添加了type
,因为我忘记了服装部分。