customers = [Customer("Joe", 6000), Customer("Tom", 8000), Customer("Jim", 15000)] for customer in customers: bikes = ", ".join( bike.model for bike in shop.filter(customer.fund) ) print (customer.name, "|", bikes) # Print BikeShop before making sales... print (shop) # Iterate over the customers, sell each a Bike, then list customer, # what they bought, the cost, and how much $ they have left... template = "{0} bought the {1} at ${2}, and they have ${3} left over." for customer in customers: affordables = shop.filter(customer.fund) shop.sell(random.choice(affordables), customer) print (template.format( customer.name, customer.bike.model, customer.bike.price, customer.fund )) # Print BikeShop after making sales... print (shop)
print("\nPossible bikes for " + x.name + ":\n") for y in bikeshop.inventory: if (y.cost*1.2)<=x.fund: print(y.model) #Prints initial inventory print("\nThese are all the bikes: \n") for y in bikeshop.inventory: print(y.model) #Each customer buys a bike, prints name of bike, the cost, and how much money #the customer has in his fund for x in customers: for y in bikeshop.inventory: if ( y.cost*1.2)<= x.fund: x.buy(y) bikeshop.sell(y) print("There are " + str(x.fund) + " dollars left in " + x.name + "'s fund") #After a purchase, the bike shop prints the remaining inventory and how much #the bike shop has made for y in bikeshop.inventory: print("\n") print(y.model) bikeshop.balance()
customers = [Customer("Ali", 200), Customer("Bob", 500), Customer("Caz", 1000)] for customer in customers: bikes = ", ".join( bike.model for bike in shop.filter(customer.fund) ) print customer.name, "|", bikes # Print the BikeShop before making any sales... print shop # Iterate over the customers, selling each a Bike, then using a template, # print who the customer is, what they bought, what it cost, and how much # they have left over... template = "{0} bought the {1} at ${2}, and they have ${3} left over." for customer in customers: affordables = shop.filter(customer.fund) shop.sell(random.choice(affordables), customer) print template.format( customer.name, customer.bike.model, customer.bike.price, customer.fund ) # Print the BikeShop again, now it's made a few sales... print shop
for x in customers: print("\nPossible bikes for " + x.name + ":\n") for y in bikeshop.inventory: if (y.cost * 1.2) <= x.fund: print(y.model) #Prints initial inventory print("\nThese are all the bikes: \n") for y in bikeshop.inventory: print(y.model) #Each customer buys a bike, prints name of bike, the cost, and how much money #the customer has in his fund for x in customers: for y in bikeshop.inventory: if (y.cost * 1.2) <= x.fund: x.buy(y) bikeshop.sell(y) print("There are " + str(x.fund) + " dollars left in " + x.name + "'s fund") #After a purchase, the bike shop prints the remaining inventory and how much #the bike shop has made for y in bikeshop.inventory: print("\n") print(y.model) bikeshop.balance()