In theory, the following code should ask for the user to enter a value for h
until he/she enters hello or goodbye.
h = "hi"
while h != "hello" or "goodbye":
h = raw_input("Valu e for h:")
But the program keeps asking for a value no matter what I enter. Why doesn't
it work? 4 1204
EAS wrote: In theory, the following code should ask for the user to enter a value for h until he/she enters hello or goodbye.
h = "hi" while h != "hello" or "goodbye": h = raw_input("Valu e for h:")
But the program keeps asking for a value no matter what I enter. Why doesn't it work?
You meant
while h != "hello" and h != "goodbye": ...
--
__ Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
\__/ She glanced at her watch ... It was 9:23.
-- James Clavell
In article <40************ ***@alcyone.com >,
Erik Max Francis <ma*@alcyone.co m> wrote: EAS wrote:
In theory, the following code should ask for the user to enter a value for h until he/she enters hello or goodbye.
h = "hi" while h != "hello" or "goodbye": h = raw_input("Valu e for h:")
But the program keeps asking for a value no matter what I enter. Why doesn't it work?
You meant
while h != "hello" and h != "goodbye": ...
Or, perhaps even better,
while h not in ("hello", "goodbye"):
The meaning is the same, but I think idiomatically, it's a closer match
to the way you would say it in natural language.
"EAS" <er****@attbi.n ospam.com> wrote in message
news:dHcrc.8649 1$536.14466932@ attbi_s03... In theory, the following code should ask for the user to enter a value for
h until he/she enters hello or goodbye.
h = "hi" while h != "hello" or "goodbye": h = raw_input("Valu e for h:")
But the program keeps asking for a value no matter what I enter. Why
doesn't it work?
Operator precedence and a misunderstandin g about how "or" works.
Operator precedence means that the expression is equivalent to:
(h != "hello") or "goodbye"
The result of h != "hello" is either True or False.
The way "or" works, if the result was false, the
second operand would be substituted, so you
would get "goodbye" which is true. In other words,
the result of the entire expression is either True
or "goodbye", which is also true. So the loop never terminates.
The "proper" way to write this test is:
while h not in ("hello", "goodbye"):
There are other ways, but this is probably the most readable.
John Roth
h != "hello" or "goodbye"
is
(h != "hello") or "goodbye"
It's always true because even if (h != "hello") evaluates to False,
then "goodbye" is 'tested' and considered to be true.
You probably meant:
h != "hello" and h != "goodbye"
that can be written even better as:
h not in ("hello", "goodbye")
Georgy
"EAS" <er****@attbi.n ospam.com> wrote in message news:dHcrc.8649 1$536.14466932@ attbi_s03...
| In theory, the following code should ask for the user to enter a value for h
| until he/she enters hello or goodbye.
|
| h = "hi"
| while h != "hello" or "goodbye":
| h = raw_input("Valu e for h:")
|
| But the program keeps asking for a value no matter what I enter. Why doesn't
| it work? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jfj |
last post by:
Hi.
Suppose this:
########################
def foo (x):
print x
f = classmethod (foo)
|
by: Ohaya |
last post by:
Hi,
I'm trying to understand a situation where ASP seems to be "blocking" of
"queuing" requests. This is on a Win2K Advanced Server, with IIS5.
I've seen some posts (e.g.,
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=Tidy7IDbDHA.2108%40cpmsftngxa06.phx.gbl)
that indicate that ASP will queue up requests when they come...
|
by: sathyashrayan |
last post by:
Please look at the following code:
static char *text = {"th", "st", "nd", "rd"};
char *ordinal_text(int number)
{
if (((number %= 100) > 9 && number < 20) || (number %= 10) > 3)
number = 0;
return text;
|
by: m_a_t_t |
last post by:
Ok, I'm reading "The C Programming Language: 2nd Edition" and I'm on
chapter 1.5.1 and here's the program you're sposed to make:
#include <stdio.h>
/* copy input to output; 1st version */
main()
{
int c;
|
by: rahul8143 |
last post by:
hello,
I am really confused over following for code snippets. No problem
that they are working codes but how? how they are evaluated by
compiler? It will be my pleasure if you explain me all following
snippets.
1) {
int i=3;
for (i--; i<7; i=7)
printf("%d",i++);
| |
by: Dodger |
last post by:
Okay, background... yes, I am another of those evil, spurned, damnable
Perl mongers, but I'm not trying to start a flamewar, I'm juust tryung
to understand something...
I can write a script in Perl like so, and it's pretty to me (and the
using of the heredocs I think does defend perl against many arguments
withthe HTML being all escaped and...
|
by: vcinquini |
last post by:
I've always learned about typedef as a statement that creates an alias
for a type. For example:
typedef long DWORD;
but I'm confused about the following typedef. Which is the type and
which is the alias?
class MyClass
|
by: rEvolution27 |
last post by:
I'm a c++ newbie here, trying out some stuff and when I try to compile
this:
void create() {
char name;
cout << "Creating a new timetable /n Please type a name for this
timetable";
cin >name;
ofstream editFile;
editFile.open (name, ios::out | ios::app);
|
by: kya2 |
last post by:
I am not able to create following store procedure.
CREATE PROCEDURE DBSAMBA.InsertDeleteBatch(OUT norows INT )
RESULT SETS 1
LANGUAGE SQL
BEGIN part1
DECLARE TOTAL_LEFT INT DEFAULT 0;
SELECT COUNT(*)INTO TOTAL_LEFT FROM DBSAMBA.REPORTEDTRANSACTION_S;
WHILE (TOTAL_LEFT > 0)
DO
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |