Example #1
0
bikes = [
    Bicycle("Desert Cruiser", 35, 1500), Bicycle("Rock Climber", 25, 3800),
    Bicycle("Speed Racer", 15, 10000), Bicycle("The Aspen", 20, 8500),
    Bicycle("City Ride", 40, 855), Bicycle("Low Rider", 50, 5550)
    ]

shop = BikeShop("Bill's Bikes", 20, bikes)

# Create a list of Customers, then iterate over them, print
# the Customer's name and Bikes they can afford to buy...

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)
Example #2
0
bikes = [
    Bicycle("Rock Hopper", 75, 100), Bicycle("Dirt Jumper", 70, 150),
    Bicycle("Speed Demon", 50, 250), Bicycle("Mountaineer", 90, 350),
    Bicycle("Road Master", 65, 100), Bicycle("Ghetto King", 75, 550)
    ]

shop = BikeShop("Surplus Cycles", 20, bikes)

# Now, create a list of Customers, then iterate over them, printing
# the Customer's name and the Bikes that they can afford...

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)
Example #3
0
        Bicycle("cheetahbike", 10, 50), Bicycle("catbike", 25, 100),
        Bicycle("dogbike", 50, 200), Bicycle("turtlebike", 75, 300),
        Bicycle("birdbike", 100, 500), Bicycle("capybike", 200, 1000)
    }
    customers = [Customers('jim', 200), Customers('oscar', 500), Customers('jan', 1000)]

    jim = Customers('jim', 200)
    oscar = Customers('oscar', 500)
    jan = Customers('jan', 1000)
    
    #instantiate the bike shop and add bikes to inventory dictionary {model: object}
    theoffice =  BikeShop('theoffice', bikes)
    
#Print the name of each customer, and a list of the bikes offered by the bike shop that they can afford given their budget. Make sure you price the bikes in such a way that each customer can afford at least one.
    for customer in customers:
        customer.affordables = theoffice.filter(customer.fund)
        print ("{0} can afford: ".format(customer.name) + ", ".join(bike.model for bike in customer.affordables))

    #Print the initial inventory of the bike shop for each bike it carries.
    print ("\n"+ "Here's what the office has to offer today:")
    print (key for key, value in theoffice.inventory.items())
    #     print (key)
    # print()
    
    print (theoffice.inventory.keys())
    print (theoffice.inventory.values())
    
    jim.buy (theoffice, theoffice.inventory["cheetahbike"])
    oscar.buy (theoffice, theoffice.inventory["catbike"])
    jan.buy (theoffice, theoffice.inventory["turtlebike"])
    
Example #4
0
  """
  print "\nCustomers"
  print "-" * 20

  for customer in customer_list:
    template = "{0}, Budget: ${1}"
    print template.format(customer.customer_name, customer.budget)
    
  """ 
    List of the bikes offered by the bike shop that they can afford given their budget
    NOTE:  Make sure you price the bikes in such a way that each customer can afford at least one.
  """
  print "\nWhich bikes can they afford?"
  for customer in customer_list:
    print '-' * 20
    bikes = ", ".join( bike.model_name for bike in bike_shop.filter(customer.budget) )
    print customer.customer_name, "-->", bikes

  """ 
    Have each of the three customers purchase a bike
      - Print the name of the bike the customer purchased
      - The cost
      - How much money they have left over in their bicycle fund
  """
  print "\nWhich bike did the customers buy?"
  print '-' * 20
  
  template = "{0} bought the {1} at ${2}, and they have ${3} left over."
  for customer in customer_list:
    affordables = bike_shop.filter(customer.budget)
    bike_shop.sell(random.choice(affordables), customer)