Conditionals & Control Flow, #13 curious question


#1



https://www.codecademy.com/en/courses/python-beginner-BxUFN/3/3?curriculum_id=4f89dab3d788890003000096#


I got it right... but for some reason, when I run the code the website let me pass to the next task by only writing False on line 13. When it told me under hints that I should be writing it on lines 8 and 14. Yet I still got it right by just writing on line 13. Like I mentioned earlier. Any thoughts why?


Should it not be wrong?


answer = "'Tis but a scratch!"

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


#2

Since the answer variable is equal to the black_knight()'s answer:

answer = "'Tis but a scratch!"
def black_knight():
    if answer == "'Tis but a scratch!": #returns True, so doesn't go into the else

The code will never reach the else statement, and therefore, codecademy won't check to see if it is correct. (Just like if you take out the True in the french soldier's if statement, codecademy will let you continue.

if answer == "Go away, or I shall taunt you a second time!":
        return

)


#3

what do you mean by "it will never reach the else statement" ?


#4

the if statement returns true, and so the code doesn't look at the else. It only checks if the if statement if false, and the else is required.


#5

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