여러 매개변수를 받는 함수
지난 강의에서 Hugo가 함수 정의에서 여러 매개변수를 사용하는 방법을 설명했어요. 이제 배운 내용을 활용해 shout() 함수를 더 수정해 보겠습니다. 여기서는 shout()가 두 개의 인수를 받을 수 있도록 바꿔볼 거예요. 앞서 작성했던 함수 shout()의 일부가 제공됩니다.
이 연습은 강의의 일부입니다
Python 함수 입문
연습 안내
- 함수 헤더를 수정하여 순서대로 두 매개변수
word1,word2를 받도록 하세요. - 각각
word1과word2에'!!!'를 이어붙여shout1과shout2에 할당하세요. shout1과shout2를 그 순서대로 이어붙여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)