What is wrong with the following code:
class Ball():
def __init__(self):
self.x = 0
self.y = 0
self.change_x = 0
self.change_y = 0
x += change_x
y += change_y
Answers
Answered by
0
Correct Python Code
class Ball():
def __init__(self):
self.x = 0
self.y = 0
self.change_x = 0
self.change_y = 0
self.size = 10
self.color = [255,255,255]
def move(self):
self.x += self.change_x
self.y += self.change_y
def draw(self, screen):
pygame.draw.circle(screen, self.color, [self.x, self.y], self.size )
- A function is a section of code that only executes when called. You can supply parameters—data—to a function. As a result, a function may return data.
- A function is a group of connected claims that together carry out a mathematical, analytic, or evaluative activity. Python functions are easy to define and crucial for programming at the intermediate level. The same standards apply to variable names and function names. The objective is to define a function by grouping together a few often performed actions.
- We can call the function and reuse the code contained within it with different variables rather than repeatedly writing the same code block for different input variables.
#SPJ2
Similar questions