Python Forum
Python program problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python program problem
#1
please give a runnable sample of your code with the full error text or a clear description of the problem

I TYPE IN THIS CODE:

total = 0

def adding_report(report = "T"):
while True:
integer = input("Input an integer to add to the total or 'Q' to quit: ")
total = total + integer
items = (integer/n)
if integer.isdigit():
if report == "A":
print("Items"/n/n, Integer)
break
elif report == "T":
print(total)
break
elif integer.startswith().lower("Q"):
break
else:
print("Input is invalid")
return report

adding_report("A")

AND THEN I GET THIS ERROR

Input an integer to add to the total or 'Q' to quit: 5
---------------------------------------------------------------------------
UnboundLocalError Traceback (most recent call last)
<ipython-input-2-7df26b21c5bc> in <module>()
19 return report
20
---> 21 adding_report("A")
22

<ipython-input-2-7df26b21c5bc> in adding_report(report)
4 while True:
5 integer = input("Input an integer to add to the total or 'Q' to quit: ")
----> 6 total = total + integer
7 items = (integer/n)
8 if integer.isdigit():

UnboundLocalError: local variable 'total' referenced before assignment

WHAT AM I DOING WRONG?
#2
Hard to tell, since you did not post your code or error correctly, hence can't tell what is intended to be indented. Please re-post properly.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
#3
Yeah I trying to figure out how to properly format it in here! How do I do it so that the indentations show up. Using spaces doesn't seem to work
#4
Quote:Yeah I trying to figure out how to properly format it in here
See BBCODE link in moderator comment (you first post)
#5
I'm locking this thread as a duplicate. Please do not post duplicate threads.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures


Possibly Related Threads…
Thread Author Replies Views Last Post
  python program problem beemanjo 5 4,104 Sep-27-2017, 03:20 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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