473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

I don't understand why this isn't working, help?

So, I'm learning how to program in Python, and so far I think I'm doing okay. While trying a SWAT type of game, I made this.
Expand|Select|Wrap|Line Numbers
  1. def chooseEntryway():
  2.     room = ''
  3.     print('Which entryway will you take? The window, the back door, or the front door?')
  4.     room = input()
  5.     room = str(room)
  6.     if room != 'window' or 'the back door' or 'the front door' or 'the window' or 'front door' or 'back door':
  7.         print('That is not an available entryway. You need to enter from the window, the front door, or the back door.')
  8.     while room == '':
  9.         chooseEntryway()
This apparently doesn't work, even when Room DOES equal one of those, it still thinks it's false and prints the last line. Anyone know what's wrong?
Mar 4 '12 #1
1 1382
dwblas
626 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. if room != 'window' or 'the back door' or 'the front door' or 'the window' or 'front door' or 'back door':
You have 2 problems. If room contains "the back door" it will not equal 'window', so there will always be 5 strings that do not match it. Second, the if statement breaks down into (truncated for brevity)
Expand|Select|Wrap|Line Numbers
  1. room="window"
  2.  
  3. if room != 'window':
  4.     print "room not equal window"
  5. # or 'the back door'
  6. elif 'the back door':  ## always true
  7.     print "the back door"
  8. elif 'the front door':  ## always true
  9.     print "the front door" 
Generally you search a list, or not in a list, when you have multiple items. See this page on Searching Lists using the "in" operator.
Mar 4 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: J. W. McCall | last post by:
Sorry again if this is OT; I'm not sure if this is a python problem or just a CGI problem, but I couldn't find a decent CGI NG. Let me know if there's somewhere else I should be posting. I got...
1
by: Merrua | last post by:
I dont understand how to do this I created a dialog based project and that is fine for most of my programming project, but one dialog box is going to generate a graph, and as far as i know from...
10
by: dhnriverside | last post by:
Hi guys Still having a problem with this dropdownlist. Basically, I've got 4. The first 2 work fine, then my code crashes on the 3rd. ddlEndTimeHour.Items.FindByValue(endTime).Selected =...
3
by: Sheau Wei | last post by:
This is the code the code that i try to run it as my search engine for my database. But i dont understand why i run a notice that undefind index. Can u help me ? <form method="post"...
5
by: ryann18 | last post by:
I was just wondering, my teacher assigned a project for me and told me to "create one cat in SandBox and put all the methods (for example method_1) you need for the excercises in KittyKitty and call...
2
by: wudoug119 | last post by:
This is my code and it will take any number that I input and say it is a prime number. Please help me... int Prime(int prime) //declares isPrime as a function using integers { ...
19
by: so many sites so little time | last post by:
the table is head the colunm is called body <?php //show_site.php // This script retrieves blog entries from the database. // Address error handing. ini_set ('display_errors', 1);...
5
by: soheir | last post by:
am doing my first project so plz help i've created a submit button <input type="submit" onclick="valid()"> my function valid checks if the fields are not empty if empty a window prmpt appears...
3
by: canabatz | last post by:
Hello all!! i got a small problem ,not big :) i got this example of a link in my site that display everything correctly! http://www.mysite.com/product.php?id=200 now my problem is : if...
1
by: dougancil | last post by:
I have the following code: Imports System.IO Imports System.Data Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.