# Explicit String Conversion

#1

Explicit String Conversion

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!
Instructions

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

?
Hint

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

Can you convert the number 3.14 into a string?

#2

your code wiil be like this
`str(3.14)`

#3

I have tried but I keep getting an error message

I posted the code like this: str(3.14).

It said that I wrote str(3.14) but not what it asked which the value of pi is around 3.14.

#4

attention

``````>>> a = 3.14
>>> type(a)
<type 'float'>
>>> b = str(a)
>>> b
'3.14'
>>> type(b)
<type 'str'>
>>> str(3.14)
'3.14'
>>> c = 'num' + str(3.14) + 'is good'
>>> c
'num3.14is good'``````

that s mean not impossible, if you are test code online may be this bug was from that site(report to them), please install python on you OS and test in your command line.

if not solved you can insert your code in here. may be your code have some thing wrong

#5

The solution is: str(3.14)
print "The value of pi is around " + "3.14"
You have to put the quotations on the end string.

#6

here is the code to finish it print str() + "The value of pi is around " + "3.14"