My code is running well in the terminal and giving me out the answer but not getting a grade from the auto-grader.
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).
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