Explicit String Conversion


Having some trouble on this one
Im putting print “I have " + 3.14 + " coconuts!” yet it say its wrong
What do I do :confused:


What are the exact instructions? :slight_smile:


Sometimes you need to combine a string with something that isn’t a string. In order to do that, you have to convert the non-string into a string.
print “I have " + str(2) + " coconuts!”

This will print I have 2 coconuts!.

The str() method converts non-strings into strings. In the above example, you convert the number 2 into a string and then you concatenate the strings together just like in the previous exercise.

Now try it yourself!


  1. Run the code as-is. You get an error!
  2. Use str() to turn 3.14 into a string. Then run the code again.



The code to turn the number 2 into a string is str(2).

Can you convert the number 3.14 into a string?


Use the str() method, like they did for “2”.


do you see why?


omg it worked, thank u so much :smiley: !


thx amanuel2 its works now


Paste your code. Plus please delete that post, one of the words may be taken offensively. Thankyou


Oops, try again. Gadzooks! A string and a float cannot be concatenated. Here’s what Python says is the error: cannot concatenate ‘str’ and ‘float’ objects


can some body plz hlp me Explicit String Conversion


Explicit String Conversion


Explicit String Conversion


I am getting “TypeError: ‘str’ object is not callable” in the exercise described above. As in,
print "The value of pi is around " + str(3.14)


follow the script of my friends ^,^
print " The value of pi is around" + str ( 3.14)

closed #14