Got stuck again python exam task3.py

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.

task3

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):
        self.rc.move_straight()
        while True:
            right = self.rc.get_laser(0)
            left = self.rc.get_laser(719)
            if (right == float("inf")) and (left == float("inf")):
                self.rc.stop_robot()
                break

It should work properly now.

Best,

1 Like

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

plss my certificate is not showing

Hello @official-aO ,

I’ve seen that your mark for the Exam is a 5.0. In order to get the certificate, you have to score at least an 8.0. Check where you are failing to get the points, fix your scripts and go for it!

Best,

okay sir but sir am getting stock while it telling me that my get_laser_reading is not working correctly

plsss sir all my code seems to work fine on the webshell but clicking on the correction it keep failing my task1.py and also my task3.py code have tried all possible but nothing is working out the correction keep failing it for me have been on this for days sir really need your help sir

for the task1.py this is my code

from robot_control_class import RobotControl

import math

def get_highest_lowest():

rc = RobotControl()

laser = rc.get_laser_full()

laser_dict = {}

output = []

for i, elem in enumerate(laser):

    if not math.isinf(elem):

        laser_dict[i] = elem

max_val = max(laser_dict.values())

min_val = min(laser_dict.values())

print(max_val, min_val)

for key, val in laser_dict.items():  # for name, age in dictionary.iteritems():  (for Python 2.x)

    if val == max_val:

        output.append(key)

        break

for key, val in laser_dict.items():  # for name, age in dictionary.iteritems():  (for Python 2.x)

    if val == min_val:

        output.append(key)

        break

return output

max_index, min_index = get_highest_lowest()

print(max_index, min_index)

and for my task3.py

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):

    self.rc.move_straight()

    while True:

        right = self.rc.get_laser(0)

        left = self.rc.get_laser(719)

        if (right == float("inf")) and (left == float("inf")):

            self.rc.stop_robot()

            break

    rc.stop_robot()

testMove = ExamControl()

testMove.main()

plss what is wrong with code have being on it for hours now looking for possible solutions but nothing is working and the code is running as expected on the webshell and it keep failing on the autocorrection plss help

plsss i need answer to this question it the only keeping me stock

Hello @official-aO ,

  • For the task1.py code, I see that it contains a call to the function at the end:
max_index, min_index = get_highest_lowest()
print(max_index, min_index)

Remove all this code for testing the function, as indicatedin the Specifications:

  • For the task3.py code, I see that it also contains some testing code at the end:
testMove = ExamControl()
testMove.main()

Remove it also, as indicated in the Specifications:

Hope this helps,

1 Like