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


Groups > comp.lang.python > #102966

Re: Syntax error (The Python Book) Linux User and Developer Bookazine

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Joel Goldstick <joel.goldstick@gmail.com>
Newsgroups comp.lang.python
Subject Re: Syntax error (The Python Book) Linux User and Developer Bookazine
Date Mon, 15 Feb 2016 10:06:34 -0500
Lines 90
Message-ID <mailman.144.1455548803.22075.python-list@python.org> (permalink)
References <caa9384e-21e1-4ac4-a719-703cc0d1f44a@googlegroups.com> <f0f27bca-9462-4f16-9b1d-a1a16dd0f8f2@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de Td4SOsI3Pc/RtvV/XjrIKQ+7dUid1nQ+B8Pd78m1HYpg==
Return-Path <joel.goldstick@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Developer': 0.03; 'offline': 0.03; 'operator': 0.03; 'received:209.85.223': 0.03; 'subject:Python': 0.05; 'sys': 0.05; 'except:': 0.07; 'false.': 0.07; 'valueerror:': 0.07; 'cc:addr:python-list': 0.09; "'''": 0.09; 'integers': 0.09; 'operator,': 0.09; 'python': 0.10; 'subject:error': 0.11; 'syntax': 0.13; 'missed': 0.15; '2016': 0.16; 'chris,': 0.16; 'incremented': 0.16; 'integer.': 0.16; 'integers,': 0.16; 'len': 0.16; 'parentheses': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'say.': 0.16; 'true:': 0.16; 'utc,': 0.16; '\xc2\xa0if': 0.16; 'wrote:': 0.16; 'string': 0.17; '&lt;': 0.18; 'copied': 0.18; 'integer': 0.18; 'skip:{ 20': 0.18; 'try:': 0.18; '&gt;': 0.18; 'email addr:gmail.com&gt;': 0.18; 'input': 0.18; 'variable': 0.18; 'changes': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '31,': 0.22; 'am,': 0.23; 'feb': 0.23; 'demonstrate': 0.23; 'import': 0.24; 'written': 0.24; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'linux': 0.26; 'rest': 0.26; 'entered': 0.27; 'error': 0.27; 'not.': 0.27; 'skip:# 10': 0.27; 'least': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'values': 0.28; 'crash': 0.29; 'convert': 0.29; "i'm": 0.30; 'print': 0.30; 'comments': 0.30; 'url:mailman': 0.30; 'code': 0.30; '15,': 0.30; 'checked': 0.31; 'subject:) ': 0.32; 'total:': 0.32; 'url:python': 0.33; 'url:listinfo': 0.34; 'except': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'false': 0.35; 'asking': 0.35; 'but': 0.36; 'skip:i 20': 0.36; 'there': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'skip:{ 10': 0.36; 'structures': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'thanks': 0.37; 'list.': 0.37; 'received:209': 0.38; 'hi,': 0.38; 'whatever': 0.39; 'url:mail': 0.40; 'mark': 0.40; 'some': 0.40; 'collection': 0.60; 'reached': 0.60; 'your': 0.60; 'determine': 0.61; 'subject:The': 0.61; 'skip:u 10': 0.61; 'total': 0.62; 'yes': 0.62; 'more': 0.63; 'here': 0.66; 'skip:\xc2 10': 0.67; 'worth': 0.67; '8bit%:21': 0.70; 'online': 0.71; 'collection,': 0.84; 'succeeds': 0.84; 'to:none': 0.91; 'joel': 0.91
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:cc :content-type; bh=mjW4vGBwBYJgplNIWpLpIl/OZdeuqCu+cJ9wQVHB8bU=; b=koDiJr6RwZXocRmjiKbIxqX4zEWBgjU4FSTNYXkAGmbVcI/X0sKr9/7XOhUDtXgU2K 0KYZaub9t12DmarjItjMqBVa8yNT6I3QFUrnS+BevGLdqFvD7piDPoKy+4LHc4RoZdOj f0f7ZyNYHkWAzuZzmNIy8iGNFEu1sMfieUauyUzz5zQLK0eJ6Na9PzaAr2CxX8asw452 d0KKebL+Z5f7ZlfaDuJicG/EfFoN5AHIu10tq/ZTqwQCV9np3X7a3usnfSz+ylpHWrEK 1FpNrBaVL9FZzKrPJfwiQuQIdMBElD58iJd7/pO/g3aNLkSdgycsPC6OU2/fBFoiuq3g gPsA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc:content-type; bh=mjW4vGBwBYJgplNIWpLpIl/OZdeuqCu+cJ9wQVHB8bU=; b=F1AjtcZ0GvJj9TZG9ocQ0k/oBOt2qHnDOMnV23ckrLZy0KkKBwdnamttyeqxqwrcKh xwaAff1mSOIrZrbVPbIpYxM1330qCHq8TSFmNaznq8FoT2DBIO2a/gL7icSnC0TT45Ak m1YzA5OV82gr0pVpApyqAmL78CwSnmOtnP7RbpQJHWwitcp7gj9Y2LJ53eI6aRdwaCPK XzqPzHtzgX1RkpFGiw/GgcKQB9y5ZB58Au2ogqor1EmX4xdc5l8jYEe7sqRSk5O46rB4 PxUf6cyFf6SqDY9qXlec0zNCIEAhxACwBWlhHbb4OwGjN2/8v07nSLUxk9Pr7YWoLTjA jExQ==
X-Gm-Message-State AG10YOQAY6NtAevxYLQtan4jcRyE9GMFlfD9jAcIgPtwm3YO2TpTRFezLLPch1g+0qYt5mbcZQvf5xWz6aL62g==
X-Received by 10.107.10.147 with SMTP id 19mr16444307iok.46.1455548794638; Mon, 15 Feb 2016 07:06:34 -0800 (PST)
In-Reply-To <f0f27bca-9462-4f16-9b1d-a1a16dd0f8f2@googlegroups.com>
X-Content-Filtered-By Mailman/MimeDel 2.1.21rc2
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21rc2
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>
Xref csiph.com comp.lang.python:102966

Show key headers only | View raw


On Mon, Feb 15, 2016 at 9:56 AM, Geoff Munn <geoff.munn@gmail.com> wrote:

> On Sunday, 14 February 2016 13:39:52 UTC, Geoff Munn  wrote:
> > Hi,
> >
> > Noob at the Python thing so here goes,
> >
> > I have copied a program to demonstrate control structures in Python but
> get a syntax error at line 31, isint = False. I'm using Python 2.7.6 and
> Linux Mint based around ubuntu14.04.1. I have pasted all the code below,
> >
> >
> >
> > #!/usr/bin/env python2
> >
> > '''
> > We are going to write a program that will ask for the user to input an
> arbitary
> > number of integers, store them in a collection, and then demonstrate how
> > the collection would be used with various control structures
> > '''
> >
> > import sys  # Used for the sys.exit function
> >
> > target_int=raw_input("How many integers?")
> >
> > '''
> > By now the variable target_int contains a string representation of
> > whatever the user typed. We nee to try and convert that to an integer but
> > be ready to deal with the error if it's not. Otherwise the program will
> crash
> > '''
> >
> > try:
> >     target_int=int(target_int)
> > except ValueError:
> >     sys.exit("You must enter an integer")
> >
> > ints=list()  # list to store the integers
> >
> > count = 0  # Track how many integers have been inputted
> >
> > # Keep asking for a number until we have reached the required number
> > while count < target_int:
> >     new_int=raw_input("Please enter integer {0}:".format(count +1)
> >     isint = False
> >     try:
> >         new_int=int(new_int)  # If the above succeeds then isint will
> >         #be set to true: isint = True
> >
> >     except:
> >         print("You must enter an integer")
> >
> >     '''
> >     Only carry on if we have an integer. If not we will loop again.
> >     The == below is a comparision operator, a single = is an asignment
> operator
> >     '''
> >     if isnit==True:
> >         ints.append(new_int)  # Adds the integer to the collection
> >         count += 1  # Count is incremented by 1
> > # The for loop
> >     print ("Using a for loop")
> >     for values in ints:
> >         print (str(value))
> > # The while loop
> >     print ("Using a while loop")
> >     total=len(ints)  # We already have the total from above but using
> len we can determine from the ints list.
> >     count = 0
> >     while count < total:
> >         print (str(ints[count]))
> >         count += 1
>
> Thanks Peter and Chris, yes missed the parentheses by taking the error as
> being in line 31, DOH but a lesson learned. I have checked and checked the
> code I entered against the provided code and had to make some more changes
> to at least go through the first while loop but have given up on the rest
> of it. Given your comments do you think its worth persevering with this
> book or is there a better 'entry' into Python programming?
> --
> https://mail.python.org/mailman/listinfo/python-list
>


Learn Python the Hard Way is pretty good some people say.  Its online.
Also Diving into Python is online written by the now offline Mark Pilgrim.
-- 
Joel Goldstick
http://joelgoldstick.com/stats/birthdays

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


Thread

Syntax error (The Python Book) Linux User and Developer Bookazine Geoff Munn <geoff.munn@gmail.com> - 2016-02-14 05:39 -0800
  Re: Syntax error (The Python Book) Linux User and Developer Bookazine Peter Otten <__peter__@web.de> - 2016-02-14 14:53 +0100
  Re: Syntax error (The Python Book) Linux User and Developer Bookazine Chris Angelico <rosuav@gmail.com> - 2016-02-15 04:38 +1100
  Re: Syntax error (The Python Book) Linux User and Developer Bookazine Geoff Munn <geoff.munn@gmail.com> - 2016-02-15 06:56 -0800
    Re: Syntax error (The Python Book) Linux User and Developer Bookazine Joel Goldstick <joel.goldstick@gmail.com> - 2016-02-15 10:06 -0500
      Re: Syntax error (The Python Book) Linux User and Developer Bookazine Geoff Munn <geoff.munn@gmail.com> - 2016-02-15 07:33 -0800
      Re: Syntax error (The Python Book) Linux User and Developer Bookazine Larry Hudson <orgnut@yahoo.com> - 2016-02-15 13:17 -0800

csiph-web