I am trying to make a coffee application and I have set up a function in which I can change a global variable of the amount of coffee beans however when i run my code this is not working. I will past my code and my results below.
I am wanting this to subtract from the global variables I have set: [amountOfBeans and amountOfMilk]
typesOfCoffe = ["FlatWhite", "Long Black"]
amountOfBeans = 500
amountOfMilk = 500
flatWhiteMilk = 5
flatWhiteBeans = 2.5
def FlatWhite(flatWhiteMilk,amountOfMilk, flatWhiteBeans,amountOfBeans):
if amountOfMilk > flatWhiteMilk and amountOfBeans > flatWhiteBeans :
amountOfMilk - flatWhiteMilk
amountOfBeans - flatWhiteBeans
print(str(amountOfMilk))
print(str(amountOfBeans))
else:
return
print("Making Flat White :)")
def CheckCoffe(typesOfCoffe, typeOfCoffe):
if typeOfCoffe in typesOfCoffe:
eval(typeOfCoffe)(flatWhiteMilk, amountOfMilk, flatWhiteBeans, amountOfBeans)
else:
print("error")
print('What Type Of Coffe?')
typeOfCoffe = raw_input()
CheckCoffe(typesOfCoffe, typeOfCoffe)
--------Results------
What Type Of Coffee?
FlatWhite
500
500
Making Flat White :)
I then tried this and did not work i got an error. i will leave my 2nd attempt and error bellow.
typesOfCoffe = ["FlatWhite", "Long Black"]
amountOfBeans = 500
amountOfMilk = 500
flatWhiteMilk = 5
flatWhiteBeans = 2.5
def FlatWhite():
global amountOfBeans
global amountOfMilk
global flatWhiteBeans
global flatWhiteMilk
if amountOfMilk > flatWhiteMilk and amountOfBeans > flatWhiteBeans :
amountOfMilk - flatWhiteMilk
amountOfBeans - flatWhiteBeans
print(str(amountOfMilk))
print(str(amountOfBeans))
else:
return
print("Making Flat White :)")
def CheckCoffe(typesOfCoffe, typeOfCoffe):
if typeOfCoffe in typesOfCoffe:
eval(typeOfCoffe)()
else:
print("error")
print('What Type Of Coffe?')
typeOfCoffe = raw_input()
CheckCoffe(typesOfCoffe, typeOfCoffe)
What Type Of Coffe?
FlatWhite
Traceback (most recent call last):
File "coffe.py", line 33, in <module>
CheckCoffe(typesOfCoffe, typeOfCoffe)
File "coffe.py", line 26, in CheckCoffe
eval(typeOfCoffe)()
File "coffe.py", line 14, in FlatWhite
if amountOfMilk > flatWhiteMilk and amountOfBeans > flatWhiteBeans :
NameError: global name 'amountOfMilk' is not defined