Problems with task 1 and task 3

Hi!
I’m having issues with tasks 1 and 3.
I test them individually and the results are as required, but when I submit to the exam, they fail.

On task 1, the results are compatible with what is required, but I keep failing the test.

This also happens on task 3.

Task 3 final, after stop:

I submitted the code here, but if I’m not allowed to do it, just send me a message.

Task 1 code

from robot_control_class import RobotControl

rc=RobotControl() #Item a - Criei a instância da classe.

def get_highest_lowest ():
    b=rc.get_laser_full()
    i=0
    n=0 #Contador do maior índice
    m=0 #Contador do menor índice
    high=b[1]
    low=b[1]
    print("Starting high", high)
    print("Starting low",low)

    while(i<720):
        print("Index", i)
        print("Actual High", high)
        print("Actual Low", low)
        print("Actual High index", n)
        print("Actual Low index", m)
        if b[i]>high and b[i]!=float("inf"):
            high=b[i]
            n=i
            i=i+1
            print("New High", high)

        elif b[i]<low and b[i]<high:
            low=b[i]
            m=i
            i=i+1
            print("New Low", low)

        else:
            i=i+1
    return [m,n]

        

values=get_highest_lowest()

print ("Highest value is: ", values[0])
print ("Lowest value is: ", values[1])

Task 3

from robot_control_class import RobotControl

class ExamControl:
    def __init__(self):
        self.rc=RobotControl()
        self.rc.get_laser(0)
        self.rc.get_laser(719)

    def get_laser_readings(self):
        self.rc=RobotControl()
        le=self.rc.get_laser(719)
        ld=self.rc.get_laser(0)
        print("Esquerda: ",le) #Left
        print("Direita, ",ld) #Right
        return [le,ld] #Retorna vetor com leituras - Return a vector

      
    def main (self):
        self.rc=RobotControl()
        check=self.get_laser_readings()
        while (check[0] and check[1] !=float("inf")):
            self.rc.move_straight()
            print("Reading!")
            check=self.get_laser_readings()

        self.rc.stop_robot()
        print("Stop!")
        print("Fim!!")

mover=ExamControl()
mover.main()

Thanks for your help, and have a great 2022!
Kind regards, Gustavo Duarte

Hi Gustavo!

What exactly is failing when you submit the exam? Please note that this (passing locally but failing in the grader) might happen if you do not follow instructions for creating the files exactly as you are told in the instructions.

1 Like

Hi @bayodesegun!
When I submit the test, I have a zero on task 1 and task 3. I believe that I’m doing everything exactly as required. The results are valid.

I created the files on the required folder and name all things exactly as required.
When I submit the test, I get this message:

Kind regards, Gustavo Duarte

Hi @ghduarte,

by checking the code you posted for task 1, I see that when you check the highest value, you don’t check the lowest, and when checking the lowest, you don’t check the highest.

I think you could potentially solve it by first checking if the value is not inf.

Something like:

while (i < 720):
  i+= 1
  value = b[i]
  if value == float('inf'):
    continue
 else:
    print('Now check highest and lowest values independently')

And for task 3, I see you are instantiating the class with:

mover=ExamControl()
mover.main()

Could it be that the instructions say that you do not have to instantiate the class when submitting the quiz? I would review the instructions to make sure.

1 Like

Hi @ralves

Task 1
I found the problem on task 1. Thanks for your help.
My if and else were wrong and I was calling the method on the end of my code, going against the instructions. Now it`s working correctly :smiley:

Task 3
I solve part of the problem on task 3. I was instantiating the class incorrectly, as you said.
With my correction, the code is working on part a, but the problems persist on part b. The problem is on the main function.
Do you know what might be? My results are exactly as the problem required.

from robot_control_class import RobotControl

class ExamControl:
    def __init__(self):
        self.rc=RobotControl()
        
    def get_laser_readings(self):
        le=self.rc.get_laser(719)
        ld=self.rc.get_laser(0)
        print("Left: ",le)
        print("Right, ",ld)
        return [le,ld] #Return vectors with readings

      
    def main (self):
        check=self.get_laser_readings()
        while (check[0] !=float("inf") and check[1] !=float("inf")):
            self.rc.move_straight()
            print("Reading!")
            check=self.get_laser_readings()

        self.rc.stop_robot()
        print("Stop!")



if __name__ == '__main__':
    mover=ExamControl()
    mover.main()

Kind regards, Gustavo Duarte

According to the logs, the problem is that was missing a “:” when checking for “inf” values in the main function:

 File "task3_correct2.py", line 1, in <module>
    from task3 import ExamControl
  File "/home/user/catkin_ws/src/python_exam/task3.py", line 19
    if (check[0] == float("inf") and check[1] == float("inf"))

SyntaxError: invalid syntax
1 Like

I didnt have any logs reporting a problem, strange!! Here, its working correctly.

Ill put the code again here. I made some modifications to it, but its not working yet.

from robot_control_class import RobotControl

class ExamControl:
    def __init__(self):
        self.rc=RobotControl()
   
        
    def get_laser_readings(self):
        le=self.rc.get_laser(719)
        ld=self.rc.get_laser(0)
        print("Left: ",le)
        print("Right, ",ld)
        return [le,ld] #Return vectors with readings

      
    def main (self):
        check=self.get_laser_readings()
        while (check[0] !=float("inf") and check[1] !=float("inf")): 
            self.rc.move_straight()
            print("Reading!")
            check=self.get_laser_readings()

        self.rc.stop_robot()
        print("Stop!")



if __name__ == '__main__':
    mover=ExamControl()
    mover.main()

Hi @ghduarte

the possible reason why your script is failing is that what you are doing is:

  • You are moving forward only when there are walls on both sides

But what you have to do is:

  • Keep moving until there are no walls detected on both sides.

Your current script stops as soon as it passes the robot’s left wall, but the robot at this point has not yet gone through the robot’s right wall. Please check the expected behavior in the image below to understand what I mean here:

task3-The-Construct-robot-leaves-wall