1

I have the following statement:

print ("You have entered the price of ",var1, "for a chocolate bar")

Which works happily however i need to put a '$' infront of it for the output. I tried hiding it in the print statement however then you end up with a gap between it so you end up with

'You have entered the price of $ 34.33 for a chocolate bar'.

I need it to be:

'You have entered the price of $34.33 for a chocolate bar'.

I am very new to python, and this is tripping me up. Any help would be appreciated. Im using python 3.3.4

cheese510
  • 81
  • 1
  • 3

2 Answers2

4

format is the recommended way to do this.

print("You have entered the price of ${0} for a chocolate bar".format(var1))
Jayanth Koushik
  • 9,476
  • 1
  • 44
  • 52
1
print "You have entered the price of ","$"+str(var1), "for a chocolate bar"
aelor
  • 10,892
  • 3
  • 32
  • 48