0
Можете пожалуйста объяснить в чем проблема и если знаете то предложите свой укороченный вариант
class Shop: def __init__(self, price, firm, type): self.price = price self.firm = firm self.type = type XP1374=Shop(6999, "Samurai","true") x=input("price or firm or type: ") if x == price: print(XP1374.price) elif x ==firm: print(XP1374.firm) elif x ==type: print(XP1374.type)
1 Resposta
0
Trotsko Mykola In if-elif you compare 'x' to value from input, not to variable (which is not visible outside the class). That's why you have to use quotation marks, something like that:
x=input("price or firm or type: ")
if x == 'price':
print(XP1374.price)
elif x == 'firm':
print(XP1374.firm)
elif x == 'type':
print(XP1374.type)