I have only began coding a week or two ago so i still dont know quite a few basics but essentially what happens is my "money" variable resets back to ten whenever the function restarts and if I put the variable outside i get an error saying that "money was referenced before assignment" I've tried other options like a global statement which still has the same issue.
def main():
money = 10.00
print('Welcome to the vending machine.')
print('The snacks available are:')
print('1. Chips - $2.50')
print('2. Chocolate Bar - $3.00')
print('3. Water - $1.90')
print('4. Cookie - $0.85')
print('5. Skittles - $2.00')
print('6. Pringles - $4.00')
print('7. Exit')
print('You have',money,'remaining!')
a = input('What would you like to purchase?')
if a == '1':
money = money - 2.5
print('You have bought chips for $2.50 you have $',money,'remaining!')
if a == '2':
money = money - 3
print('You have bought a chocolate bar for $3.00 and have $',money,'remaining!')
if a == '3':
money = money - 1.90
print('You have bought water for $1.90 and have $',money,'remaining!')
if a == '4':
money = money - 0.85
print('You have bought a cookie for $0.85 and have $',money,'remaining!')
if a == '5':
money = money - 2.00
print('You habe bought skittles for $2.00 and have $',money,'remaining!')
if a == '6':
money = money - 4.00
print('You have bought pringles for $4.00 and have $',money, 'remaining!')
c = input('Would you like to make another purchase? Y/N').upper()
if c == 'Y':
main()
if c == 'N':
exit
else:
exit
main()