Prerequisites exam help (return two values in a single function)

My code is running well in the terminal and giving me out the answer but not getting a grade from the auto-grader.

Task 1

Inside the python_exam folder, create a new Python script named task1.py. Inside this script, create a function named get_highest_lowest. This function does the following:

a) First, it creates an instance of the RobotControl class.

b) Second, it gets all the values of the laser readings and it stores them into a list.

c) Then, it compares all these laser values that you have stored in the list in order to detect the highest value and the lowest one.

d) Finally, it returns the position in the list of the highest and lowest values (check Specifications).

Specifications

  • The name of the function MUST BE the one specified above: get_highest_lowest

  • Bear in mind that the function doesn’t have to return the values (highest and lowest), but the position in the list of those values.

  • Your final (after you have tested that it works properly) program MUST contain the get_highest_lowest function, but MUST NOT contain any call to this function.

  • The function has to return the position values in an specific order: first, it returns the position of the highest value and second, it returns the position of the lowest value.

  • The laser readings list may contain some values that are expressed as inf. You MUST NOT take these values into account when calculating the highest and lowest value. Only take into account the numeric values.

My CODE -

from robot_control_class import RobotControl

def get_highest_lowest():

    

    robotcontrol = RobotControl()

    inf = float('inf')

    l = robotcontrol.get_laser_full()

    l_list = list(l)

    for n, i in enumerate(l_list):

        if inf in l:

            if i == inf:

                l_list[n] = None  

    if inf in l:

        max_value = max(l_list)

        min_value = min(l)

        ind_max = l_list.index(max_value)

        ind_min = l.index(min_value)

    else:

        max_value = max(l)

        min_value = min(l)

        ind_max = l.index(max_value)

        ind_min = l.index(min_value)

    return ind_max

    return ind_min

To start look up how to return more than one value from a function. You can only have a single return per function. Also be sure to take good notes and you can even download the code used in each chapter so you have something you can look back on. To see how the exercises and examples were done.

1 Like

I am not able to scroll down to see my result ? How can I

Hi @Ankit_Kumar ,

I’m assumed you are now able to return two values in a single return statement, because as @hskramer mentioned, once the first return happens, the rest of the function is ignored.

With regards to scrolling down, this is really something we have to improve. In the meantime, a way of seeing the end of the results is by zooming out with CTRL - (control + minus).

Please let us know if you still have any questions.

Cheers,

Thank you so much ! You are doing aa= great work! kudos

Greetings, When I am running roslaunch realrobotlab main.launch command it’s giving out an error
please guide me through this

Hi @Ankit_Kumar ,

I was talking to @roalgoal and he says these error messages do not affect the simulation.

You can still work on the rosject with these error messages.

In any case, we will work on getting rid of these error messages.

Cheers,