Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #54514

Re: Print statement not printing as it suppose to

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <timothy.c.delaney@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'python,': 0.02; 'subject:not': 0.03; 'syntax': 0.04; 'insert': 0.05; 'output': 0.05; 'matches': 0.07; 'string': 0.09; '%s"': 0.09; 'formatting': 0.09; 'inserted': 0.09; 'python': 0.11; '(there': 0.16; 'be:': 0.16; 'simplest': 0.16; 'subject:Print': 0.16; 'weird.': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'email addr:gmail.com&gt;': 0.22; 'print': 0.22; '(or': 0.24; 'header:In- Reply-To:1': 0.27; 'tim': 0.29; 'statement': 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'parameters.': 0.31; 'prints': 0.31; 'supposed': 0.32; 'another': 0.32; 'says': 0.33; 'cases': 0.33; 'to:name:python-list': 0.33; 'problem': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'edge': 0.36; 'done': 0.36; "didn't": 0.36; 'starting': 0.37; 'thank': 0.38; 'version,': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'anything': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'space': 0.40; 'skip:u 10': 0.60; 'easy': 0.60; 'everybody': 0.60; 'simple': 0.61; "you're": 0.61; "you've": 0.63; 'total': 0.65; 'different': 0.65; 'here': 0.66; 'sam': 0.68; 'statement,': 0.68; 'subject:printing': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ivsqy4oXjol/3uO34tvkayzdG2m7u+FWE8Kd8/V2cCQ=; b=tgCQUTrZukXQKCatqdEaUbNMeEHyIPW+cVK4qqocA7SMzpZah+0J3mi6Tm0EFtEd9O VMMt4KijwJOIEBES5s08Mr7yRJsIk068SioWVElhaWiFWN28gPePE6PgPLR5bw05VvGH FLuhgHorgMyjGyTXXiY3Vz7petUNJzIOgP10qMkUvH/6wA/8UHzYXnuZyTKB/GLrSM/8 rurZeDLCHHeAJzdGailaJG+fmY/f7sd71AYc7iNZE6Waj1ceWlRHykaiqUNGTptGnbPO Eo+lnMwuZXWzgEORv0Orex/CPlIBQSDsHWipM1JDM2Upj3clmNcNL/nvzngbzn3lm4KA Tilw==
MIME-Version 1.0
X-Received by 10.68.137.1 with SMTP id qe1mr10492086pbb.25.1379715086559; Fri, 20 Sep 2013 15:11:26 -0700 (PDT)
In-Reply-To <05bbf1a3-6480-48ee-8984-2482b90c79c0@googlegroups.com>
References <05bbf1a3-6480-48ee-8984-2482b90c79c0@googlegroups.com>
Date Sat, 21 Sep 2013 08:11:26 +1000
Subject Re: Print statement not printing as it suppose to
From Tim Delaney <timothy.c.delaney@gmail.com>
To Python-List <python-list@python.org>
Content-Type multipart/alternative; boundary=047d7b2e3efca0307104e6d7f3a7
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.202.1379715089.18130.python-list@python.org> (permalink)
Lines 81
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1379715090 news.xs4all.nl 15933 [2001:888:2000:d::a6]:45952
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:54514

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On 21 September 2013 07:57, Sam <anasdahany@gmail.com> wrote:

> hi everybody i am just starting to learn python, i was writing a simple
> i/o program but my print statement is acting weird. here is my code i want
> to know why it prints this way. thank you
>
> print("\nThe total amount required is ", total )
>
>
> OUTPUT
>
> ('\nThe total amount required is ', 3534)
>
> ===> the problem is obviously on the last print statement that is supposed
> to print the outut
>

Check your version of Python. The output you have given says that you're
using a Python 2 version, but the print syntax you're using is for Python
3. Unfortunately, you've hit one of the edge cases where they produce
different output.

As a general rule, either use % formatting or format()to produce a single
string to print, rather than relying on print to output them correctly for
you (or using string concatenation). Since you're only just starting you
won't have got to them yet - the simplest way to to it is to just insert
the string representation of all parameters. The above done using %
formatting would be:

print("\nThe total amount required is  %s" % (total,))

which will produce the same output on both Python 2 and Python 3. Note the
double space before %s - that matches your print statement (there would be
soft-space inserted in your print statement, which is another reason not to
rely on print for anything other than single strings). If you didn't want
that extra space, it's easy to delete.

Tim Delaney

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Print statement not printing as it suppose to Sam <anasdahany@gmail.com> - 2013-09-20 14:57 -0700
  Re: Print statement not printing as it suppose to Tim Delaney <timothy.c.delaney@gmail.com> - 2013-09-21 08:11 +1000
  Re: Print statement not printing as it suppose to Emiliano Carlos de Moraes Firmino <emiliano.firmino@gmail.com> - 2013-09-20 18:11 -0400
  Re: Print statement not printing as it suppose to John Gordon <gordon@panix.com> - 2013-09-20 22:40 +0000
  Re: Print statement not printing as it suppose to Chris Angelico <rosuav@gmail.com> - 2013-09-21 12:50 +1000
  Re: Print statement not printing as it suppose to Dave Angel <davea@davea.name> - 2013-09-21 04:40 +0000

csiph-web