Related
from tkinter import CENTER
global f
f = 0
#this t_movie function is used to select movie name
def t_movie():
global f
f = f+1
print("which movie do you want to watch?")
print("1,movie 1 ")
print("2,movie 2 ")
print("3,movie 3")
print("4,back")
movie = int(input("choose your movie: "))
if movie == 4:
# in this it goes to center function and from center it goes to movie function and it
comes back here and then go to theater
CENTER()
theater()
return 0
if f == 1:
theater()
# this theater function used to select screen
def theater():
print("which screen do you want to watch movie: ")
print("1,SCREEN 1")
print("2,SCREEN 2")
print("3,SCREEN 3")
a = int(input("choose your screen: "))
ticket = int(input("number of ticket do you want?: "))
timing(a)
# this timing function used to select timing for movie
def timing(a):
time1 = {
"1": "10.00-1.00",
"2": "1.10-4.10",
"3": "4.20-7.20",
"4": "7.30-10.30"
}
time2 = {
"1": "10.15-1.15",
"2": "1.25-4.25",
"3": "4.35-7.35",
"4": "7.45-10.45"
}
time3 = {
"1": "10.30-1.30",
"2": "1.40-4.40",
"3": "4.50-7.50",
"4": "8.00-10.45"
}
if a == 1:
print("choose your time:")
print(time1)
t = input("select your time:")
x = time1[t]
print("successful!, enjoy movie at "+x)
elif a == 2:
print("choose your time:")
print(time2)
t = input("select your time:")
x = time2[t]
print("successful!, enjoy movie at "+x)
elif a == 3:
print("choose your time:")
print(time3)
t = input("select your time:")
x = time3[t]
print("successful!, enjoy movie at "+x)
return 0
def movie(theater):
if theater == 1:
t_movie()
elif theater == 2:
t_movie()
elif theater == 3:
t_movie()
elif theater == 4:
city()
else:
print("wrong choice")
def center():
print("which theater do you wish to see movie? ")
print("1,Inox")
print("2,Icon")
print("3,pvp")
print("4,back")
a = int(input("choose your option: "))
movie(a)
return 0
# this function is used to select city
def city():
print("Hi welcome to movie ticket booking: ")
print("where you want to watch movie?:")
print("1,city 1")
print("2,city 2 ")
print("3,city 3 ")
place = int(input("choose your option: "))
if place == 1:
center()
elif place == 2:
center()
elif place == 3:
center()
else:
print("wrong choice")
city() # it calls the function city
Here is your code with the indentation fixed. At least, I think it's fixed, Your structure is confusing, so it's hard to tell.
from tkinter import CENTER
f = 0
#this t_movie function is used to select movie name
def t_movie():
global f
f = f+1
print("which movie do you want to watch?")
print("1,movie 1 ")
print("2,movie 2 ")
print("3,movie 3")
print("4,back")
movie = int(input("choose your movie: "))
if movie == 4:
# in this it goes to center function and from center it goes to movie function and it comes back here and then go to theater
CENTER()
theater()
return 0
if f == 1:
theater()
# this theater function used to select screen
def theater():
print("which screen do you want to watch movie: ")
print("1,SCREEN 1")
print("2,SCREEN 2")
print("3,SCREEN 3")
a = int(input("choose your screen: "))
ticket = int(input("number of ticket do you want?: "))
timing(a)
# this timing function used to select timing for movie
def timing(a):
time1 = {
"1": "10.00-1.00",
"2": "1.10-4.10",
"3": "4.20-7.20",
"4": "7.30-10.30"
}
time2 = {
"1": "10.15-1.15",
"2": "1.25-4.25",
"3": "4.35-7.35",
"4": "7.45-10.45"
}
time3 = {
"1": "10.30-1.30",
"2": "1.40-4.40",
"3": "4.50-7.50",
"4": "8.00-10.45"
}
if a == 1:
print("choose your time:")
print(time1)
t = input("select your time:")
x = time1[t]
print("successful!, enjoy movie at "+x)
elif a == 2:
print("choose your time:")
print(time2)
t = input("select your time:")
x = time2[t]
print("successful!, enjoy movie at "+x)
elif a == 3:
print("choose your time:")
print(time3)
t = input("select your time:")
x = time3[t]
print("successful!, enjoy movie at "+x)
return 0
def movie(theater):
if theater == 1:
t_movie()
elif theater == 2:
t_movie()
elif theater == 3:
t_movie()
elif theater == 4:
city()
else:
print("wrong choice")
def center():
print("which theater do you wish to see movie? ")
print("1,Inox")
print("2,Icon")
print("3,pvp")
print("4,back")
a = int(input("choose your option: "))
movie(a)
return 0
# this function is used to select city
def city():
print("Hi welcome to movie ticket booking: ")
print("where you want to watch movie?:")
print("1,city 1")
print("2,city 2 ")
print("3,city 3 ")
place = int(input("choose your option: "))
if place == 1:
center()
elif place == 2:
center()
elif place == 3:
center()
else:
print("wrong choice")
city() # it calls the function city
I'm trying to write a simple program, but I meet a problem that the program does not output the given variable "tax" in the end.
def main():
# define and initialize constants and variables
menu1 = 6
menu2 = 2.5
menu3 = 1.25
menu4 = 3.75
choose = total = 0
tax = total*0.06
# display welcome
print("Welcome to Yum Yum Snack Bar!")
try:
while choose != 5:
print("\nPlease choose from the following menu:")
print("1) Personal Pizza $6.00")
print("2) Pretzel $2.50")
print("3) Chips $1.25")
print("4) Hot Dog $3.75")
print("5) Exit ")
choose = int(input("\nEnter your choice here: "))
if choose == 1:
total += menu1
elif choose == 2:
total += menu2
elif choose == 3:
total += menu3
elif choose == 4:
total += menu4
elif choose == 5:
continue
else:
print("Invalid choice. Must choose 1 – 5. Try again.")
print("Current total: $",total)
except:
print("Invalid choice. Must choose 1 – 5. Try again.")
main()
print("Current total: $",total)
print("Sales tax: $",tax)
print("Total Bill: $",total+tax)
print("Have a nice day!")
main()
when you initialized tax, you gave it a value of 0 because total*0.06 at that point equaled zero.
python goes line by line so the variable "tax" didn't change its value for the whole code, you only changed "total".
so to get the tax, you should calculate it again.
print("Current total: $",total)
tax=0.06*total
print("Sales tax: $",tax)
print("Total Bill: $",total+tax)
print("Have a nice day!")
Here the value of total gets updated but the tax is calculated before the check as given below, hence tax will output tax = total*0.06 where initially total=0
Please try this:
def main():
# define and initialize constants and variables
menu1 = 6
menu2 = 2.5
menu3 = 1.25
menu4 = 3.75
choose = total = tax = 0
# display welcome
print("Welcome to Yum Yum Snack Bar!")
try:
while choose != 5:
print("\nPlease choose from the following menu:")
print("1) Personal Pizza $6.00")
print("2) Pretzel $2.50")
print("3) Chips $1.25")
print("4) Hot Dog $3.75")
print("5) Exit ")
choose = int(input("\nEnter your choice here: "))
if choose == 1:
total += menu1
elif choose == 2:
total += menu2
elif choose == 3:
total += menu3
elif choose == 4:
total += menu4
elif choose == 5:
continue
else:
print("Invalid choice. Must choose 1 – 5. Try again.")
print("Current total: $",total)
except:
print("Invalid choice. Must choose 1 – 5. Try again.")
tax = total*0.06
print("Current total: $",total)
print("Sales tax: $",tax)
print("Total Bill: $",total+tax)
print("Have a nice day!")
main()
I guess your problem is solved.Also start using python dictionary instead of using lots of if else statements
def main():
# define and initialize constants and variables
menu1 = 6
menu2 = 2.5
menu3 = 1.25
menu4 = 3.75
choose = total = 0
tax = total*0.06
# display welcome
print("Welcome to Yum Yum Snack Bar!")
try:
while choose != 5:
print("\nPlease choose from the following menu:")
print("1) Personal Pizza $6.00")
print("2) Pretzel $2.50")
print("3) Chips $1.25")
print("4) Hot Dog $3.75")
print("5) Exit ")
choose = int(input("\nEnter your choice here: "))
price_dict = {
1: menu1,
2: menu2,
3: menu3,
4: menu4
}
if 0 < choose < 5:
total += price_dict[choose]
else:
if choose == 5:
continue
else:
print("Invalid choice. Must choose 1 – 5. Try again.")
print("Current total: $",total)
except:
print("Invalid choice. Must choose 1 – 5. Try again.")
main()
tax = total*0.06
print("Current total: $",total)
print("Sales tax: $",tax)
print("Total Bill: $",total+tax)
print("Have a nice day!")
main()
Now your tax is always 0. You have to calculate the tax at the end. Like this:
def main():
# define and initialize constants and variables
menu1 = 6
menu2 = 2.5
menu3 = 1.25
menu4 = 3.75
choose = total = 0
# display welcome
print("Welcome to Yum Yum Snack Bar!")
try:
while choose != 5:
print("\nPlease choose from the following menu:")
print("1) Personal Pizza $6.00")
print("2) Pretzel $2.50")
print("3) Chips $1.25")
print("4) Hot Dog $3.75")
print("5) Exit ")
choose = int(input("\nEnter your choice here: "))
if choose == 1:
total += menu1
elif choose == 2:
total += menu2
elif choose == 3:
total += menu3
elif choose == 4:
total += menu4
elif choose == 5:
continue
else:
print("Invalid choice. Must choose 1 – 5. Try again.")
print("Current total: $", total)
except:
print("Invalid choice. Must choose 1 – 5. Try again.")
main()
print("Current total: $", total)
tax = total * 0.06
print("Sales tax: $", tax)
print("Total Bill: $", total + tax)
print("Have a nice day!")
main()
So I am trying to write a code that uses functions to create a menu for user input. It's basically just inputting the amount of dollars you wish and picking which currency to convert it to. I am absolutely lost because every time I attempt to run this code I have so far (Just to make sure I'm on the correct path), I input "1" and say 20 dollars just for example, it tells me that "dollars" is not defined when I clearly have it as a user input.
def DisplayMenu():
print("Choose a menu option:")
print("1. European Euro")
print("2. British Pound")
print("3. Mexican Peso")
print("4. Chinese Yuan")
print("5. Japanese Yen")
print("6. Quit")
selection = int(input("Enter your selection: "))
dollars = eval(input("Enter the dollar amount to convert: "))
def DollarConvert(selection, dollars):
if selection == "1":
conversion = dollars * 0.921
elif selection == "2":
conversion = dollars * 0.807
elif selection == "3":
conversion = dollars * 24.246
elif selection == "4":
conversion = dollars * 7.085
elif selection == "5":
conversion = dollars * 108.03
elif selection == "6":
quit
elif selection > 6:
print("Invalid input.")
DisplayMenu()
print("$ ",dollars," = ",chr(8364),conversion)
Hopefully someone can help me with this because I am out of ideas
You never run or from DollarConvert(), or receive outputs from either function. Change the functions to return values, like this:
def DisplayMenu():
print("Choose a menu option:")
print("1. European Euro")
print("2. British Pound")
print("3. Mexican Peso")
print("4. Chinese Yuan")
print("5. Japanese Yen")
print("6. Quit")
selection = int(input("Enter your selection: "))
dollars = eval(input("Enter the dollar amount to convert: "))
return selection, dollars
def DollarConvert(selection, dollars):
if selection == "1":
return = dollars * 0.921
elif selection == "2":
return = dollars * 0.807
elif selection == "3":
return dollars * 24.246
elif selection == "4":
return dollars * 7.085
elif selection == "5":
return dollars * 108.03
elif selection == "6":
quit
elif selection > 6:
print("Invalid input.")
return None
selection, dollars = DisplayMenu()
conversion = DollarConvert(selection, dollars)
print("$ ",dollars," = ",chr(8364),conversion)
There we go.
In your code, the dollars variable's scope is limited to inside that function. You have to return dollars from the function to make it accessible. Also your dollar convert function is never called, so you need to call it. You also need to add a return statement for the conversion variable. Returning is essential for most all functions, otherwise data is lost.
You could also do it using the global keyword
dollars = None
conversion = None
def DisplayMenu():
global dollars
print("Choose a menu option:")
print("1. European Euro")
print("2. British Pound")
print("3. Mexican Peso")
print("4. Chinese Yuan")
print("5. Japanese Yen")
print("6. Quit")
selection = input("Enter your selection: ")
dollars = int(input("Enter the dollar amount to convert: "))
DollarConvert(selection, dollars)
def DollarConvert(selection, dollars):
global conversion
if selection == "1":
conversion = dollars * 0.921
elif selection == "2":
conversion = dollars * 0.807
elif selection == "3":
conversion = dollars * 24.246
elif selection == "4":
conversion = dollars * 7.085
elif selection == "5":
conversion = dollars * 108.03
elif selection == "6":
quit
elif selection > 6:
print("Invalid input.")
DisplayMenu()
print("$ ",dollars," = ",chr(8364),conversion)
Also, one more mistake on line 12 & 13, i.e
selection = int(input("Enter your selection: "))
changed to
selection = input("Enter your selection: ")
and
dollars = eval(input("Enter the dollar amount to convert: "))
changed to
dollars = int(input("Enter the dollar amount to convert: "))
Pretty much the title. Wrote some code but I don't know whats wrong with it as it won't run. I don't know if its even close to right. This program is a mac and cheese program, the user chooses between small, medium, and large and can add toppings. It has to spit out the toppings cost, base cost, and total cost with tax. I think I'm close, but I'm pretty fresh to this whole programming thing, so help a guy out. :)
#Lab 8 Mac and Cheese Program
#This program calculates the cost of ordered mac and cheese
#Date: 10/10/19
#Welcome Message
print ("Thank you for your purchase! This program will calculate the total cost of your order.")
print('-'*65)
print()
#Declare Variables
small = 4.00
medium = 5.00
large = 6.00
bacon = 1.50
grilled_onions = 1.00
grilled_chicken = 2.50
sloppy_joe = 2.50
lobster = 5.00
def mainMenu():
print("1. Small $4.00")
print("2. Medium $5.00")
print("3. Large $6.00")
selection = int(input("What size Mac and Cheese would you like? Choose a number. ")
if selection == "1":
small()
elif selection == "2":
medium()
elif selection == "3":
large()
else:
print("Enter a valid selection" )
mainMenu()
def small():
small = 4.00
print("You have ordered a small Mac and Cheese. ")
toppings = str(input("Choose your toppings: ")
def menu():
print("1. Bacon $1.50 ")
print("2. Grilled Onions $1.00 ")
print("3. Grilled Chicken $2.50 ")
print("4. Sloppy Joe Meat $2.50 ")
print("5. Lobster $5.00 ")
print("6. No toppings ")
choice = int(input("Enter the number for the topping you want. ")
if choice == "1":
print("You have added Bacon to your order. ")
print("That will add 1.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "2":
print("You have added Grilled Onions to your order. ")
print("That will add 1.00 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "3":
print("You have added Grilled Chicken to your order. ")
print("That will add 2.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "4":
print("You have added Sloppy Joe Meat to your order. ")
print("That will add 2.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "5":
print("You have added Lobster to your order. ")
print("That will add 5.00 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "6":
print("You have chosen to add no toppings. ")
continue
toppings_cost = choice
print("The cost for all your toppings is" , toppings_cost)
base_price = small
print("The base price of your order is: ", base_price)
tax = 0.06
total_price = 0.06(choice + small)
print("The total cost of your order is ", total_price)
restart = input("Would you like to try another order? ")
if restart == "Yes"
mainMenu()
else:
print("Thank you for your order, have a great day!")
break
small()
def medium():
medium = 5.00
print("You have ordered a medium Mac and Cheese. ")
toppings = str(input("Choose your toppings: ")
def menu():
print("1. Bacon $1.50 ")
print("2. Grilled Onions $1.00 ")
print("3. Grilled Chicken $2.50 ")
print("4. Sloppy Joe Meat $2.50 ")
print("5. Lobster $5.00 ")
print("6. No toppings ")
choice = int(input("Enter the number for the topping you want. ")
if choice == "1":
print("You have added Bacon to your order. ")
print("That will add 1.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "2":
print("You have added Grilled Onions to your order. ")
print("That will add 1.00 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "3":
print("You have added Grilled Chicken to your order. ")
print("That will add 2.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "4":
print("You have added Sloppy Joe Meat to your order. ")
print("That will add 2.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "5":
print("You have added Lobster to your order. ")
print("That will add 5.00 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "6":
print("You have chosen to add no toppings. ")
continue
toppings_cost = choice
print("The cost for all your toppings is" , toppings_cost)
base_price = medium
print("The base price of your order is: ", base_price)
tax = 0.06
total_price = 0.06(choice + medium)
print("The total cost of your order is ", total_price)
restart = input("Would you like to try another order? ")
if restart == "Yes"
mainMenu()
else:
print("Thank you for your order, have a great day!")
break
medium()
def large():
large = 6.00
print("You have ordered a large Mac and Cheese. ")
toppings = str(input("Choose your toppings: ")
def menu():
print("1. Bacon $1.50 ")
print("2. Grilled Onions $1.00 ")
print("3. Grilled Chicken $2.50 ")
print("4. Sloppy Joe Meat $2.50 ")
print("5. Lobster $5.00 ")
print("6. No toppings ")
choice = int(input("Enter the number for the topping you want. ")
if choice == 1:
print("You have added Bacon to your order. ")
print("That will add 1.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "2":
print("You have added Grilled Onions to your order. ")
print("That will add 1.00 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "3":
print("You have added Grilled Chicken to your order. ")
print("That will add 2.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "4":
print("You have added Sloppy Joe Meat to your order. ")
print("That will add 2.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "5":
print("You have added Lobster to your order. ")
print("That will add 5.00 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "6":
print("You have chosen to add no toppings. ")
continue
toppings_cost = choice
print("The cost for all your toppings is" , toppings_cost)
base_price = large
print("The base price of your order is: ", base_price)
tax = 0.06
total_price = 0.06(choice + large)
print("The total cost of your order is ", total_price)
restart = input("Would you like to try another order? ")
if restart == "Yes"
mainMenu()
else:
print("Thank you for your order, have a great day!")
break
large()
mainMenu()
You might find it helpful to start with a trimmed down version of your program and get that to work. Just maybe "small." Also, the "def menu()" function appears to be repeated for each size. You might find it easier to work with/debug if you just have one "def menu()" that works more generally. Lastly, you might want to watch out for "ints vs. strings" in your processing. Hope that helps troubleshoot.
My For loops don't seem to be "activating" or working. I am writing a program about the Oregon trail and I am working on the "shop" part. Here is what its been doing,
First it was asking the same question "How much food would you like to buy" until I pressed E to break out of it. Now its not doing the math or activating the for loop. Here is the code i'm working with:
import random
global all
global PlayerPerk
#Organ Trail Start--
print("You may:")
print("1. Travel the road")
print("2. Learn More about the road")
choiceStart = input("What is your choice? ")
def Shop(PlayerPerk, money):
global all
#intro
print("Before You set off on your Journey, you will need some supplies to survive the dangerous trail. You will need Food, Ammo, Spare Parts, Clothing, and Oxen")
#money define
if PlayerPerk == "1":
print("You are A cop. You have $400 to spend.")
money = 400
elif PlayerPerk == "2":
print("You are a Clerk. You have $700 to spend.")
money = 700
elif PlayerPerk == "3":
print("You are a Banker. You have $1600 to spend.")
money =1600
print("Welcome to My shop! First thing, how much Food would you like to buy?")
#Food -------------------------------------------------------------------------------
FoodToBuy = input("How Much food would you like (each cost $2):")
MoneySubtract = FoodToBuy*2
for i in range(1,1000):
if FoodToBuy == int:
if money - MoneySubtract > 0:
money -= MoneySubtract
print("You spent: ",MoneySubtract, "You now have: ",money)
Food = FoodToBuy
MoneySubtract = 0
else:
print("Insufficent Funds!")
Shop(PlayerPerk,money)
elif FoodToBuy == "e":
break
#Ammo --------------------------------------------------------------------------------
print("Now lets buy some Ammo!")
AmmoToBuy = input("How Much Rifle Ammo would you like to buy (each box cost $5):")
MoneySubtract = AmmoToBuy*5
for i in range(1,1000):
if AmmoToBuy == int:
if money - MoneySubtract > 0:
money -= MoneySubtract
print("You spent:",MoneySubtract, "You now have: ",money)
Ammo = AmmoToBuy
MoneySubtract = 0
else:
print("Insufficent Funds!")
Shop(PlayerPerk,money)
elif AmmoToBuy=="e":
break
#Spare Parts---------------------------------------------------------------------------
print("Now lets buy some Spare Parts!")
SparePartsToBuy = input("How much Spare Parts would you like to buy (each costs $20 [max of 9]):")
MoneySubtract = SparePartsToBuy*20
for i in range(1,1000):
if SparePartsToBuy == int:
if money - MoneySubtract > 0:
money -= MoneySubtract
print("You spent:", MoneySubtract, "You now have: ",money)
SpareParts = SparePartsToBuy
MoneySubtract = 0
else:
print("Insufficent Funds!")
Shop(PlayerPerk,money)
elif AmmoToBuy=="e":
break
else:
print("Unknown input!")
Shop(PlayerPerk, 0)
#chlothing-----------------------------------------------------------------------------
print("Now, you need to buy some chlothes!")
ClothesToBuy = input("How many Clothes would you like to buy (each pair costs $5):")
MoneySubtract = ClothesToBuy*5
for i in range(1,1000):
if ClothesToBuy == int:
if money - MoneySubtract > 0:
money -= MoneySubtract
print("You spent:", MoneySubtract, "You now have: ",money)
SpareParts = ClothesToBuy
MoneySubtract = 0
else:
print("Insufficent Funds!")
Shop(PlayerPerk,money)
elif AmmoToBuy=="e":
break
else:
print("Unknown input!")
Shop(PlayerPerk, 0)
#oxen-------------------------------------------------------------------------------------
print("Finally, you need to buy some Ox!")
OxenToBuy = input("How many Oxen would you like to buy (each costs $30):")
MoneySubtract = OxenToBuy*30
for i in range(1,1000):
if OxenToBuy == int:
if money - MoneySubtract > 0:
money -= MoneySubtract
print("You spent:", MoneySubtract, "You now have: ",money)
SpareParts = OxenToBuy
MoneySubtract = 0
else:
print("Insufficent Funds!")
Shop(PlayerPerk,money)
if AmmoToBuy=="e":
break
else:
print("Unknown input!")
Shop(PlayerPerk, 0)
#----------------------------------------------------------------------------------------------
def MonthStart(PlayerPerk):
global all
print("It is 1848. Your jumping off place for oregon is Independence, Missouri. You must decide which month to leave Indepence.")
print("1. March")
print("2. April")
print("3. May")
print("4. June")
print("5. July")
print("6. ask for advice")
StartingMonth = input("What is your choice? ")
if StartingMonth == ("6"):
global all
print("You attend a public meeting held for 'folks with the California - Oregon fever.' You're told:")
print("If you leave too early, there won't be any grass for your oxen to eat.")
print("if you leave to late, you may not get to Oregon before winter comes.")
print("If you leave at just the write time, there will be green grass and the weather will still be cool.")
exMonthChoice = input("Would you like to stop viewing?(y/n) ")
if exMonthChoice ==("Y" or "y"):
MonthStart(PlayerPerk)
elif exMonthChoice == ("N"or"n"):
print("Still viewing")
else:
print("Unknown usage.")
elif StartingMonth == ("1"):
Month = "March"
print("You chose: ", Month )
Shop(PlayerPerk,0)
elif StartingMonth == ("2"):
Month = "April"
print("You chose: ", Month )
Shop(PlayerPerk,0)
elif StartingMonth == ("3"):
Month = "May"
print("You chose: ", Month )
Shop(PlayerPerk,0)
elif StartingMonth == ("4"):
Month = "June"
print("You chose: ", Month)
Shop(PlayerPerk,0)
elif StartingMonth == ("5"):
Month = "July"
print("You chose: ", Month)
Shop(PlayerPerk,0)
global all
############################
#NAMING
def NAMING(PlayerPerk):
global all
print("Now lets name your person")
Name1 = input("What is the name of the Wagon leader ")
Name2 = input("What is the name of the 2nd person in the family? ")
Name3 = input("What is the name of the 3rd person in the family? ")
Name4 = input("What is the name of the 4th person in the family? ")
Name5 = input("What is the name of the 5th person in the family? ")
NameVerification = input("Are these names correct?")
if NameVerification == ("Y" or "y"):
MonthStart(PlayerPerk)
elif NameVerification ==("N" or "n"):
NAMING(PlayerPerk)
#Start OCCUPATION
def Occupation():
global all
############################################################
print("Many people find themselves on the road. You may : ")
print("1. Be a cop from Kentucky.")
print("2. Be a clerk from Jersey City.")
print("3. Be a Banker from Boston.")
print("4. Find out the differences between these choices.")
############################################################
jobChoice = input("What is your choice? ")
if jobChoice == ("4"):
print("Traveling to Oregon isn't easy! But if you are a banker, you'll have more money for supplies and services than a cop or a clerk.")
print(" But, a cop has a higher chance of haveing a successful hunt!")
print("And a Clerk has a higher survival rate!")
exChoice1 = input("Would you like to stop viewing your options?(y/n) ")
if exChoice1 == ("y" or "Y"):
Occupation()
###############################
elif jobChoice ==("1"):
print("You chose to be a cop from Kentucky!")
PlayerPerk = ("1")
NAMING(PlayerPerk)
elif jobChoice == ("2"):
print("You chose to be a clerk from Jersey City!")
PlayerPerk = ("2")
NAMING(PlayerPerk)
elif jobChoice == ("3"):
print("You chose to be a Banker from Boston!")
PlayerPerk = ("3")
NAMING(PlayerPerk)
#Call choices
if choiceStart == ("1"):
Occupation()
And here is the specific code I'm having troubles with:
def Shop(PlayerPerk, money):
global all
#intro
print("Before You set off on your Journey, you will need some supplies to survive the dangerous trail. You will need Food, Ammo, Spare Parts, Clothing, and Oxen")
#money define
if PlayerPerk == "1":
print("You are A cop. You have $400 to spend.")
money = 400
elif PlayerPerk == "2":
print("You are a Clerk. You have $700 to spend.")
money = 700
elif PlayerPerk == "3":
print("You are a Banker. You have $1600 to spend.")
money =1600
print("Welcome to My shop! First thing, how much Food would you like to buy?")
#Food -------------------------------------------------------------------------------
FoodToBuy = input("How Much food would you like (each cost $2):")
MoneySubtract = FoodToBuy*2
for i in range(1,1000):
if FoodToBuy == int:
if money - MoneySubtract > 0:
money -= MoneySubtract
print("You spent: ",MoneySubtract, "You now have: ",money)
Food = FoodToBuy
MoneySubtract = 0
else:
print("Insufficent Funds!")
Shop(PlayerPerk,money)
elif FoodToBuy == "e":
break
#Ammo --------------------------------------------------------------------------------
print("Now lets buy some Ammo!")
AmmoToBuy = input("How Much Rifle Ammo would you like to buy (each box cost $5):")
MoneySubtract = AmmoToBuy*5
for i in range(1,1000):
if AmmoToBuy == int:
if money - MoneySubtract > 0:
money -= MoneySubtract
print("You spent:",MoneySubtract, "You now have: ",money)
Ammo = AmmoToBuy
MoneySubtract = 0
else:
print("Insufficent Funds!")
Shop(PlayerPerk,money)
elif AmmoToBuy=="e":
break
#Spare Parts---------------------------------------------------------------------------
print("Now lets buy some Spare Parts!")
SparePartsToBuy = input("How much Spare Parts would you like to buy (each costs $20 [max of 9]):")
MoneySubtract = SparePartsToBuy*20
for i in range(1,1000):
if SparePartsToBuy == int:
if money - MoneySubtract > 0:
money -= MoneySubtract
print("You spent:", MoneySubtract, "You now have: ",money)
SpareParts = SparePartsToBuy
MoneySubtract = 0
else:
print("Insufficent Funds!")
Shop(PlayerPerk,money)
elif AmmoToBuy=="e":
break
else:
print("Unknown input!")
Shop(PlayerPerk, 0)
#chlothing-----------------------------------------------------------------------------
print("Now, you need to buy some chlothes!")
ClothesToBuy = input("How many Clothes would you like to buy (each pair costs $5):")
MoneySubtract = ClothesToBuy*5
for i in range(1,1000):
if ClothesToBuy == int:
if money - MoneySubtract > 0:
money -= MoneySubtract
print("You spent:", MoneySubtract, "You now have: ",money)
SpareParts = ClothesToBuy
MoneySubtract = 0
else:
print("Insufficent Funds!")
Shop(PlayerPerk,money)
elif AmmoToBuy=="e":
break
else:
print("Unknown input!")
Shop(PlayerPerk, 0)
#oxen-------------------------------------------------------------------------------------
print("Finally, you need to buy some Ox!")
OxenToBuy = input("How many Oxen would you like to buy (each costs $30):")
MoneySubtract = OxenToBuy*30
for i in range(1,1000):
if OxenToBuy == int:
if money - MoneySubtract > 0:
money -= MoneySubtract
print("You spent:", MoneySubtract, "You now have: ",money)
SpareParts = OxenToBuy
MoneySubtract = 0
else:
print("Insufficent Funds!")
Shop(PlayerPerk,money)
if AmmoToBuy=="e":
break
else:
print("Unknown input!")
Shop(PlayerPerk, 0)
The only problem i'm having is making the for loops work. I plan on using all the variables as the code develops. If you know whats wrong or have any information on anything let me know! Thank you in advance!