[Tutor] why does this not work

Mark Lawrence breamoreboy at yahoo.co.uk
Tue Apr 23 22:00:31 CEST 2013


On 23/04/2013 20:39, Roelof Wobben wrote:
> Im trying to learn python by a course at codeacademy.
>
> Now I have this code :
>
> def shut_down(s):
>      s = s.lower()
>      if s == "yes":
>          return "Shutting down..."
>      elif s == "no" :
>          return "Shutdown aborted!"
>      else:
>          return "Sorry, I didn't understand you"
>
> But when I run it  I see this message:
>
> It looks like output other than yes/no does not return "Sorry, I didn't
> understand you."
>
> So can anyone explain to me what I did wrong.
>
> Roelof

PEBKAC or PEBCAK? :)

c:\Users\Mark\MyPython>type b.py
def shut_down(s):
     s = s.lower()
     if s == "yes":
         return "Shutting down..."
     elif s == "no" :
         return "Shutdown aborted!"
     else:
         return "Sorry, I didn't understand you"

for s in 'what', 'the', 'heck?', 'YES', 'NO', 'works', 'okay', 'for', 'me':
     print(s, shut_down(s))

c:\Users\Mark\MyPython>b.py
what Sorry, I didn't understand you
the Sorry, I didn't understand you
heck? Sorry, I didn't understand you
YES Shutting down...
NO Shutdown aborted!
works Sorry, I didn't understand you
okay Sorry, I didn't understand you
for Sorry, I didn't understand you
me Sorry, I didn't understand you


-- 
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.

Mark Lawrence



More information about the Tutor mailing list