Night 12: Tricks with a twist
이미 Python 또는 의사 코드로 이날의 학습을 마쳤습니다. 두 언어 모두에서 완료한 것으로 인정됩니다. 원하면 다시 연습하세요.
이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Tonight: tricks with a twist
- Last night your pet learned tricks. But a trick did the same thing every time.
- Tonight you give a trick some information, so it can change.
- You will learn one thing: parameters.
Words for tonight
| Word | Meaning |
|---|---|
| parameter | a name in the brackets of def; it gets a value |
| argument | the value you give in the call |
| pass | give a value to a function |
English
A function with a parameter
- Write a name in the brackets of
def. This is the parameter. - When you call the function, give a value. This is the argument.
def hello(name):
print("Hello,", name)
hello("Kit")
hello("Ana")
- First call:
nameis"Kit". Second call:nameis"Ana".

English
More than one parameter
- Use a comma between parameters. The values go in in order.
def feed(food, amount):
print("Kit eats", amount, food)
feed("apples", 3)
feed("fish", 1)
| Call | food |
amount |
|---|---|---|
feed("apples", 3) |
"apples" |
3 |
feed("fish", 1) |
"fish" |
1 |
English
Text times a number
- A small new tool for tonight:
"*" * 3gives"***".
def star_row(n):
print("*" * n)
star_row(2)
star_row(5)
English
Names in the task
- The checker calls your function with its own values, like
hello("Bo"). - So the function must work for any value, not only the one in your code.
- Now give your pet's tricks a twist!
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Define hello(name). It prints Hello, and the name. hello("Kit") prints Hello, Kit. Call it for Kit and for Ana.
출력을 보려면 '실행'을 클릭하세요.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Define jump(times). It prints Jump! times times, one per line. Call jump(3).
출력을 보려면 '실행'을 클릭하세요.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Define feed(food, amount) with 두 개 parameters. feed("apples", 3) prints Kit eats 3 apples.
출력을 보려면 '실행'을 클릭하세요.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
Define star_row(n). It prints one line of n stars, like *** for star_row(3). Then use a loop to call it for 1, 2, 3 and 4. You get a triangle.
출력을 보려면 '실행'을 클릭하세요.