我需要一个搜索算法的帮助,搜索海报根据其大小,颜色和不同的参数
print("Hello!, welcome to my Poster shop")
class Posters():
"""make a template for the posters"""
def __init__(self, size, name, colors, category):
"""Gives the poster some categories"""
self.size = size
self.name = name
self.colors = colors
self.category = category
poster1 = Posters(12, 'global_warming', 'blue', 'environment')
poster2 = Posters(11, 'volcano erruption', 'red', 'natural')
sizes = {poster1: poster1.size, poster2: poster2.size}
size_input = input("Search for different sized posters here: ")
for key, value in sizes.items():
if size_input == value:
print(sizes[value])
它没有显示结果,只是空白
input
函数返回一个string
^{<Poster
的cd3>}属性是int
。所以当你做if size_input == value:
的时候,你是在比较string
和int
,这会给你False
您需要将中的用户输入转换为
int
。用int
函数包装输入函数相关问题 更多 >
编程相关推荐