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


Groups > comp.lang.python > #59246

Re: Some python newb help please?

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'elif': 0.05; 'class,': 0.07; 'subject:help': 0.08; 'lawrence': 0.09; 'west,': 0.09; '")"': 0.16; '"enter': 0.16; 'east,': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'simple.': 0.16; 'subject:python': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'trying': 0.19; 'command': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; '"you': 0.24; 'guys': 0.24; 'skip:" 30': 0.26; 'asking': 0.27; 'header:In-Reply-To:1': 0.27; 'wondering': 0.29; 'leave': 0.29; '(this': 0.29; 'subject:please': 0.30; "i'm": 0.30; 'int,': 0.31; 'figure': 0.32; 'checking': 0.33; 'could': 0.34; 'problem': 0.35; "can't": 0.35; 'something': 0.35; 'received:84': 0.35; 'but': 0.35; 'words,': 0.36; 'subject:?': 0.36; 'similar': 0.36; 'to:addr:python-list': 0.38; '12,': 0.39; 'to:addr:python.org': 0.39; 'above,': 0.60; "you're": 0.61; 'email addr:gmail.com': 0.63; 'world': 0.66; 'header:Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'lack': 0.78; 'fare': 0.84; 'remarks': 0.84; 'reply-to:addr:python.org': 0.84; 'north,': 0.91; '2013': 0.98
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=IvYnLtPg c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=2LCq-pQfA8cA:10 a=i_12VyLbQSEA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=sjDOIi9c8Y4A:10 a=pGLkceISAAAA:8 a=ETq87aqrMRdIN1SKmFcA:9 a=wPNLvfGTeEIA:10 a=MSl-tDqOz04A:10
X-AUTH mrabarnett:2500
Date Tue, 12 Nov 2013 22:56:35 +0000
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Some python newb help please?
References <f9bcd68d-ac00-421a-ade5-5f5690861d25@googlegroups.com> <mailman.2490.1384294935.18130.python-list@python.org> <22894a10-1ffd-4671-94f4-962dfb56e4fd@googlegroups.com>
In-Reply-To <22894a10-1ffd-4671-94f4-962dfb56e4fd@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To python-list@python.org
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.2495.1384296995.18130.python-list@python.org> (permalink)
Lines 86
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1384296995 news.xs4all.nl 15919 [2001:888:2000:d::a6]:45300
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:59246

Show key headers only | View raw


On 12/11/2013 22:27, lrwarren94@gmail.com wrote:> On Tuesday, November 
12, 2013 4:21:58 PM UTC-6, Mark Lawrence wrote:
 >> On 12/11/2013 22:14, lr....@gmail.com wrote:
 >>
 >> > So I'm trying to write a program for a problem in class, and 
something strange is happening that I can't figure out why is happening. 
I was wondering if you guys could help me fix it?
 >> >
[snip]
 >
 > x = 0
 > y = 0
 > quitCommand = 0
 >
 > print "Welcome to the World of Textcraft!"
 > print "----------------------------------"
 > print ""

You can simplify that to:

     print

 >
 > while quitCommand != int(5):

5 is already an int, so int(5) == 5.

 >      print "You are currently at (" + str(x) + ", " + str(y) + ")"
 >      print "Enter a command (1 = North, 2 = East, 3 = South, 4 = 
West, 5 = Exit):"
 >      if int(raw_input()) == 1:

You're asking the user to enter something and then checking whether its 
int value is 1.

 >              print "Moving north"
 >              y = y + 1
 >      elif int(raw_input()) == 2:

Now you're asking the user to enter something _again_ and then checking 
whether its int value is 2.

In other words, in order for it to print "Moving east" the following 
steps must occur:

1. Ask the user to enter something.

2. Check whether it's 1. It isn't. (Previous condition)

3. Ask the user to enter something.

4. Check whether it's 2. (This condition)

 >              print "Moving east"
 >              x = x + 1
 >      elif int(raw_input()) == 3:

Similar remarks to above, but longer.

 >              print "Moving south"
 >              y = y - 1
 >      elif int(raw_input()) == 4:

Similar remarks to above, but longer again.

 >              print "Moving west"
 >              x = x - 1
 >      elif int(raw_input()) == 5:

Similar remarks to above, but longer again.

 >              print "Dost thou leave so soon? Fare thee well!"
 >              quitCommand = 5
 >      else:
 >              print "I find your lack of reading comprehension skills 
disturbing."
 >

The fix is simple. Ask once:

      answer = int(raw_input())
      if answer == 1:
          ...
      elif answer == 2:
          ...
      ...

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


Thread

Some python newb help please? lrwarren94@gmail.com - 2013-11-12 14:14 -0800
  Re: Some python newb help please? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-12 22:21 +0000
    Re: Some python newb help please? lrwarren94@gmail.com - 2013-11-12 14:27 -0800
      Re: Some python newb help please? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-12 22:54 +0000
      Re: Some python newb help please? MRAB <python@mrabarnett.plus.com> - 2013-11-12 22:56 +0000
        Re: Some python newb help please? lrwarren94@gmail.com - 2013-11-12 15:04 -0800
          Re: Some python newb help please? Chris Angelico <rosuav@gmail.com> - 2013-11-13 10:19 +1100
      Re: Some python newb help please? Tim Chase <python.list@tim.thechases.com> - 2013-11-12 16:59 -0600
      Re: Some python newb help please? Chris Angelico <rosuav@gmail.com> - 2013-11-13 09:58 +1100
      Re: Some python newb help please? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-11-12 20:49 -0500
  Re: Some python newb help please? John Strick <jstrickler@gmail.com> - 2013-11-12 14:49 -0800
  Re: Some python newb help please? Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-12 23:05 +0000

csiph-web