Python Forum
Removing extra space - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Removing extra space (/thread-18950.html)



Removing extra space - sumncguy - Jun-07-2019

The print output annoys me. Big Grin
My question is how do I get rid of the space betwen the the dollar sign and value.
I did try to search the web, but couldnt find a solution.

I am running this in Centos 7 Python 2.7.5
Output is given below, then the code.

Quote:How many copies are you buying ? 25
Unit price: $ 89
Total price: $ 2225


from __future__ import print_function
import sys, os
def cls():
    os.system('clear')

def main():
    cls()
    copur = int(raw_input('How many copies are you buying ? '))
    if copur <= 10:
         uprice = 99
    elif copur > 10 and copur <= 50:
         uprice = 89
    elif copur > 50 and copur <= 100:
         uprice = 79
    elif copur > 100:
         uprice = 69
    #tot = float(copur * uprice)
    tot = int(copur * uprice)
    print('Unit price: $',uprice)
    print('Total price: $',tot)



RE: Removing extra space - kotter - Jun-07-2019

This happens because in the print function you are using commas. This should fix it:

    
print('Unit price: $' + str(uprice))
print('Total price: $' + str(tot))



RE: Removing extra space - ichabod801 - Jun-07-2019

I prefer the format method of strings:

print('Unit price: ${}'.format(uprice))
print('Total price: ${}'.format(tot))
You should switch to Python 3 if possible. At the end of the year support for 2.7 will stop.


RE: Removing extra space - michalmonday - Jun-07-2019

Alternatively you could make use of the optional sep parameter of the print function:
print(1,2,3, sep='---')
print(1,2,3, sep='')
Output:
1---2---3 123



RE: Removing extra space - sumncguy - Jun-07-2019

Thanks ....