1) Remove random health level and make it user input. for example: If we input 0.1, Output should look like: Input heal

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

1) Remove random health level and make it user input. for example: If we input 0.1, Output should look like: Input heal

Post by answerhappygod »

1) Remove random health level and make it user input.for example: If we input 0.1, Output should look like:Input health level first between 0-1?0.1health_level of Marvin0 before healing: 0.1Marvin0 has been healed by Dr. Who!health_level of Marvin0 after healing: (0.2, 1)health_level of Marvin1 before healing: 0.2Marvin1 has been healed by Dr. Who!health_level of Marvin1 after healing: (0.3, 1)health_level of Marvin2 before healing: 0.3Marvin2 has been healed by Dr. Who!health_level of Marvin2 after healing: (0.4, 1)health_level of Marvin3 before healing: 0.4Marvin3 has been healed by Dr. Who!health_level of Marvin3 after healing: (0.5, 1)health_level of Marvin4 before healing: 0.5Marvin4 has been healed by Dr. Who!health_level of Marvin4 after healing: (0.6, 1)[('Marvin0', (0.1, 1)), ('Marvin1', (0.2, 1)), ('Marvin2', (0.3, 1)), ('Marvin3', (0.4, 1)), ('Marvin4', (0.5, 1)), ('Marvin3', (0.6, 1)),]***Modify the code below to get out put as above:***import randomclass Robot: def __init__(self, name): self.name = name self.health_level = random.random() def say_hi(self): print("Hi, I am " + self.name) def needs_a_doctor(self): if self.health_level < 0.8: return True else: return Falseclass PhysicianRobot(Robot): def say_hi(self): print("Everything will be okay! ") print(self.name + " takes care of you!") def heal(self, robo): robo.health_level = random.uniform(robo.health_level, 1) print(robo.name + " has been healed by " + self.name + "!")doc = PhysicianRobot("Dr. Who") rob_list = []for i in range(5): x = Robot("Marvin" + str(i)) if x.needs_a_doctor(): print("health_level of " + x.name + " before healing: ", x.health_level) doc.heal(x) print("health_level of " + x.name + " after healing: ", x.health_level) rob_list.append((x.name, x.health_level))print(rob_list)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply