Re: [Tutor] Basic question on spaces

2011-07-20 Thread Alan Gauld

Alexander Quest wrote:


As you can see, this is quite rudimentary; I have not discovered any special
function that eliminates spaces yet, if such a function exits. 


There was a thread on this a week or so back.
There you will find several suggestions however, in Python 3 the
simplest is probably to use print() itself. print takes a couple of 
optional parameters, one of which defines the separator character, by 
default a space. You can specify an empty string instead and then hard 
code your spaces.


Try
 help(print)

for more details.


The other options include using a format string  or string concatenation 
to create the string you want before you send it to print.


HTH,

Alan G.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Basic question on spaces

2011-07-19 Thread Alexander Quest
Hello; I'm a new student of Python using Python Programming for Absolute
Beginners 3rd edition by Michael Dawson as my guide. This is a basic
question regarding spaces. I'm not sure how to make it so spaces do not show
up between variables and basic strings, particularly before commas and after
dollar signs, as in the simple tipper program I have below.


#Tip program: calculates 15% and 20% tip for a given bill.

bill = int(input(Hello! Welcome to the tipper program. \nWhat is the amount
of 
 your bill, in dollars please: ))

percent15 = bill * .15
percent20 = bill * .20
print(\nOkay, based on that bill, a 15% tip would be $, percent15, , and
\n
  a 20% tip would be $, percent20, .)
input(\n\nPress the enter key to exit.)



As you can see, this is quite rudimentary; I have not discovered any special
function that eliminates spaces yet, if such a function exits. The problem
is, as stated above, unwanted spaces after both dollar signs, before the
comma after '15.0' and before the period after '20.0. Apologies for asking
such a basic question, but any help will be appreciated.

-Alex
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Basic question on spaces

2011-07-19 Thread Steve Willoughby

On 19-Jul-11 20:39, Alexander Quest wrote:

Hello; I'm a new student of Python using Python Programming for
Absolute Beginners 3rd edition by Michael Dawson as my guide. This is a
basic question regarding spaces. I'm not sure how to make it so spaces
do not show up between variables and basic strings, particularly before
commas and after dollar signs, as in the simple tipper program I have
below.


You don't want to use print with a comma-separated list of values, then. 
 Your best bet would be the format string method, like this:


print 
Okay, based on that bill, a 15% tip would be ${0}, and
a 20% tip would be ${1}.
.format(percent15, percent20)


--
Steve Willoughby / st...@alchemy.com
A ship in harbor is safe, but that is not what ships are built for.
PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor