A simple question on operator

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jul 2005
Posts: 35
Reputation: k_en is an unknown quantity at this point 
Solved Threads: 0
k_en k_en is offline Offline
Light Poster

A simple question on operator

 
0
  #1
Dec 27th, 2005
I can do a control loop like this in C++

  1. int case =0;
  2. while( case<0 && case>20){}

How am i suppose to implement this in Python? I didn't get any errors if i wrote this, the problem is it doesn't enter the while loop when case<0 and case>5
  1. while case<0 & case>5:
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 133
Reputation: mawe is an unknown quantity at this point 
Solved Threads: 58
mawe mawe is offline Offline
Junior Poster

Re: A simple question on operator

 
0
  #2
Dec 27th, 2005
Hi!

So you want to do something if case is smaller than 0 or greater than 20, right?
  1. while case<0 or case>20: do something
If case should be between 0 and 20:
  1. while 0<case<20: do something
Hope this helps.

Regards, mawe
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 35
Reputation: k_en is an unknown quantity at this point 
Solved Threads: 0
k_en k_en is offline Offline
Light Poster

Re: A simple question on operator

 
0
  #3
Dec 27th, 2005
If case <=2 or case >=5, it will enter the while loop. the code below doesn't solve my problem. why can't it enter the while loop when my case match this condition case <=2 or case >=5


  1. while case<0 or case>20: do something
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 138
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

Re: A simple question on operator

 
0
  #4
Dec 27th, 2005
Something like this works fine:
  1. try:
  2. case = int(raw_input("enter a number less then 3 or more than 4: "))
  3. except:
  4. case = 0
  5. while case <=2 or case >=5:
  6. # do something to get out of loop
  7. case += 1
  8. print case
  9. if case > 10: break
Notice that case is reserved keyword in C++, also notice that && is and || is or in Python. A simple & is bitwise and in C++ and Python.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC