Python program problem - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Python program problem (/thread-5287.html) |
Python program problem - beemanjo - Sep-26-2017 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? RE: Python program problem - sparkz_alot - Sep-26-2017 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. RE: Python program problem - beemanjo - Sep-26-2017 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 RE: Python program problem - Larz60+ - Sep-26-2017 Quote:Yeah I trying to figure out how to properly format it in hereSee BBCODE link in moderator comment (you first post) RE: Python program problem - ichabod801 - Sep-27-2017 I'm locking this thread as a duplicate. Please do not post duplicate threads. |