For some reason Money
doesn't change to 8 as it should; it always stays at 10.
Money = 10
Resto = 0
ApplePrice = 2
def buy(current, price):
Money == current - price
return Money
buy(Money, ApplePrice)
print(Money)
For some reason Money
doesn't change to 8 as it should; it always stays at 10.
Money = 10
Resto = 0
ApplePrice = 2
def buy(current, price):
Money == current - price
return Money
buy(Money, ApplePrice)
print(Money)
Rather than altering the global variable I'd recommend keeping your variables as they are & using the return value from buy()
;
money = buy(MONEY, APPLEPRICE)
print(money)
You've also got a problem with the calculation in the function.
You would want this, defining your constants first.
MONEY = 10
RESTO = 0
APPLEPRICE = 2
def buy(current, price):
money = current - price
return money
money = buy(MONEY, APPLEPRICE)
print(money)
I know docs aren't that interesting, but take a look over PEP8 as it will help you write good code to a standard most of us try to match.