Else Problems


#1

I honestly believe some of these exorcises should evaluate the actual "is the code correct".
See in code below, I had to add "#return False" just so it would accept my answer.
Even if this is supposed to be enforcing if/else, why not just tell them please use if/else for the answer, currently it treats the answer as totally wrong. Same as ternary, it still treats it as completely wrong unless I add #return False.


answer = "'Tis but a scratch!"

#sol1
def black_knight():
    return answer == "'Tis but a scratch!"
    #return False

def french_soldier():
    return answer == "Go away, or I shall taunt you a second time!"
    #return False

#sol2
def black_knight():
    return True if answer == "'Tis but a scratch!" else False
    #return False
    
def french_soldier():
    return True if answer == "Go away, or I shall taunt you a second time!" else False
    #return False


#2

@randonuser
From
https://docs.python.org/2/reference/
the link in [compound statements]
https://docs.python.org/2/reference/compound_stmts.html#the-if-statement
( take notice of the colon-: and the required indentation )


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.