On Fri, Feb 7, 2014 at 12:22 PM, Scott W Dunning <swdunn...@cox.net> wrote:
> Assume variables exist for minutes and seconds. Each variable is an integer.
> How would you create a string in the format,
>
> 3:11
>
> with no spaces. where 3 is minutes and 11 is seconds.
>
>
> Obviously when Iā€¦
>
> print minutes, ā€œ:ā€, seconds
>
> I get 3 : 11
>
> how can I get it to print with no spaces?
>
> 3:11

The print statement isn't right for what you're doing here. You need
to create a single string with that result, which you could then print
out.

There are two easy ways to do this. First one is to create a string
from the number of minutes, create a string from the number of
seconds, and concatenate them, with a third string (the colon) in
between. Do you know how to turn an integer into a string, and do you
know how to add strings together?

The second way is to format the values directly into a single string.
You can use printf codes for this. Check this out:

http://docs.python.org/2/library/stdtypes.html#string-formatting-operations

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to