Guest User

Untitled

a guest
Jan 8th, 2014
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.65 KB | None | 0 0
  1. # Shopping simulator
  2. # Evan Project started 1/21/13
  3.  
  4. import random
  5. import time
  6. import sys
  7. # define food variables for inventory
  8. chicken = 0
  9. bread = 0
  10. fish = 0
  11. soup = 0
  12. macncheese = 0
  13. donuts = 0
  14.  
  15. money = 0
  16. choice = " "
  17. name = input("Hello, user! What is your name?: ")
  18. while name == "" or name == " ":
  19.     print("That is not a valid name! Choose another!")
  20.     name = input("What is your name?: ")
  21. print("Welcome,", name,"to the grocery shopping simulator!")
  22. money = float(input("How much money would you like to deposit?: "))
  23. while money < 0:
  24.     print("You cannot take that amount of money to the store!")
  25.     money = float(input("How much money would you like to deposit?: "))
  26.     input("\nPress the [ENTER] key to start the simulation!")
  27.  
  28. def how_many():
  29.     global howmany
  30.     howmany = int(input("How much of this item would you like to buy?: "))
  31.     if choice == "1":
  32.         chicken += howmany
  33.         money = money - howmany * chicken
  34.    
  35. def ask_menu():
  36.     menu_or_no = input("Would you like to go back to the menu?(y/n): ")
  37.     menu_or_no = menu_or_no.lower()
  38.     while menu_or_no not in ("y", "n"):
  39.         menu_or_no = input("Would you like to go back to the menu?: ")
  40.     if menu_or_no == "y":
  41.         menu()
  42.     elif menu_or_no == "n":
  43.         food_menu()
  44.  
  45. def food_menu():
  46.         global money
  47.         global chicken
  48.         global fish
  49.         global soup
  50.         global bread
  51.         global macncheese
  52.         global donuts
  53.         print(
  54.             """
  55. These are the items you can buy:
  56. Option 1 - Chicken: $9
  57. Option 2 - Loaf of bread: $4
  58. Option 3 - Fish: $12
  59. Option 4 - Soup: $3
  60. Option 5 - Mac and Cheese: $1
  61. Option 6 - Donuts: $4
  62. """
  63.             )
  64.         option = input("What would you like to buy? Option: ");
  65.         if option == "1":
  66.             if money < 9:
  67.                 print("You do not have enough money for this!")
  68.                 ask_menu()
  69.             else:
  70.                 how_many()
  71.                 chicken = chicken + howmany
  72.                 money = money - howmany * 9
  73.                 print("You bought", howmany, "chicken!")
  74.                 ask_menu()
  75.         elif option == "2":
  76.             if money < 4:
  77.                 print("You do not have enough money for this!")
  78.                 ask_menu()
  79.             else:
  80.                 how_many()
  81.                 bread = bread + howmany
  82.                 money = money - howmany * 4
  83.                 print("You bought", howmany, "loafs of bread!")
  84.                 ask_menu()
  85.         elif option == "3":
  86.             if money < 12:
  87.                 print("You do not have enough money for this!")
  88.                 ask_menu()
  89.             else:
  90.                 how_many()
  91.                 fish = fish + howmany
  92.                 money = money - howmany * 12
  93.                 print("You bought", howmany, "pieces of fish!")
  94.                 ask_menu()
  95.         elif option == "4":
  96.             if money < 3:
  97.                 print("You do not have enough money for this!")
  98.                 ask_menu()
  99.             else:
  100.                 how_many()
  101.                 soup = soup + howmany
  102.                 money = money - 3 * howmany
  103.                 ask_menu()
  104.         elif option == "5":
  105.             if money < 1:
  106.                 print("You do not have enough money for this!")
  107.                 ask_menu()
  108.             else:
  109.                 how_many()
  110.                 macncheese = macncheese + howmany
  111.                 money = money - 1 * howmany
  112.                 ask_menu()
  113.         elif option == "6":
  114.             if money < 4:
  115.                 print("You do not have enough money for this!")
  116.                 ask_menu()
  117.             else:
  118.                 how_many()
  119.                 donuts = donuts + howmany
  120.                 money = money - 4 * howmany
  121.                 ask_menu()
  122.  
  123.         # easter egg :D
  124.         elif option == "42":
  125.             print("I will fight you to the DEATH.")
  126.             ask_menu()
  127.         else:
  128.             print("That is not an option!")
  129.             ask_menu()
  130.  
  131.  
  132. print("\nWelcome to the Grocery Store! Please select an option from the menu!")
  133. def menu():
  134.     global stolen_money
  135.     global rand_number
  136.     stolen_money = random.randint(25, 137)
  137.     rand_number = random.randint(1,3)
  138.     print(
  139.         """
  140.        MENU
  141. 1 - Leave the store
  142. 2 - Deposit more money
  143. 3 - Buy groceries
  144. 4 - Check inventory
  145. 5 - Rob the store
  146. """
  147.         )
  148.     global choice
  149.     choice = input("Selection: ")
  150.  
  151. menu() # displays menu, allows user input to be converted into running a new choice
  152. while choice != "1":
  153.     if choice == "2":
  154.         money2 = int(input("How much money would you like to deposit?: "))
  155.         money += money2
  156.         print("You now have $" + money + "!")
  157.         menu()
  158.     elif choice == "3":
  159.         food_menu()
  160.     elif choice == "4":
  161.         print(" ITEM           | QUANTITY")
  162.         print(" Chicken        |", chicken)
  163.         print(" Bread          |", bread)
  164.         print(" Fish           |", fish)
  165.         print(" Soup           |", soup)
  166.         print(" Mac and cheese |", macncheese)
  167.         print(" Donuts         |", donuts)
  168.         print("Money: $", money)
  169.         input("Press the [ENTER] key to go back to the menu.")
  170.         menu()
  171.     elif choice == "5":
  172.         if rand_number == 3:
  173.             print("You were caught stealing and have been sent to jail!")
  174.             time.sleep(2)
  175.             sys.exit()
  176.         else:
  177.             print("You have stolen $", stolen_money,"!\n")
  178.             money += stolen_money
  179.             menu()
  180.        
  181. if choice == "1":
  182.     print("\t\tThank you for shopping,", name, "! Please come again!")
  183.     input("\n\t\tPress the [ENTER] key to exit the program!")
Advertisement
Add Comment
Please, Sign In to add comment