How to put a string and a float as an answer | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to put a string and a float as an answer

How can you get as output -"Distance =" + (distance)- For example distance = int(input()) print("the distance =" + distance) And that you get as output "the distance = 5" next to each other?

17th Jul 2022, 9:05 AM
Pot Lood
Pot Lood - avatar
6 Answers
+ 5
Pot Lood , not to forget that we do this task without any conversion, just use comma to separate the arguments of print() function. we also need no additional spaces... ... print("the distance =", distance)
17th Jul 2022, 4:57 PM
Lothar
Lothar - avatar
+ 4
+ str(distance)
17th Jul 2022, 9:13 AM
A͢J
A͢J - avatar
+ 4
Korkunç el Gato , using print() with concatenation (+) of arguments: we have to put additional spaces as a separator between the values using print with comma between arguments: space is inserted automatically
19th Jul 2022, 5:13 PM
Lothar
Lothar - avatar
+ 2
Dang thank you
17th Jul 2022, 9:16 AM
Pot Lood
Pot Lood - avatar
+ 1
Lothar If you had to concatenate you would have used spaces though, right? Just trying to make sure.
18th Jul 2022, 10:59 AM
Korkunç el Gato
Korkunç el Gato - avatar
+ 1
Lothar I wasn't quite sure if you also advised to not put any for concatenation inside print. I kind of doubted if my memory of what I read about python conventions was wrong. Thanks :-)
20th Jul 2022, 5:54 AM
Korkunç el Gato
Korkunç el Gato - avatar