Python task3 and 1 help

Hello everyone,

I’m stuck one tasks 1and3 on the exam. My code works for both programs but grade bot says It doesn’t work as correctly by the specifications. In the specifications, it says " Your final program (after you have tested that it works properly) MUST contain the ExamControl class, but MUST NOT contain any instance of the class." but how can it not contain any instance of the class and run the class? You need to import the class from another program?

For task3, how do you return values in specific order? Because you need to read from both sides at the same time?

Here is my code for task1:

from robot_control_class import RobotControl

def get_highest_lowest():
    rc = RobotControl()
    mx=0
    mn=rc.get_laser(0)
    # Initialize variables to hold the positions of the highest and lowest values
    pmn=1
    pmx=1
    list_laser_full =rc.get_laser_full()
    for x in list_laser_full:
        
        if x > mx and x != float('inf'): #gets maximum postion of the laser
            mx = x
            pmx = list_laser_full.index(mx)
            mn = mx      
        if x < mn: #gets minimum postion of the laser
            mn = x
            pmn = list_laser_full.index(mn)    
    return [pmx,pmn]

ret_list = get_highest_lowest()
print("Laser max position is ",ret_list[0])
print("Laser min position is ",ret_list[1])

Please give me some pointers.

Thanks,

Hi @Reggiethedogo,

Welcome to our community:

You said:

When testing your program, you normally have to instantiate the class to make sure it starts, but when submitting the quiz correction, you shouldn’t instantiate because the automated script will import your class, and then instantiate it. If you instantiate, then there will be an error because there will be two instances of your class sending instructions to the robot, for example.

Now, related to your code for task3, I’m not sure this "index() " method exists.
A possible way getting the index would be to create an index variable, and increment it on the for loop.
Example:

def get_highest_lowest():
    // other code ...
    index = 0

    for x in list_laser_full:
        
        if x > mx and x != float('inf'): #gets maximum postion of the laser
            mx = x
            pmx = index
            mn = mx      
        if x < mn: #gets minimum postion of the laser
            mn = x
            pmn = index

        index += 1

    return [pmx,pmn]

It is worth mentioning that you could also check if the number is not infinite when deciding whether the value is the minimum one.
Example:

if x != float('inf'):
    // ONLY THEN, check if is greater or smaller
    if x > mx:
      //do something
    elif x < mn:
      // do something else

I also think would be good to set the initial values of pmn and pmx to 0 (zero) instead of 1.