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


Groups > comp.lang.python > #59276

Re: Some python newb help please?

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: Some python newb help please?
Date 2013-11-12 20:49 -0500
Organization IISS Elusive Unicorn
References <f9bcd68d-ac00-421a-ade5-5f5690861d25@googlegroups.com> <mailman.2490.1384294935.18130.python-list@python.org> <22894a10-1ffd-4671-94f4-962dfb56e4fd@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.2521.1384307390.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, 12 Nov 2013 14:27:37 -0800 (PST), lrwarren94@gmail.com declaimed
the following:


>
>I'm not quite sure what you mean by that. it was on that pastebin link. I'll post it again here though. it's no longer than half a page. 

	The preference here is that if you ask a question about code, you
provide the code IN the message -- you don't send us off to some site that
may or may not retain the code down the road (whereas the question posted
here may be archived forever)

>
>x = 0
>y = 0
>quitCommand = 0
>
>print "Welcome to the World of Textcraft!"
>print "----------------------------------"
>print ""
>
>while quitCommand != int(5):

	5 IS an int, so why coerce it to itself.

>    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:
>            print "Moving north"
>            y = y + 1
>    elif int(raw_input()) == 2:
>            print "Moving east"
>            x = x + 1
>    elif int(raw_input()) == 3:
>            print "Moving south"
>            y = y - 1
>    elif int(raw_input()) == 4:
>            print "Moving west"
>            x = x - 1
>    elif int(raw_input()) == 5:
>            print "Dost thou leave so soon? Fare thee well!"
>            quitCommand = 5
>    else:
>            print "I find your lack of reading comprehension skills disturbing."
>

	Note that you ask for NEW input from the user on each if/elif. You want
to read ONE value from the user, and then compare THAT value on each
if/elif line.

	HINT: raw_input() can display a prompt string... so

	command = int(raw_input(
		"Enter a command "
		"(1 = North, 2 = East, 3 = South, 4 = West, 5 = Exit): "))

{Note: I took advantage of Python's ability to concatenate adjacent strings
-- that way the line doesn't wrap at odd locations in UseNet}
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

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