Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Shopping simulator
- # Evan Project started 1/21/13
- import random
- import time
- import sys
- # define food variables for inventory
- chicken = 0
- bread = 0
- fish = 0
- soup = 0
- macncheese = 0
- donuts = 0
- money = 0
- choice = " "
- name = input("Hello, user! What is your name?: ")
- while name == "" or name == " ":
- print("That is not a valid name! Choose another!")
- name = input("What is your name?: ")
- print("Welcome,", name,"to the grocery shopping simulator!")
- money = float(input("How much money would you like to deposit?: "))
- while money < 0:
- print("You cannot take that amount of money to the store!")
- money = float(input("How much money would you like to deposit?: "))
- input("\nPress the [ENTER] key to start the simulation!")
- def how_many():
- global howmany
- howmany = int(input("How much of this item would you like to buy?: "))
- if choice == "1":
- chicken += howmany
- money = money - howmany * chicken
- def ask_menu():
- menu_or_no = input("Would you like to go back to the menu?(y/n): ")
- menu_or_no = menu_or_no.lower()
- while menu_or_no not in ("y", "n"):
- menu_or_no = input("Would you like to go back to the menu?: ")
- if menu_or_no == "y":
- menu()
- elif menu_or_no == "n":
- food_menu()
- def food_menu():
- global money
- global chicken
- global fish
- global soup
- global bread
- global macncheese
- global donuts
- print(
- """
- These are the items you can buy:
- Option 1 - Chicken: $9
- Option 2 - Loaf of bread: $4
- Option 3 - Fish: $12
- Option 4 - Soup: $3
- Option 5 - Mac and Cheese: $1
- Option 6 - Donuts: $4
- """
- )
- option = input("What would you like to buy? Option: ");
- if option == "1":
- if money < 9:
- print("You do not have enough money for this!")
- ask_menu()
- else:
- how_many()
- chicken = chicken + howmany
- money = money - howmany * 9
- print("You bought", howmany, "chicken!")
- ask_menu()
- elif option == "2":
- if money < 4:
- print("You do not have enough money for this!")
- ask_menu()
- else:
- how_many()
- bread = bread + howmany
- money = money - howmany * 4
- print("You bought", howmany, "loafs of bread!")
- ask_menu()
- elif option == "3":
- if money < 12:
- print("You do not have enough money for this!")
- ask_menu()
- else:
- how_many()
- fish = fish + howmany
- money = money - howmany * 12
- print("You bought", howmany, "pieces of fish!")
- ask_menu()
- elif option == "4":
- if money < 3:
- print("You do not have enough money for this!")
- ask_menu()
- else:
- how_many()
- soup = soup + howmany
- money = money - 3 * howmany
- ask_menu()
- elif option == "5":
- if money < 1:
- print("You do not have enough money for this!")
- ask_menu()
- else:
- how_many()
- macncheese = macncheese + howmany
- money = money - 1 * howmany
- ask_menu()
- elif option == "6":
- if money < 4:
- print("You do not have enough money for this!")
- ask_menu()
- else:
- how_many()
- donuts = donuts + howmany
- money = money - 4 * howmany
- ask_menu()
- # easter egg :D
- elif option == "42":
- print("I will fight you to the DEATH.")
- ask_menu()
- else:
- print("That is not an option!")
- ask_menu()
- print("\nWelcome to the Grocery Store! Please select an option from the menu!")
- def menu():
- global stolen_money
- global rand_number
- stolen_money = random.randint(25, 137)
- rand_number = random.randint(1,3)
- print(
- """
- MENU
- 1 - Leave the store
- 2 - Deposit more money
- 3 - Buy groceries
- 4 - Check inventory
- 5 - Rob the store
- """
- )
- global choice
- choice = input("Selection: ")
- menu() # displays menu, allows user input to be converted into running a new choice
- while choice != "1":
- if choice == "2":
- money2 = int(input("How much money would you like to deposit?: "))
- money += money2
- print("You now have $" + money + "!")
- menu()
- elif choice == "3":
- food_menu()
- elif choice == "4":
- print(" ITEM | QUANTITY")
- print(" Chicken |", chicken)
- print(" Bread |", bread)
- print(" Fish |", fish)
- print(" Soup |", soup)
- print(" Mac and cheese |", macncheese)
- print(" Donuts |", donuts)
- print("Money: $", money)
- input("Press the [ENTER] key to go back to the menu.")
- menu()
- elif choice == "5":
- if rand_number == 3:
- print("You were caught stealing and have been sent to jail!")
- time.sleep(2)
- sys.exit()
- else:
- print("You have stolen $", stolen_money,"!\n")
- money += stolen_money
- menu()
- if choice == "1":
- print("\t\tThank you for shopping,", name, "! Please come again!")
- input("\n\t\tPress the [ENTER] key to exit the program!")
Advertisement
Add Comment
Please, Sign In to add comment