473,387 Members | 2,436 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,387 software developers and data experts.

Python riddle

I know that this code is nonsense, but why does this print 'Why?'

a = 1
if a >2:
try:
5/0
except:
raise
else:
print 'why?'

Dec 6 '05 #1
6 2044
1 is not greater then 2 last time i checked :)

Dec 6 '05 #2
Forget it, it's not 1st of april yet.

Dec 6 '05 #3
SPE - Stani's Python Editor wrote:
I know that this code is nonsense, but why does this print 'Why?'

a = 1
if a >2:
try:
5/0
except:
raise
else:
print 'why?'


because 1 is not greater than 2 I suppose :)

Dec 6 '05 #4

SPE - Stani's Python Editor wrote:
I know that this code is nonsense, but why does this print 'Why?'

a = 1
if a >2:
try:
5/0
except:
raise
else:
print 'why?'


last time i checked this should print 'why?'
I have no idea how you got it to print 'Why?'

Dec 6 '05 #5
kyle.tk wrote:
SPE - Stani's Python Editor wrote:
I know that this code is nonsense, but why does this print 'Why?'

a = 1
if a >2:
try:
5/0
except:
raise
else:
print 'why?'


last time i checked this should print 'why?'
I have no idea how you got it to print 'Why?'

class CapOutput: .... def __init__(self, fileobj):
.... self._file = fileobj
.... def write(self, text):
.... self._file.write(text.capitalize())
.... sys.stdout = CapOutput(sys.stdout)
print 'why?'

Why?

Dec 6 '05 #6
On Mon, 05 Dec 2005 22:58:42 -0800, Dan Bishop wrote:
class CapOutput: ... def __init__(self, fileobj):
... self._file = fileobj
... def write(self, text):
... self._file.write(text.capitalize())
... sys.stdout = CapOutput(sys.stdout)
print 'why?'

Why?

That's ... brilliant. Brilliant and evil.

But mostly evil.
*grin*
--
Steven.

Dec 7 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Juha Haataja | last post by:
I have been learning Python since April, and would like a few comments from the experts on list processing. I managed to implement a Python code for solving the so-called Einstein's Riddle, see...
63
by: pythonchallenge | last post by:
For the riddles' lovers among you, you are most invited to take part in the Python Challenge, the first python programming riddle on the net. You are invited to take part in it at:...
0
by: pythonchallenge | last post by:
For the riddles' lovers among you, you are most invited to take part in the Python Challenge, the first python programming riddle on the net. You are invited to take part in it at:...
1
by: Sara Khalatbari | last post by:
Hey guys! Thanks for helping me find time&date. Have you seen this? This is the first programming riddle on the net with 20 levels! http://www.pythonchallenge.com/ ...
3
by: Michael | last post by:
Hi, I'm a pretty sound programmer in C++, but would like to learn python! Does anyone know of any tutorial s aimed at me?? My biggest confusion so far is the lack of pointers in Python .........
1
by: mmf | last post by:
Hallo! I tried to use Python from C like it is described in the Python Docmentation. So I wrote the following C source file: #include <Python.h> int main(int argc, char *argv) {...
0
by: Diez B. Roggisch | last post by:
QOTW: "If I wanted to write five lines instead of one everywhere in a Python program, I'd use Java." -- Paul Rubin http://groups.google.com/group/comp.lang.python/msg/6fac4f3022acd1fa?hl=de& "i...
1
by: ImortalSorrow | last post by:
Please I need urgent help with this program! Everything is working well except a part where i want to repeat the riddle if the answer isnt correct. here's the code..hope someone can help me! ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.