This is the code, it should take an average of ether x or y coordinates when called how ever when y is called it gives an error.
import turtle
turtle.setup()
A = turtle.Turtle()
####################################################
total_of_x_scores = 0
total_of_y_scores = 0
number_of_x_scores = 0
number_of_y_scores = 0
average = 0
def average(axis):
global total_of_x_scores
global total_of_y_scores
global number_of_x_scores
global number_of_y_scores
global average
if axis=='x'or'X':
x=A.xcor()
total_of_x_scores += x #adding curent score
number_of_x_scores += 1
average=total_of_x_scores/number_of_x_scores
else:
y=A.ycor()
total_of_y_scores += y #adding curent score
number_of_y_scores += 1
average=total_of_y_scores/number_of_y_scores
return average
######################################################
while True:
A.goto(100,100)
print('x',average('x'))
print('y',average('y'))
and this is the error, notice that it doesn't error on the x
x 100.0
Traceback (most recent call last):
File "C:/Users/Jack/Desktop/average def.py", line 34, in <module>
print('y',average('y'))
TypeError: 'float' object is not callable