0

A question from a beginner:

  1. Can someone explain to me please why the method change_pos isn't working and doesn't change the sitting position from True to False (and either the opposite way) in the following code?

  2. How do I implement this change_pos method to whole instances (p1, p2) in one line of code?

class Person:
    def __init__(self, name, Personality, isSitting):
        self.name=name
        self.Personality = Personality
        self.isSitting=isSitting 

    def sit_down(self):
        self.isSitting=True

    def stand_up(self):
        self.isSitting=False

    def change_pos(self):
        if (self.isSitting==True):
            self.isSitting==False
        else: 
            self.isSitting==True

p1=Person("Alice", "aggressive", False)
p2=Person("Becky", "talkative", True)

print (p1.name,'is', p1.isSitting ,'about sitting')
print (p2.name,'is', p2.isSitting ,'about sitting')

p2.change_pos()

print (p1.name,'is', p1.isSitting ,'about sitting')
print (p2.name,'is', p2.isSitting ,'about sitting')

The output is:

Alice is False about sitting
Becky is True about sitting
Alice is False about sitting
Becky is True about sitting
PM 2Ring
  • 54,345
  • 6
  • 82
  • 182
Eli
  • 31
  • 1
  • 2

0 Answers0