0

レッスン中ですが、行き詰まっています。私はPythonを初めて使用するので、どこが間違っているのかを理解するのは困難です。

#Write your two "if" statements below!

def true_function():
    if                #Fill in your `if` statement here!
        return        #Make sure this function returns `True`

def false_function():
    if                #Fill in your `if` statement here!
        return        #Make sure this function returns `False`

これは私の提案した解決策であり、エラーが発生します。

#Write your two "if" statements below!

    def true_function():
        if  2 + 2 == 4:           #Fill in your `if` statement here!
            return 'True'   #Make sure this function returns `True`

    def false_function():
        if  2 + 2 == 5:           #Fill in your `if` statement here!
            return 'False' #Make sure this function returns `False`

誰かが私がどこで間違っているのかを理解するのを手伝ってもらえますか?

4

1 に答える 1

5

TrueFalseはオブジェクト (または変数、定数、ソフトキーワード、またはそれらを呼びたいもの) です。それらは文字列ではありません。

return True

2 番目の関数も false 条件を使用しているため、ifブロックの内容は決して実行されません。端から落ちて、None代わりに戻ってきます。

于 2013-02-26T23:17:41.760 に答える