# Task 1 and task 3 - work's but I can't pass exam

**URL:** <https://get-help.theconstruct.ai/t/task-1-and-task-3-works-but-i-cant-pass-exam/31756>\
**Category:** ROS Prerequisites Exam\
**Created:** [August 12, 2024, 9:28am UTC](https://get-help.theconstruct.ai/t/task-1-and-task-3-works-but-i-cant-pass-exam/31756 "2024-08-12T09:28:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rimmhomeem](https://get-help.theconstruct.ai/letter_avatar_proxy/v4/letter/r/fbc32d/32.png) [@rimmhomeem](https://get-help.theconstruct.ai/u/rimmhomeem)\
**Post date:** [August 12, 2024, 9:28am UTC](https://get-help.theconstruct.ai/t/task-1-and-task-3-works-but-i-cant-pass-exam/31756/1 "2024-08-12T09:28:16Z")

</div>

Hello there.

My task 1 and 3 code below. That’s wrong? May You help my.

TASK 1

#!/usr/bin/env python  
from cmath import inf  
from robot\_control\_class import RobotControl

robotcntl = RobotControl()

l = robotcntl.get\_laser\_full()

def get\_highest\_lowest(list\_check):  
max = 0  
i = 0  
for value1 in l:  
if value1 \> max and value1 != inf:  
max = value1  
max\_pos = i + 1  
i+=1  
min = max  
i = 0  
for value2 in l:  
if value2 \< min:  
min = value2  
min\_pos = i + 1  
i+=1  
return [max\_pos, min\_pos]  
#pos\_list = get\_highest\_lowest(l)  
#print (l)  
#print ("The position of higher value in the list is: ", pos\_list[1])  
#print ("The position of lowest value in the list is: ", pos\_list[0])

TASK 3

#!/usr/bin/env python3  
from robot\_control\_class import RobotControl  
from cmath import inf  
class ExamControl:  
def **init** (self,motion,speed):  
self.rc = RobotControl(robot\_name=“turtlebot”)  
self.motion = motion  
self.speed = speed

```
def get_laser_readings(self):
    self.dis_right = self.rc.get_laser(0)
    self.dis_left = self.rc.get_laser(719)
    return [self.dis_left, self.dis_right]
def do_forward(self):
    self.rc.move_straight()
def stops_robot(self):
    self.rc.stop_robot()
def main(self):
    self.mr1 = ExamControl('forward', self.speedspeed)
    self.mr1.do_forward()
    self.dis = self.mr1.get_laser_readings()
    while (self.dis[0] != inf) or (self.dis[1] != inf):
        self.mr1.do_forward()
        self.dis = self.mr1.get_laser_readings()
    self.mr1.stops_robot()

```

#mr2 = ExamControl(‘forward’, 0.4)  
#mr2.main()

---

<div class="post-metadata">

**Author:** ![roalgoal](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/roalgoal/32/7280_2.png) [@roalgoal](https://get-help.theconstruct.ai/u/roalgoal)\
**Post date:** [August 13, 2024, 7:46am UTC](https://get-help.theconstruct.ai/t/task-1-and-task-3-works-but-i-cant-pass-exam/31756/2 "2024-08-13T07:46:41Z")

</div>

Hi @rimmhomeem, could you please briefly summarize what tasks 1 and 3 are? What exactly is the description to pass the exam? Maybe you are missing an instruction.

As for the code you shared, it is really hard to read unformatted. To do so, please wrap your code in three ` symbols:

```auto
this is an example

```

It seems like you did so in the task 3 code for some of it. It’s really hard to help you with only the code pasted, we need more context.

---

<div class="post-metadata">

**Author:** ![rimmhomeem](https://get-help.theconstruct.ai/letter_avatar_proxy/v4/letter/r/fbc32d/32.png) [@rimmhomeem](https://get-help.theconstruct.ai/u/rimmhomeem)\
**Post date:** [August 13, 2024, 8:34am UTC](https://get-help.theconstruct.ai/t/task-1-and-task-3-works-but-i-cant-pass-exam/31756/3 "2024-08-13T08:34:03Z")

</div>

Hello roalgoal.

I’ve made some changes in my code Task 2 - and pass Task 3 and Exam with scope 8.5!  
Why Task 2?  
In my view - the bot checks final position - so only made a little change in final angle position (Task 2) and got a green mark in Task3 scope.  
Only one question left - what is wrong in code Task 1? I’ve checked it many times - maybe laser distance can be different while the bot checks the task?

TASK 1

```auto
#!/usr/bin/env python
from cmath import inf
from robot_control_class import RobotControl

robotcntl = RobotControl()

l = robotcntl.get_laser_full() 

def get_highest_lowest(list_for_check):
    max = 0
    i = 0
    pos = [0, 0]
    for value1 in l:
        if (value1 > max) and (value1 != inf):
            max = value1
            pos[0] = i + 1
        i+=1
    min = max
    i = 0
    for value2 in l:
        if value2 < min:
            min = value2
            pos[1] = i + 1
        i+=1
    return pos

```

Thnx in advance!

Respectfully  
R.

---

<div class="post-metadata">

**Author:** ![rimmhomeem](https://get-help.theconstruct.ai/letter_avatar_proxy/v4/letter/r/fbc32d/32.png) [@rimmhomeem](https://get-help.theconstruct.ai/u/rimmhomeem)\
**Post date:** [August 13, 2024, 8:47am UTC](https://get-help.theconstruct.ai/t/task-1-and-task-3-works-but-i-cant-pass-exam/31756/4 "2024-08-13T08:47:22Z")

</div>

Hi roalgoal.

I’ve got a screenshot how Task 1 works after few execution in a row -

 ![Capture](https://get-help.theconstruct.ai/uploads/default/original/2X/4/4f54452f02c60ce4083088316d5655b5d533c604.jpeg)

– Each time the results are different ! Maybe it was a reason why I can’t pass an exam Task1?

---

<div class="post-metadata">

**Author:** ![roalgoal](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/roalgoal/32/7280_2.png) [@roalgoal](https://get-help.theconstruct.ai/u/roalgoal)\
**Post date:** [August 14, 2024, 7:47am UTC](https://get-help.theconstruct.ai/t/task-1-and-task-3-works-but-i-cant-pass-exam/31756/5 "2024-08-14T07:47:14Z")

</div>

Task 1, summarized, is asking you to find the highest and lowest value of a list of laser readings, and return its position.

In your code, once you find `max`, you assign that value as `min` and start looping through the list to check for a smaller value. So the logic makes sense.

I’d say the fluctuation is due to the noise of the laser readings, because the `min` seems to stay in the same region.

One thing you can do is check the length of the list, move the robot, and see if the results make sense. Usually, the robot laser starts at the back and goes around counter-clockwise, so you can figure out if the results you are seeing make sense.

---

<div class="post-metadata">

**Author:** ![system](https://get-help.theconstruct.ai/uploads/default/original/2X/9/9d3ce8305cc0d0d9b6e07d15767a6f245c526f1b.jpeg) [@system](https://get-help.theconstruct.ai/u/system)\
**Post date:** [August 19, 2024, 7:47am UTC](https://get-help.theconstruct.ai/t/task-1-and-task-3-works-but-i-cant-pass-exam/31756/6 "2024-08-19T07:47:27Z")

</div>

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