What did I do? quiz 2.18

I dont see what i did wrong...

def is_friend(name):
if name[0] == 'D':
return true
else:
return false

print is_friend('Diane')
print is_friend('Fred')

asked 06 Mar '12, 03:59

Jimmy%20Martin's gravatar image

Jimmy Martin
1515
accept rate: 0%


9 Answers:

True not true. It is case sensitive

link

answered 06 Mar '12, 04:02

Danil%20Trokhimik's gravatar image

Danil Trokhimik
482718

edited 06 Mar '12, 04:03

Indentation is very very important in Python. Please check that see if that helps. Also try your code works with this:

http://pythonwebconsole.thomnichols.org/

link

answered 06 Mar '12, 04:13

Narra%20Bharath's gravatar image

Narra Bharath
494616

edited 06 Mar '12, 04:14

Check your formatting (indents, etc)

I cleaned it up for you. Try this:

def is_friend(name):
    if name[0] == 'D':
        return True
    else:
        return False

print is_friend('Diane')
link

answered 06 Mar '12, 04:14

Rob%20Barnes-3's gravatar image

Rob Barnes-3 ♦
19.1k1068205

true should be True (T is capital) and false should be False
Also, do not write the print statements when you are submitting

link

answered 06 Mar '12, 04:03

Prabha%20Ramanathan's gravatar image

Prabha Raman...
424517

Still doesn't like it...

def is_friend(name):
    if name[0] == 'D':
        return True
        else:
        return False

print is_friend('Diane')
print is_friend('Fred')
link

answered 06 Mar '12, 04:04

Jimmy%20Martin's gravatar image

Jimmy Martin
1515

edited 06 Mar '12, 04:26

fnenu-1's gravatar image

fnenu-1 ♦♦
18.5k1981231

says syntax on "else:" line

link

answered 06 Mar '12, 04:07

Jimmy%20Martin's gravatar image

Jimmy Martin
1515

1

Check indentation

(06 Mar '12, 04:09) Danil Trokhimik Danil%20Trokhimik's gravatar image

Try this
def is_friend(name): return name[0] == 'D'

link

answered 06 Mar '12, 04:08

Danil%20Trokhimik's gravatar image

Danil Trokhimik
482718

This may be more helpful..

def is_friend(name):

 if name[0] == 'D':

 return True

 else:

return False

print is_friend('Diane')
link

answered 06 Mar '12, 04:10

Jimmy%20Martin's gravatar image

Jimmy Martin
1515

edited 06 Mar '12, 04:14

Rob%20Barnes-3's gravatar image

Rob Barnes-3 ♦
19.1k1068205

1

When you post code, you want to make sure it's formatted properly so we can read it.
Please review this post if you need to know how to format your code for the forums.

(06 Mar '12, 04:12) Rob Barnes-3 ♦ Rob%20Barnes-3's gravatar image

must have been my indenting. When I copied Velak, it worked fine. Thanks for the speedy help.

link

answered 06 Mar '12, 04:24

Jimmy%20Martin's gravatar image

Jimmy Martin
1515

1

Your indentation of the else: was wrong.

(06 Mar '12, 04:26) fnenu-1 ♦♦ fnenu-1's gravatar image

and the if statement as well.

(06 Mar '12, 04:31) Rob Barnes-3 ♦ Rob%20Barnes-3's gravatar image

Any guesses why my indents are off? Isn't the tabbing automatic?

(06 Mar '12, 04:36) Jimmy Martin Jimmy%20Martin's gravatar image
1

The tabbing lines up with the block above (except when you've put a : in which case when you hit enter, it indents more) so when you want to finish that block, you have to de-indent it yourself.

(06 Mar '12, 04:40) fnenu-1 ♦♦ fnenu-1's gravatar image
Your answer
Question text:

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×15,230
×319
×20

Asked: 06 Mar '12, 03:59

Seen: 360 times

Last updated: 06 Mar '12, 04:40