I'm just starting to learn python and keep getting an error that I just can't figure out. Any help would be massively appreciated. Basically, I keep getting the following error:
Enter an int: 8
Traceback (most recent call last):
File "C:\Users\Samuel\Documents\Python Stuff\Find Prime Factors of Number.py", line 16, in <module>
once_cycle()
File "C:\Users\Samuel\Documents\Python Stuff\Find Prime Factors of Number.py", line 8, in once_cycle
while x==0:
UnboundLocalError: local variable 'x' referenced before assignment
I see lots of people are having the same problem, but when I look at what people have told them to do I can't figure it out. Anyway, my code is this. I've re-checked all my indentation and can't see a problem with it. The aim of this program is to find the prime factors of an int (although it's only 90% complete). It's written in Python 2.7.3.
import math
testedInt = float(raw_input("Enter an int: "))
workingInt = testedInt
x = 0
def once_cycle():
for dividor in range(1, int(math.floor(math.sqrt(testedInt))+1)):
while x==0:
print "Called"
if (workingInt%dividor == 0):
workingInt = workingInt/dividor
x = 1
if (workingInt > 1):
once_cycle()
return
once_cycle()
print workingInt
Thanks in advance for any help,
Sam