Python riddle

  • Thread starter SPE - Stani's Python Editor
  • Start date
S

SPE - Stani's Python Editor

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?'
 
?

=?ISO-8859-1?Q?Daniel_Sch=FCle?=

SPE said:
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 :)
 
K

kyle.tk

SPE said:
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?'
 
D

Dan Bishop

kyle.tk said:
last time i checked this should print 'why?'
I have no idea how you got it to print 'Why?'
.... def __init__(self, fileobj):
.... self._file = fileobj
.... def write(self, text):
.... self._file.write(text.capitalize())
....Why?
 
S

Steven D'Aprano

... def __init__(self, fileobj):
... self._file = fileobj
... def write(self, text):
... self._file.write(text.capitalize())
...
Why?


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

But mostly evil.


*grin*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top