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


Groups > comp.lang.python > #53740

Re: Newbie question related to Boolean in Python

From Neil Cerutti <neilc@norwich.edu>
Newsgroups comp.lang.python
Subject Re: Newbie question related to Boolean in Python
Date 2013-09-05 20:38 +0000
Organization Norwich University
Message-ID <b8s8e6F1ll0U1@mid.individual.net> (permalink)
References <f2259124-4af1-4608-9969-8e42a140633e@googlegroups.com>

Show all headers | View raw


On 2013-09-05, skwyang93@gmail.com <skwyang93@gmail.com> wrote:
> 1.      bear_moved = False
> 2.     
> 3.      while True:
> 4.        next = raw_input("> ")
> 5.    
> 6.        if next == "take honey":
> 7.            dead("The bear looks at you then slaps your face off.")
> 8.        elif next == "taunt bear" and not bear_moved:
> 9.            print "The bear has moved from the door. You can go through."
> 10.	    
> 11.            bear_moved = True
> 12.	 elif next == "taunt bear" and bear_moved:
> 13.	     dead("The bear gets pissed off and chews your leg off.")
> 14.	 elif next == "open door" and bear_moved:
> 15.	    gold_room()
> 16.	 else:
> 17.	     print "I got no idea what that means.
>
> # This is just to show my understanding of Boolean. In line 8-9, if my input is "taunt bear", the result is true and true, which will continue the loop.
>
> # So what confused me is line 12-13. if my input is taunt bear, is it suppose to be taunt bear == "taunt bear" and bear_moved which is true and true? which means the loop will continue instead of cancelling it.
>
> Thanks in advance for spending your time to answer my question. 

Your logic looks OK, but the indentation on your code is screwy.
It should not compile like that. There may be indentation errors,
but I don't want to make assumptions when the indentation is
definitely not what your real code says. Can you cut and paste
your code directly instead of retyping it?


-- 
Neil Cerutti

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Newbie question related to Boolean in Python skwyang93@gmail.com - 2013-09-05 13:08 -0700
  Re: Newbie question related to Boolean in Python Neil Cerutti <neilc@norwich.edu> - 2013-09-05 20:38 +0000
    Re: Newbie question related to Boolean in Python Thomas Yang <skwyang93@gmail.com> - 2013-09-05 16:36 -0700
      Re: Newbie question related to Boolean in Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-06 02:28 +0000
  Re: Newbie question related to Boolean in Python Dave Angel <davea@davea.name> - 2013-09-05 20:47 +0000
  Re: Newbie question related to Boolean in Python Tim Roberts <timr@probo.com> - 2013-09-05 21:02 -0700

csiph-web