| | |
A simple question on operator
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jul 2005
Posts: 35
Reputation:
Solved Threads: 0
I can do a control loop like this in C++
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
Python Syntax (Toggle Plain Text)
int case =0; 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
Python Syntax (Toggle Plain Text)
while case<0 & case>5:
•
•
Join Date: Sep 2005
Posts: 133
Reputation:
Solved Threads: 58
Hi!
So you want to do something if case is smaller than 0 or greater than 20, right?
If case should be between 0 and 20:
Hope this helps.
Regards, mawe
So you want to do something if case is smaller than 0 or greater than 20, right?
Python Syntax (Toggle Plain Text)
while case<0 or case>20: do something
Python Syntax (Toggle Plain Text)
while 0<case<20: do something
Regards, mawe
•
•
Join Date: Jul 2005
Posts: 35
Reputation:
Solved Threads: 0
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
Python Syntax (Toggle Plain Text)
while case<0 or case>20: do something
Something like this works fine:
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.
Python Syntax (Toggle Plain Text)
try: case = int(raw_input("enter a number less then 3 or more than 4: ")) except: case = 0 while case <=2 or case >=5: # do something to get out of loop case += 1 print case if case > 10: break
![]() |
Similar Threads
- Help with vector.. simple question (C++)
- Simple array question (C++)
- This has to be a simple question to answer. (Visual Basic 4 / 5 / 6)
- Simple Class Question (C++)
- Simple question (Windows Servers and IIS)
- XP Pro (re)activation question (Windows NT / 2000 / XP)
Other Threads in the Python Forum
- Previous Thread: New to python
- Next Thread: Modifying a project in python
| Thread Tools | Search this Thread |
Tag cloud for Python
address aliased anydbm app bash beginner bits changecolor cipher class clear code conversion coordinates corners cturtle curves definedlines development dictionary dynamic events examples excel feet file float format ftp function gui handling homework images import info input java keycontrol line linux list lists loan loop matching mouse number numbers output parsing path permissions port prime programming projects py2exe pygame pymailer pyqt python random rational raw_input recursion recursive scrolledtext searchingfile shebang singleton split string strings table tails terminal text thread threading time tkinter tlapse tooltip tuple tutorial type ubuntu unicode url urllib urllib2 valueerror variable whileloop windows word wx.wizard wxpython xlwt






