0

I have the following code, for example:

price = 50.00
tax = price * 0.08
print "Tax = $",tax     # Tax = $ 4.0

As you can see there is a space between $ and 4.0. Is there a way to avoid this? I haven't done much Python coding.

2
Contributors
1
Reply
3
Views
11 Years
Discussion Span
Last Post by vegaseat
0

The simplest way would be to convert tax to a string and concatinate with a +. This avoids a comma, which adds one space.

price = 50.00
tax = price * 0.08
print "Tax = $",tax          # Tax = $ 4.0
print "Tax = $"+str(tax)     # Tax = $4.0

You should also look at the format string and it's % specifiers.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.