Introducing more than 2 variables in a print sentence

Greetings, this is my first question in the forum.
First, I would like to thank all the contructsim team because all this courses and the simulations are helping me a lot in learning ROS, Python, and everything related to Robots.

My question is simple, I was making the exercise 2.5, and I wanted to introduce the sentence:
“The distance measured by the laser number {input1} is {input2}m”
I already managed to write it ussing commas as:
print (“The distance measured by the laser number “,number,” is:”,laser,“m”)
But I tried to write it using %d inside the string, but I only managed to write one of the variables, if I put two variables it recognizes it as a string. Im writing the sentence as:
print (“The distance measured by the laser number %d is %d m” %number , %laser )

Would anyone write the great line for me? Thanks a lot, and happy codding!

give input like this
print (‘The distance measured by the laser number %d is %d m’ %(number,laser) )

2 Likes

Hi, @AngelLoGa , the answer is as @VATSAL_TYAGI mentioned. Just in case you want to know more about this, there are two ways to print multiple variables into your print statement, they are placeholder method, which is what @VATSAL_TYAGI used to print, and the format method.

The concept is explained in well at this Click LINK. Please go through it to know more.

2 Likes

Thank you both @VATSAL_TYAGI and @Joseph1001 . I used to write the sentences as this in C++ but’s been 4 years since I wrote my last program. I was a bit out of line! Thanks both of you for the help!

1 Like