I need some help with a code I'm working on. The code starts off by creating a class for types of cars. Once that's done, I have it construct a list of predetermined vehicles (all made from the aforementioned class), and then I ask for user input, to see if the type of car they own is in the database.
When I input a type of car that the database doesn't recongize (say, a Prius), it asks to create a new item in the list so it contains the information for - theoretical - future inputs. However, the "if x in list" feature doesn't appear to work, because even if I enter the name of a product that is inside the list (a Viper) it doesn't recognize it.
Saying that, I have two questions: How do I get the list to print the names, manufacturer, and price of the car, instead of the standard "<__main__.carType instance at 0x6d400>" stuff? And why does the program not recognize objects that are in or have been appended to the list? Any advice or assistance would be greatly appreciated.
Here's the code.
class carType: def __init__(self, name, brand, price): self.name = name self.brand = brand self.price = price carlist = [ carType("Viper", "Dodge", 80000), carType("Mustang", "Ford", 25000), carType("Silhouette", "Oldsmobile", 26000), carType("Croma", "Fiat", 15000), carType("RL", "Acura", 46000), carType("Axiom", "Isuzu", 24000) ] while True: x = raw_input("Enter the name of your car: ") if x in carlist: print "The car you specified is in our database." print "Your car was built by", carType.brand, ". and the general MSRP is", carType.price, "." break else: print "Your car is not in the database." print "Please enter the manufacturer and suggested retail price (MSRP)." y = raw_input("Who is the manufacturer of your vehicle? ") z = input("What is the suggested retail price? ") a = carType(x, y, z) carlist.append(a) print carlist break