Got stuck again python exam

Although I have obtained the certificate, I still want to improve my ability through the third question of python, but I don’t know why the class I wrote can’t pass the test.


here is the code, please help me!

I really don’t know why :face_with_monocle:

Hello @YuvaanWang ,

There are some things wrong with your class. Basically:

  • You don’t have a constructor of the class to initialize things
  • The variable rc should be defined as self.rc
  • Imort should be done outside the class

Here you have your class with these fixes:

from robot_control_class import RobotControl

class ExamControl:

    def __init__(self):
        self.rc = RobotControl()

    def get_laser_readings(self):
        a = self.rc.get_laser(0)
        b = self.rc.get_laser(719)
        return b, a

    def main(self):
        while True:
            right = self.rc.get_laser(0)
            left = self.rc.get_laser(719)
            if (right == float("inf")) and (left == float("inf")):

It should work properly now.


1 Like

Thank you very much, I have learn a lot from that.