Advertisement
2teez

PyCode of a Veggie Shop

Nov 24th, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.00 KB | None | 0 0
  1. import sys
  2.  
  3. def veggie_quatity(msg):
  4.     while True:
  5.         try:
  6.             quantity = int(raw_input(msg))
  7.             if quantity < 0:
  8.                 print "Error, Enter Positive Number!"
  9.                 continue
  10.             return quantity
  11.         except Exception, e:
  12.             print e
  13.        
  14. def bye():
  15.     shop_ticket()
  16.     sys.exit(0)
  17.    
  18. def shop_ticket():
  19.     template = '%-10s%10d%10.2f\n'
  20.     print "Item\t\tQuantity\tCost\n"
  21.     for item in veggie_menu:
  22.        if item != 'Q':
  23.            if veggie_menu[item][1] > 0:
  24.            print template%(veggie_menu[item][3],
  25.                       veggie_menu[item][1], veggie_menu[item][2])
  26.                      
  27. #  use dictionary store your key as veggie types and values for
  28. #  these constants as follow
  29. #  [price_of_veggie_type, counter, total_veggie_order, veggie_names]
  30. veggie_menu = {
  31.        "L": [0.89, 0, 0.0, 'Lettuce'], "G" :[2.50, 0, 0.0, 'Green Beans'],
  32.        "P" :[0.50, 0, 0.0, 'Peppers'], "T" :[0.75, 0, 0.0, 'Tomatoes'],
  33.        "O" :[0.50, 0, 0.0, 'Onions'], "Q" : bye,    
  34.      }
  35.  
  36. while True:
  37.     print """
  38.         Veggie Menu:
  39.         Select Item by letter Choice
  40.         L = Lettuce      
  41.         G = Green Beans    
  42.         P = Peppers              
  43.         T = Tomatoes                
  44.         O = Onions                    
  45.         Q = Quit Program          
  46.         """
  47.     try:
  48.         veggieType = (raw_input("What Veggie would you like to order? Enter Q to Quit: ")).upper();
  49.         if veggieType == 'Q':
  50.         veggie_menu[veggieType]()      
  51.         if veggieType not in veggie_menu.keys():
  52.         print "Error", veggieType, "doesn't exists"
  53.         continue
  54.        
  55.         how_many = veggie_quatity("How many "+ veggie_menu[veggieType][3]+
  56.                                   " would you like to order? ")
  57.        
  58.         veggie_menu[veggieType][1] += how_many        
  59.         veggie_menu[veggieType][2] += (how_many * veggie_menu[veggieType][0])
  60.        
  61.     except Exception, e:
  62.         print e
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement