始める無料で始める

複数のパラメータをもつ関数

前のレクチャーで、Hugo は関数定義における複数パラメータの使い方を説明しました。ここでは学んだことを使って、shout() 関数をさらに改良します。shout() が 2 つの引数を受け取るように変更しましょう。以前に作成した shout() 関数の一部を以下に示します。

この演習はコースの一部です

Pythonの関数入門

コースを見る

演習の手順

  • 関数ヘッダーを変更し、word1word2 の順で 2 つのパラメータを受け取るようにしてください。
  • word1word2 それぞれに '!!!' を連結し、順に shout1shout2 に代入します。
  • shout1shout2 をこの順番で連結し、new_shout に代入します。
  • 文字列 'congratulations''you' をこの順番で shout() に渡し、返り値を yell に代入してください。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# Define shout with parameters word1 and word2
def shout(____, ____):
    """Concatenate strings with three exclamation marks"""
    # Concatenate word1 with '!!!': shout1
    
    
    # Concatenate word2 with '!!!': shout2
    
    
    # Concatenate shout1 with shout2: new_shout
    

    # Return new_shout
    return new_shout

# Pass 'congratulations' and 'you' to shout(): yell


# Print yell
print(yell)
コードを編集して実行