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


Groups > comp.lang.python > #52157

Re: beginner question (True False help)

From Dave Angel <davea@davea.name>
Subject Re: beginner question (True False help)
Date 2013-08-08 01:18 +0000
References <6c6dedec-5e47-4229-bc67-01b058cdb410@googlegroups.com> <7c627d74-a5c5-4356-9a04-9608de0006ba@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.332.1375924751.1251.python-list@python.org> (permalink)

Show all headers | View raw


eschneider92@comcast.net wrote:

> What I wanted to happen is when the user typed something other than 'y' or 'yes' after being asked 'go again?', the batman==False line would cause the program to stop asking anything and say 'this is the end'. Instead, what is happening is that the program just keeps going. I figured that after defining the function (thingy(), repeat()), that the while statement would repeat until the 'go again' user input was something other than 'y' or 'yes', and the batman==False part of the repeat() function would cause the 'while batman==True' part to become False and end. You probably answered my question and I'm too dumb to see it, but that's a slight elaboration on my problem.

When you assign a variable inside a function, it has no effect on a
global variable with similar name.  In order to make it change the
global, you'd have needed the global declaration.

Try this:

var = 42
def  myfunc():
     var = 90


print "before:", var
myfunc()
print "after:", var

Now, change the function, by adding a declaration:

def myfunc():
    global var
    var = 90

and the result will change.


-- 
DaveA

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