Error Bug in Prerequisites Exam , with Solution to fix it

Dear TheConstruct Team ,

Greeting ,

There is bug with Prerequisites Exam in file
robot_control_class.py

The Path for the file :
/home/simulations/public_sim_ws/src/all/ros_basics_examples/python_course_class/robot_control_class.py

The Error shown here and which is line 159 :

The Output in Terminal showing This :

Current distance to wall: 3.320596
Current distance to wall: 2.573591
Current distance to wall: 1.831416
Current distance to wall: 1.075487
Traceback (most recent call last):
  File "task2.py", line 29, in <module>
    robotcontrol.turn(90, -1, 1.8)
  File "/home/simulations/public_sim_ws/src/all/ros_basics_examples/python_course_class/robot_control_class.py", line159, in turn
    s = "Turned robot " + clockwise + " for " + str(time) + " seconds"
TypeError: cannot concatenate 'str' and 'int' objects

This error is occurring because you are trying to concatenate a string and an integer using the + operator. You need to convert the integer value to a string using the str() function before you can concatenate it with the string.

Here is an example of how you can fix this error:

s = "Turned robot " + clockwise + " for " + str(time) + " seconds"

Alternatively, you can use string formatting to create the string:

s = "Turned robot {} for {} seconds".format(clockwise, time)

The Result Disappear the error , proof :

2 Likes