Skip to content
Advertisement

Assert statement s.islower

I have written the assert statements like this,

def pigify(w):
    """
    Returns: copy of w converted to Pig Latin.
    
    Write only the asserts and NOTHING ELSE
    
    Precondition: w is a nonempty string with only lowercase letters
    """
    assert type(w) == str, 'needs a word'
    assert s.islower(w) == upper(w) 'Violates precondtion'

I only need to write the asserts statements (as it states in the docstring), and I am assuming the last assert is wrong. I am trying to write that if the word is capitalized, then it violates the precondtion (in the assert statement). Thank you so much.

Advertisement

Answer

According to the documentation, islower() on its own does exactly what you need, and returns a boolean, so it can be used with assert directly:

assert w.islower()
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement