[prev in list] [next in list] [prev in thread] [next in thread]
List: python-list
Subject: Re: Program Error Help - Python 3.1
From: Cameron Simpson <cs () zip ! com ! au>
Date: 2017-03-31 23:42:48
Message-ID: 20170331234248.GA59845 () cskk ! homeip ! net
[Download RAW message or body]
On 31Mar2017 16:12, 2019.cavanaughc@fpsedu.org <2019.cavanaughc@fpsedu.org> wrote:
> Hello I've been coding for about 1 or 2 months and i have encountered a problem \
> with a 'while' statement. It keeps looping even when the statement is false, here \
> is the code. The code is for a game that I'm making that resembles the Oregon \
> Trial.
Obviously the statement (well, "test") isn't false! Let's look:
[...]
> answer8 = ""
> while answer8 != ("1") or answer8 != ("2"):
[...]
Answer8 cannot be both "1" and also "2". Therefore, it will always _not_ be
equal to at least one of "1" and "2". Therefore this test is always true.
You might better write this:
while answer8 not in ("1", "2"):
or:
while not( answer8 == "1" or answer8 == "2" ):
BTW, you need to decide whther you're working in strings or integers. input()
in Python 3 returns a string. If you want to test against strings, fine.
However, if you want to test against numbers you need to convert the string to
a number:
answer8n = int(answer8)
and then test against answer8n.
Cheers,
Cameron Simpson <cs@zip.com.au>
--
https://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic