如何对类进行排序以匹配特定的特征



因此,基本上对python和整体编码都是新的。开始构建我的第一个项目。我学了一些OOP课程,但我需要一些帮助。我对一个项目的想法是根据用户输入显示特定种类的蘑菇,如蘑菇的菌盖颜色、鳃的颜色、栖息地等。我是处理类还是需要开始学习数据库。我能完成我的目标是多么困难啊。例如输入为:黄色、白色、森林输出需要是具有相同特征的蘑菇列表。我知道课堂是如何运作的,但我似乎在这里碰壁了

我建议您使用字典以及阅读python中字典和列表的文档,但这里有一个想法:

mushrooms_college = {'name':['Ganoderma lucidum','Amanita phalloides'],'color':['red and yellow', 'red and black']}
color_mushroom = input('what is the color? ')
values_colors_mushrooms = list(mushrooms_college['color'])
index = values_colors_mushrooms .index(color_mushroom)
mushrooms_college['name'][index]

最新更新