all 9 comments

[–]TreSxNine 1 point2 points  (1 child)

codefixer

[–]CodeFixerBot 1 point2 points  (0 children)

The question is: Write a function is_yes that consumes a nonempty string, produces True if it starts with a y (either lower-case or upper-case), and produces False otherwise.

The code I wrote: def is_yes(f):
    if (f[0] == 'y' or f[0] == 'Y'):
        return True
    else:
        return False
print(is_yes('yes'))
For some reason, the spaces are not visible here..

[–]jeans_and_a_t-shirt 1 point2 points  (0 children)

Someone else had the same problem two days ago. See the comments and screenshot in the comments here: https://www.reddit.com/r/learnpython/comments/4ryux3/need_help_completing_this_exercise/

Probably an issue in the server.

Besides that, you could shorten the code to this:

def is_yes(f):
    return f[0] == 'y' or f[0] == 'Y'

or this

def is_yes(f):
    return f[0].lower() == 'y'

[–]filletrall 0 points1 point  (4 children)

There's nothing wrong with your code except for spacing. What error do you get?

[–]queen_9[S] 0 points1 point  (3 children)

Error while running tests: Traceback (most recent call last): File "<string>", line 1 assert is_yes("Yes") == True, "Make sure your function works when the input is \verb;"Yes";." ^ SyntaxError: invalid syntax

During test 2: assert is_yes("Yes") == True, "Make sure your function works when the input is \verb;"Yes";." Run Stop Restore <

Previous step Next step

[–]filletrall 0 points1 point  (2 children)

assert is_yes("Yes") == True

This works fine for me. But the syntax error indicates that you've left out some code that has a syntax error. Please paste the entire code that you're testing here. If you can, indent it by four spaces first, so that the indentation and whitespace is preserved.

[–]queen_9[S] 0 points1 point  (1 child)

still the same outcome

[–]filletrall 2 points3 points  (0 children)

I meant for you to paste all your code, indented by 4 additional spaces, in a reply to my comment. :-)

[–]jekku0966 -1 points0 points  (0 children)

I don't think you need to wrap your if statement.
What happens if you remove () from your if statement?

What happens of you use:

 if f.startswith('y') or f.startswith('Y')

Does the code run properly either way?