Python Forum
Vending Machine Program: Problem with variables
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Vending Machine Program: Problem with variables
#1
I'm trying to make a simple vending machine program. Running this program gives me this error:

Error:
Traceback (most recent call last):  File "C:/Users/ignacio cabero/Desktop/Python/vendingmachine.py", line 13, in <module>    insertp25()  File "C:/Users/ignacio cabero/Desktop/Python/vendingmachine.py", line 11, in insertp25    total_insert += 0.25 UnboundLocalError: local variable 'total_insert' referenced before assignment
global total_cost, total_insert
total_cost=0
total_insert=0

float(total_cost)
float(total_insert)
def insertp25():
   total_insert += total_insert + 0.25
   print(total_insert)
insertp25()
insertp25()
What can I do? I made the variables global yet nothing seems to work.
Reply


Messages In This Thread
Vending Machine Program: Problem with variables - by icabero0225 - Jun-08-2017, 04:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem program runs in a loop jasserin 0 188 May-18-2024, 03:07 PM
Last Post: jasserin
  problem using exec to save local variables dkarl 0 1,846 Dec-01-2019, 08:52 AM
Last Post: dkarl
  Problem with variables JCB 3 2,389 Nov-13-2019, 07:20 PM
Last Post: the_ophidian_order
  Problem: Once I cancel the process my program will start working! Hadad 0 1,699 Jul-24-2019, 04:09 PM
Last Post: Hadad
  Program Problem (2) ChrisG 2 2,478 May-25-2019, 05:11 PM
Last Post: ChrisG
  Program Problem ChrisG 2 2,046 May-25-2019, 11:41 AM
Last Post: ChrisG
  A problem with defining variables meru120 5 3,520 Apr-16-2019, 03:13 PM
Last Post: buran
  Problem with variables Steffenwolt 4 3,372 Jul-14-2018, 07:27 PM
Last Post: Steffenwolt
  problem running program in VScode LavaCreeperKing 4 4,042 Mar-25-2018, 04:34 PM
Last Post: LavaCreeperKing
  Program not running (Overloading problem) anurag123 2 2,669 Feb-19-2018, 07:23 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020