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


Groups > comp.lang.python > #52293

Re: beginner question (True False help)

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: beginner question (True False help)
Date 2013-08-09 22:58 -0400
Organization IISS Elusive Unicorn
References <6c6dedec-5e47-4229-bc67-01b058cdb410@googlegroups.com> <b9e1881e-dd26-497f-83d0-8884d08ec8ff@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.416.1376103528.1251.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, 9 Aug 2013 15:27:50 -0700 (PDT), eschneider92@comcast.net declaimed
the following:

>This is what I ended up with btw. Does this insult anyone's more well attuned Python sensibilities?
>
>letters='abcdefghijkl'
>def repeat():
>    print('wanna go again?')
>    batman=input()
>    if batman in ('y','yes'):
>        main()
>    else:
>        return
>def main():
>    print('guess a letter')
>    batman=input()
>    if batman in letters:
>        print('ok that letter was in letters')
>        repeat()
>    else:
>        print('asdasdasd')
>        repeat()
>main()
>print('how ya doin')

	You have recursion: repeat calls main and main calls repeat...
Eventually you may fill the call stack. (I'm presuming Python 3.x -- I
still run 2.x as some of the libraries I most rely upon have not yet been
ported).

	Also the structure

	else:
		return
	<end of procedure>

is equivalent to just

	<end of procedure>


	Let's see... (Untested)
-=-=-=-=-=-
letters='abcdefghijkl'
def main():
	while True:
		ltr = raw_input("Guess a Letter> ")
		if ltr.lower() in letters:
			print "OK, that letter was in 'letters'"
		else:
			print "asda is a UK grocery chain"
		ans = raw_input("Want to try again? ")
		if not ans.lower().startswith("y"): break

if __name__ == "__main__":
	print "How ya doin'"
	main()
-- 
	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

beginner question (True False help) eschneider92@comcast.net - 2013-08-07 01:17 -0700
  Re: beginner question (True False help) Joshua Landau <joshua@landau.ws> - 2013-08-07 09:42 +0100
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-07 13:59 -0700
    Re: beginner question (True False help) Dave Angel <davea@davea.name> - 2013-08-08 01:18 +0000
  Re: beginner question (True False help) Larry Hudson <orgnut@yahoo.com> - 2013-08-07 19:49 -0700
  Re: beginner question (True False help) wxjmfauth@gmail.com - 2013-08-07 23:20 -0700
    Re: beginner question (True False help) Chris Angelico <rosuav@gmail.com> - 2013-08-08 12:41 +0100
    Re: beginner question (True False help) Terry Reedy <tjreedy@udel.edu> - 2013-08-08 16:29 -0400
      Re: beginner question (True False help) wxjmfauth@gmail.com - 2013-08-09 01:05 -0700
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 15:27 -0700
    Re: beginner question (True False help) Joshua Landau <joshua@landau.ws> - 2013-08-10 00:05 +0100
    Re: beginner question (True False help) Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-08-09 22:58 -0400
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 15:28 -0700
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:14 -0700
    Re: beginner question (True False help) Joshua Landau <joshua@landau.ws> - 2013-08-10 00:30 +0100
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:24 -0700
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:34 -0700
    Re: beginner question (True False help) Joshua Landau <joshua@landau.ws> - 2013-08-10 02:22 +0100
    Re: beginner question (True False help) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-10 01:40 +0000
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:40 -0700
    Re: beginner question (True False help) MRAB <python@mrabarnett.plus.com> - 2013-08-10 01:39 +0100
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:43 -0700
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 18:08 -0700

csiph-web