Feb-05-2020, 06:22 AM
Hi All, I am trying to make the code below to be a little bit more interactive by doing the following:
1. When run the code, it will show you the list of all robots
2. Then there is an input function to ask for robot's name
3. after typing in the robot's name, it will use the selfintroduce function to display its attributes
Any help is appreciated. thanks!
1. When run the code, it will show you the list of all robots
2. Then there is an input function to ask for robot's name
3. after typing in the robot's name, it will use the selfintroduce function to display its attributes
Any help is appreciated. thanks!
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) robot1 = Robot("Zero","white","100lb") robot2 = Robot("R2D2", "blue", "200lb") c=input("enter robot's name\n") print(c.selfintroduce(self)) #doesnt work #robot1.selfintroduce() #robot2.selfintroduce()