# is_friend (Unit 2, 18)

 1 Hello: I responded to the subject quiz using the following: def is_friend(name): initial=name[0] return initial=='d' However, when I submit, it keeps giving me an error message stating that it didn't work on the string "Dave". However, it does work on "Dave" and numerous other strings (names) that I tested. I would appreciate if someone could tell me what is wrong with the above. I saw the answer in the video that follows the quiz, and I understand that there are other (better) ways to do it, but what is wrong with this way? Thanks Hassan asked 29 Feb '12, 03:36 hassan210977 16●1●3 accept rate: 0% dreyescat 6.9k●16●34●82

 2 I think you are comparing 'd' against 'D'. They are not the same. answered 29 Feb '12, 03:40 dreyescat 6.9k●16●34●82
 1 You are checking if the first letter is a 'd' instead of a Capital 'D'... I guess that is your problem... you see the programm is case sensitive so right now it is checking if 'D' is the same as 'd' converting to values: 'D' == 'd'  and they have different values, try to look for a ASCII Table which has the values of the characters for a computer and you'll see that they are in fact different. What you could do as alternative is something like: if ( initial=='d' or initial == 'D'): return True else: return False  answered 29 Feb '12, 03:42 Flavio Diez 232●10
 1 Python is case sensative. If you wanted to (as I did) you could take both upper and lower case into account in your solution answered 29 Feb '12, 03:44 Rob Barnes-3 ♦ 19.1k●10●68●205
 0 Thanks everyone. It just hit me, and that was it. Thanks again. answered 29 Feb '12, 03:53 hassan210977 16●1●3
 0 I got the same problem, but for me it was because I gave True and False as a string, not as a boolean. answered 29 Feb '12, 04:08 yup..same here (01 Mar '12, 12:16) Arushi Pant-1
 0 There is another problem with using name[0]. If then name provided is am empty string, the program will get an error. It would be much better to use name[:1] instead, which should successfully work even for empty strings. answered 01 Mar '12, 11:43 Vadim Dribinsky 178●7 Thanks for the tip :-) (01 Mar '12, 19:10) hassan210977
Question text:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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

×15,321
×20
×8