-1

Whenever I go to print out a GBP sign followed by a number I get this error code.

Traceback (most recent call last):
  File "main.py", line 65, in <module>
    print (u"\xA3" + total_cost)
TypeError: can only concatenate str (not "float") to str

This is the code.

total_cost == 10
print (u"\xA3" + total_cost)

I would like for it to output £10.

Can someone help please?

  • Simplest would be to use `,` instead of `+` inside the `print` or then just cast the `total_cost` to string with `str(total_cost)`. If you want to control the number of digits printed, use f-strings. – Niko Föhr Feb 26 '21 at 09:52

3 Answers3

0

You could try to convert the number to a string using the str() function. It's not very efficient for a lot of computations though so beware :)

print(u"\xA3" + str(total_cost))
L. Landenne
  • 88
  • 2
  • 9
0
>>> print (u"\xA3", total_cost, sep='')
£10
Fedor Dikarev
  • 506
  • 3
  • 9
0

try this:

print (u"\xA3" + str(total_cost))

M.Noe
  • 58
  • 4