Python Task1.py or Task2.py maybe

hi guys, i have problem when i grad the course i get this problem >>

[13:41:18][warn] Grading has taken longer than expected. Aborting…
Things you can check:

  • Infinite loops within your code
  • Logic within you code taking longer than specified
    Please try again and contact us if the problem persists.

how i can contact someone to grad the task & my code.
and thank you…

Hi,
Maybe we can help if you share your code and what was the requirements.

Péter

Hi @wisam-kakooz,

I was checking the logs of your penultimate submission and found the following:

  1. :green_circle: Task1, final string correctly printed
  2. :green_circle: Task2, small square performed correctly
  3. :red_circle: Task2, medium square NOT performed correctly
  4. :red_circle: Task2, big square NOT performed correctly
  5. Task3, exam2.py permissions set correctly
  6. Task3, exam3.py permissions set correctly
  7. :red_circle: Task1, highest value not detected correctly
  8. :red_circle: Task1, lowest value not detected correctly
    7-and-8 :red_circle: :red_circle: Play attention here. You may be confusing the laser positions/indexes.
  9. Task2, left laser value is correct

Then the logs for the last submission:

  1. Task2, small square performed correctly
  2. Task2, medium square performed correctly
  3. Task2, big square performed correctly
  4. Task3, exam1.py permissions set correctly
  5. Task3, exam2.py permissions set correctly
  6. Task3, exam3.py permissions set correctly
  7. :red_circle: Task1, highest value not detected correctly
  8. :red_circle: Task1, lowest value not detected correctly

The warning messages say:

[assess] Python Task 1: highest value NOT detected correctly
Check:

  • Adjust the Python script task1.py according to the instructions and specifications (mark: 5.00)

and also:

Python Task 2: task2.py NOT found
Aborting further checks. Check:

  • Please create /home/user/catkin_ws/src/python_exam/task2.py

Also

Python Task 3: task3.py NOT found
Aborting further checks. Check:

  • Please create /home/user/catkin_ws/src/python_exam/task3.py
import math
from robot_control_class import RobotControl

def get_highest_lowest():
    control = RobotControl()
    values_positions_list = []

    # Iterate over laser readings from 0 to 719
    for i in range(720):
        laser_value = control.get_laser(i)
        # Filter out "inf" values and add numeric values with their positions to the list
        if isinstance(laser_value, (int, float)) and not math.isinf(laser_value):
            values_positions_list.append((laser_value, i))

    # If no valid laser values found, return empty lists for both positions
    if not values_positions_list:
        return [], []

    # Find the highest and lowest numeric values and their positions
    highest_value_position = max(values_positions_list, key=lambda x: x[0])[1]
    lowest_value_position = min(values_positions_list, key=lambda x: x[0])[1]

    # Print the positions of the lowest and highest numeric values
    print("Position of highest value:", highest_value_position)
    print("Position of lowest value:", lowest_value_position)

    # Return the positions
    return [lowest_value_position], [highest_value_position]
from robot_control_class import RobotControl

def get_highest_lowest():
    control = RobotControl()
    values_positions_list = []

    # Iterate over laser readings from 0 to 719
    for i in range(720):
        laser_value = control.get_laser(i)
        # Discard "inf" values
        if not isinstance(laser_value, float) or not float('-inf') < laser_value < float('inf'):
            # Add numeric values with their positions to the list
            if isinstance(laser_value, (int, float)):
                values_positions_list.append((laser_value, i))
    values_positions_list.sort()

    # If no valid laser values found, return empty list
    if not values_positions_list:
        return []

    # Find the highest and lowest numeric values and their positions
    lowest_value_position = min(values_positions_list, key=lambda x: x[0])[1]
    highest_value_position = max(values_positions_list, key=lambda x: x[0])[1]
    print([lowest_value_position, highest_value_position])
    # Return the positions sorted in a single list
    return [lowest_value_position, highest_value_position]

Hi,
I do not know the requirements, but maybe the “position” is not the ranges index, but an angle in radian.

About your algorithm:
I think, it is ok, but IMHO
a) it can be faster, if you pick the min and max values in the first loop. In that case, you do not have to store all the values and indexes and iterate again for max and iterate again for min.
b) it can be shorter (in code length) you can use numpy argmax/argmin instead of loops
But these are not serious things.

I found another interesting part:
values_positions_list.sort()
I do not know, how this sorts your list, but if you can sort the list by range value,
your min will be in the first position and your max will be at the last position, so no need to use min/max.
But sorting an array is very slow, I rather use a) option only. That is only O(n), so probably the fastest.

Péter

Hi @wisam-kakooz,

I see you are calling control.get_laser(i), but you could just call laser_values = control.get_laser_full() once and iterate over those values.

I think your solution is a bit complex.

You could just set initial values for indexes, and initial values, and compare the values in the indexes to find the higher and lower indexes.

Example:

higher_index = lower_index = -1
higher_value = -1
lower_value = 100000

# now, iterate over the laser_values and compare them:
for value in laser_values:
 # do the checks now, and set the 4 variables defined above.
 # At the end of this loop you will already have the values you are looking for.

Also, I see that sometimes you return [] and sometimes [value1, value1].
If the code that calls your function expects two values, you should always return two values. So, instead of returning [], you could return [lower_index, higher_index], for example, but the error is not exactly at this point.

Please consider the code example I provided above.

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