Python exam Task1

Hello,
I am trying to solve task 1 in the Python exam in many ways but it tells me that my solution is wrong. here is the code
"

from robot_control_class import RobotControl
import math

def get_highest_lowest(laser_readings):
    read_max = 0
    read_min = math.inf
    i_max = None
    i_min = None

    for i, read in enumerate(laser_readings):
        if read == math.inf:
            continue
        elif read < read_min:
            read_min = read
            i_min = i
        elif read > read_max:
            read_max = read
            i_max = i

    return i_max, i_min

# Example usage:
rc = RobotControl()
laser_readings = list(rc.get_laser_full())

Can u help me with the mistakes in my code if there is?

Hi @IslamZaid

your code is the following:

def get_highest_lowest(laser_readings):
    read_max = 0
    read_min = math.inf
    i_max = None
    i_min = None

    for i, read in enumerate(laser_readings):
        if read == math.inf:
            continue
        elif read < read_min:
            read_min = read
            i_min = i
        elif read > read_max:
            read_max = read
            i_max = i

    return i_max, i_min

But the instructions say the following:

As you can see, the instructions do not say you need to have a parameter in the function that provides the laser_readings. What it says is that you create an instance of RobotControl inside your function and get the laser readings from that instace’s class functions.

Do you understand how to proceed?

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.