Code Foundation for ROS EXAM,task1.py

What is wrong in my code ,please help

Hello,

Try pasting the code here and the error message if any.

1 Like

from robot_control_class import RobotControl

robotcontrol = RobotControl()

def get_highest_lowest():

  laser_value = robotcontrol.get_laser_full()

  new_a = list(laser_value)

  largest = new_a[0]

  lowest = new_a[0]

  for n in range(len(new_a)):

      if new_a[n] != float('inf'):

          if new_a[n] > largest:

              largest  = new_a[n]

              vallarg = n

          if new_a[n] < lowest:

              lowest = new_a[n]

              val_low = n

  return vallarg,val_low

task1 Question : 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.

Hi @vishalmaddheshiya,

I’ve been checking the logs, and the logs say that the highest and lowest values were correctly detected.

What is the feedback message that you get, that makes you think the code is not passing the test?

Cheers.

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