Return-Path: 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 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 Content-Type: text/plain; charset=UTF-8 Cc: python-list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On 7 August 2013 09:17, 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?