-2
Line 14: radius = radius + 25

Error message:

UnboundLocalError: local variable 'radius' referenced before assignment on line 14

I have no idea why this is throwing an error. as far as I'm aware the computer's just being dumb...

I have another question, and I am not waiting two days for an answer. 
but a bit of backstory is necessary. I'm using CodeHS to learn Python. I'm on lesson 2.12.5, and this is my code.
`
global sidereal
sidereal=int(input("How large do you like your squares? (1-400)")
def squaretine():
    for i in range(4)
        pendown()
        forward(sidereal)
        left(90)
        penup()
squaretine()
`
And this is my error:
ParseError: bad input on line 3

I could't even tell you what's wrong, I personally don't see any errors...



3 Answers3

0

Most likely, you are doing an operation on radius before the variable is created. You have to create it before as follows :

# x the value you want to give to radius
radius = x
radius = radius + 25
vlemaistre
  • 3,301
  • 13
  • 30
0

You are doing it inside a function, and since you are modifying it, python thinks you are refering to a local variable. Add global radius to the beginning of your function

blue_note
  • 27,712
  • 9
  • 72
  • 90
0

try this.

radius = 0
def something():
    global radius
    radius = radius + 25
    return radius

The reason this happens is that you can only access global variables from a def function so you have to declare it as global beforehand. You also have to declare the variable before you modify it using itself.

Dadu Khan
  • 369
  • 2
  • 16