Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52121
| Return-Path | <joshua.landau.ws@gmail.com> |
|---|---|
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.071 |
| X-Spam-Evidence | '*H*': 0.88; '*S*': 0.02; 'else:': 0.03; 'subject:help': 0.08; 'subject:question': 0.10; 'cc:addr:python- list': 0.11; 'def': 0.12; '"new': 0.16; "'yes',": 0.16; 'subject:beginner': 0.16; 'values:': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'trying': 0.19; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'equivalent': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'anyone': 0.31; 'option': 0.32; "i'd": 0.34; 'could': 0.34; 'problem': 0.35; 'subject: (': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'false': 0.36; 'explain': 0.39; 'does': 0.39; 'unable': 0.39; 'how': 0.40; 'tell': 0.60; 'august': 0.61; 'simply': 0.61; 'obvious': 0.74; 'repeat': 0.74; 'working,': 0.84; 'subject:True': 0.91; 'to:addr:comcast.net': 0.91; 'imagine': 0.93; 'hundred': 0.95; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=A68U33KFFTWWU73OiGnXXygyYwg1Y6XYo3cTx4X0Z7A=; b=vpF14Z0/h74PMu/RzNHWZXaHyrdHjKtgeFxPK6T86hspSWKq9jmkLvTbSxmCfCMP25 tSFv6hgrVQMEDAxqGbewqn2D72T0Mv7daJ0DBS5gQ6Ph4iq5e/ZoKytk0fuFlKbA0XdC 5x2L6x+rpTBe86QZ6g0gjQFDz2ecDA/w3qdS6gofLzCb8SkGV6FdkoSviuPTYfA5Puvo Wn8GAGLUTLt/ONYJuNXDrSKdlReGiLRhY3+PkFkHhTZZQdUSNUtOtJ2FKZyU/kCjEnK+ g6Ugv/0id10K43Ijqu6CYK20Df2aXUYrClbVJKcmJfw6n4nj8oViMvcDPk2qA4AOKVgC HOJw== |
| X-Received | by 10.152.26.72 with SMTP id j8mr977062lag.19.1375865003454; Wed, 07 Aug 2013 01:43:23 -0700 (PDT) |
| MIME-Version | 1.0 |
| Sender | joshua.landau.ws@gmail.com |
| In-Reply-To | <6c6dedec-5e47-4229-bc67-01b058cdb410@googlegroups.com> |
| References | <6c6dedec-5e47-4229-bc67-01b058cdb410@googlegroups.com> |
| From | Joshua Landau <joshua@landau.ws> |
| Date | Wed, 7 Aug 2013 09:42:43 +0100 |
| X-Google-Sender-Auth | XC3_AwfTm8yRRW3nk5jN0i8-heE |
| Subject | Re: beginner question (True False help) |
| To | kurt schwitters <eschneider92@comcast.net> |
| Content-Type | text/plain; charset=UTF-8 |
| Cc | python-list <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.306.1375865009.1251.python-list@python.org> (permalink) |
| Lines | 61 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1375865009 news.xs4all.nl 15992 [2001:888:2000:d::a6]:49224 |
| X-Complaints-To | abuse@xs4all.nl |
| Path | csiph.com!usenet.pasdenom.info!news.franciliens.net!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
| Xref | csiph.com comp.lang.python:52121 |
Show key headers only | View raw
On 7 August 2013 09:17, <eschneider92@comcast.net> wrote:
> I'm trying to create an option for the program to repeat if the user types 'y' or 'yes', using true and false values, or otherwise end the program. If anyone could explain to me how to get this code working, I'd appreciate it.
Always tell people what in particular you don't understand (*ducks*)
because it wasn't obvious what part of the problem you were unable to
fulfil.
> letters='abcdefghijklmn'
> batman=True
> def thingy():
> print('type letter from a to n')
> typedletter=input()
> if typedletter in letters:
> print('yes')
> else:
> print('no')
> def repeat():
> print('go again?')
> goagain=input()
> if goagain in ('y', 'yes'):
> print('ok')
> else:
> print('goodbye')
> batman=False
This doesn't do what you want it to.
x = "old thing"
def change_x():
x = "new thing"
change_x()
print(x) # Not changed!
The solution is to put "global x" at the start of the function.
> while batman==True:
> thingy()
> repeat()
> print('this is the end')
Note that this isn't actually a good way to do it. Imagine you had
several hundred function -- would you really want to have an
equivalent number of names floating around that you have to look
after?
The solution is to make the functions simply return values:
x = "old thing"
def return_thing():
x = "new thing"
return "new thing" # You can do this in one line
x = return_thing() # Get the value from the function and change x with it
Does this make sense?
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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