Hello everyone,
I have a robot class and a person class, I am trying to do the following:
1. find the person who is sitting
2. then use input function to type in robot's name
3. assign the robot to the person who is sitting
I am having trouble with the first step which when I loop through the person dictionary, it is not able to find the person who is sitting. If anyone could provide some guidance that would be great, or maybe redirect my approach if it is not right. Thanks!
I have a robot class and a person class, I am trying to do the following:
1. find the person who is sitting
2. then use input function to type in robot's name
3. assign the robot to the person who is sitting
I am having trouble with the first step which when I loop through the person dictionary, it is not able to find the person who is sitting. If anyone could provide some guidance that would be great, or maybe redirect my approach if it is not right. Thanks!
#robot class, with object name, color, weight, and selfintroduce function
class Robot():
def __init__ (self, name, color, weight): #defining attributes name, color, weight
self.name = name
self.color = color
self.weight = weight
def selfintroduce(self): #defining selfintroduce function
print("The robot name is", self.name)
print("The color is",self.color)
print("The weight is",self.weight)
robots = {"zero":Robot("Zero","white","100lb"),"r2d2":Robot("R2D2", "blue", "200lb")}
class Person():
def __init__ (self, name, personality, sitting):
self.name = name
self.personality = personality
self.sitting = sitting
def sit_down(self):
self.sitting = True
def stand_up(self):
self.sitting = False
p = {"alice":Person("Alice","Aggressive",False), "becky":Person("Becky","Talkative",True)}
print('The list of people are: '+', '.join(p.keys()))
#print(bool(Person.sit_down(p["becky"]))) #how come this doesnt return the right boolean?
#find the person who is sitting, then input robot, assign the robot to the person.
#assign_robot = input('assign a robot to the person who is sitting\n')
for key, value in p.items():
if p[key].sit_down() is False:
print(key) # wont print anything, why
