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


Groups > comp.lang.python > #73724

Newbie coding question - format error

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!newsfeed0.kamp.net!newsfeed.kamp.net!feeder1.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.81.MISMATCH!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <shieldfire@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; 'subject:error': 0.03; 'tutorial': 0.03; 'exercise': 0.04; '<>,': 0.07; 'string': 0.09; 'sentence': 0.09; 'stating': 0.09; 'works.': 0.09; 'subject:question': 0.10; 'martin': 0.11; "'))": 0.16; 'before.': 0.16; 'indexerror:': 0.16; 'subject:coding': 0.16; 'subject:format': 0.16; 'tuple': 0.16; 'url:luc': 0.16; '{1},': 0.16; 'index': 0.16; 'obviously': 0.18; 'error': 0.23; 'integer': 0.24; 'skip:e 30': 0.24; 'question': 0.24; 'second': 0.26; 'url:edu': 0.26; 'message-id:@mail.gmail.com': 0.30; 'another': 0.32; 'says': 0.33; 'url:python': 0.33; 'third': 0.33; 'problem': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'sequence': 0.36; 'method': 0.36; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'skip:x 10': 0.40; 'how': 0.40; 'full': 0.61; 'url:3': 0.61; 'range': 0.61; 'first': 0.61; 'here:': 0.62; 'sum': 0.64; 'between': 0.67; 'results': 0.69; 'divided': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=HiOFlkvSyqgTE0v9ebtnuf57q7OMjTxZdsN1uEfQuyc=; b=kO+19CTtCRtA3iaFYMEG8Kua3U7837Jmt2bQRItw3DVHJchLBI/Kn88gB89ZaNP6SD t2fYjqq/v7Uuyfzf7yX8U8SFjRdPx68kMgr0LLMRVDJh5BpPGhUTrvpO6XMwfZl5QoVY U8wgA2XsJCwpkFO9h8MFb6kZw+LBt56DmhkyNkB6hF2UMYJ0YGBlo3N+cQ3CQC+BN6Eu 6YmB1dzuF1Ghb58LWOg8yt+TtySkCB/SYMK5PmIYs43H+wyr/5k+brZi1QQb5pE+W2Og XBI+P0ARG2mZJujLCdsqplnASeZG2kACYFmY1s7/qijmhBOalpxla1zd8i4QgTOSwLrA ah3A==
MIME-Version 1.0
X-Received by 10.52.0.177 with SMTP id 17mr525667vdf.12.1404025590027; Sun, 29 Jun 2014 00:06:30 -0700 (PDT)
Date Sun, 29 Jun 2014 09:06:29 +0200
Subject Newbie coding question - format error
From Martin S <shieldfire@gmail.com>
To python-list@python.org
Content-Type multipart/alternative; boundary=047d7b86e4f28c9b1604fcf42e70
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.11321.1404025599.18130.python-list@python.org> (permalink)
Lines 76
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1404025599 news.xs4all.nl 2941 [2001:888:2000:d::a6]:58212
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:73724

Show key headers only | View raw


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

Hi again,

Still working leisurely through the tutorial here:
http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/io.html

An excise at the end of second 1.10 says to
Write a version of the quotient problem in *Exercise for Quotients*
<http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/io.html#quotientproblem>,
quotientformat.py, that uses the string format method to construct the same
final string as before. Again be sure to give a full sentence stating both
the integer quotient and the remainder.


So I did

x=int(input('Enter an integer '))
y=int(input('Enter another integer '))
z=int(input('Enter a third integer '))
formatStr='Integer {0}, {1}, {2}, and the sum is {3}.'
equations=formatStr.format(x,y,z,x+y+z)
print(equations)
formatStr2='{0} divided by {1} is {2} with a reminder of {3}'
equations2=formatStr2.format(x,y,x//y,x%y)
print(equations2)

And obviously this works.
But the question is: if I want to keep the results of {2} and {3} between
the first instance (formatStr) and the second (formatStr2)  how would I go
about it? Apprently using {4} and {5}  instead results in a index sequence
error as in

IndexError: tuple index out of range

/Martin S
--
Regards,

Martin S

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


Thread

Newbie coding question - format error Martin S <shieldfire@gmail.com> - 2014-06-29 09:06 +0200

csiph-web