Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What does it do. Given the Python code below, answer the questions about it. val

ID: 3835238 • Letter: W

Question

What does it do. Given the Python code below, answer the questions about it. value = 10 class pong(): value = 15 def _ _init_ _ (self, value): value = value def bounce(self, height): self. value = height def howhigh(self): print ("Height = "+str (self. value)+" ft") class ping (): value = 5 def _ _init_ _ (self, value): self.value = value def bounce(self, height): ping, value += height def collide (self, other): other, value += self value self, value -= value def howhigh(self): print("Height = "+str (self. value) + " ft") ball 1 = ping(20) ball2 = pong(30) for i in (20, 10): ball1. bounce(i) ball2. bounce(i) ball1 .collide(ball2) balll .howhigh() ball2. howhigh () (a) Explain the scope of every variable named value in the code above. (b) Make a chart to keep track of these variables. Show how the values change after each call to bounce() or collide(). (a) What is printed out by this script?

Explanation / Answer

ANSWER::

if the variable is local the scope of the variable is used only with in the function

if the declared variable is global and the scope of the variable is throughout the program it is depends upon the where it is declared

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote