beginner question (True False help)

S

Steven D'Aprano

What does global mean?

Hi eschneider92,

A few bits of advice:

- You may like to actually sign your emails with a real name, or at least
an alias that you want to be called, otherwise we'll just call you by
your email address, and apart from sounding silly, many people don't like
that.

- You might also find that the tutor mailing list is a better match for
your status as a complete beginner to Python. You can subscribe to it
here:

http://mail.python.org/mailman/listinfo/tutor


- If you do, please take my advice and use individual emails, not daily
digests. It is MUCH easier to carry on a back-and-forth conversation with
individual emails.

- Please try to quote enough of the message you are replying to to
establish context, but without filling the email with page after page of
irrelevant history. (Notice the line at the top of this message, starting
with ">"? That's what you previously wrote.) If you need help configuring
your email program to quote the previous message, just ask.
 
D

Dennis Lee Bieber

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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,880
Messages
2,569,944
Members
46,246
Latest member
RosalieMar

Latest Threads

Top