Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb507488

Browse files
committed
Add change_function_name exercise
1 parentf65a924 commitb507488

File tree

2 files changed

+73
-4
lines changed

2 files changed

+73
-4
lines changed

‎backend/main/chapters/c08_functions.py‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# flake8: NOQA E501
2-
fromtypingimportList
32

4-
frommain.exercisesimportgenerate_string
5-
frommain.textimportExerciseStep,MessageStep,Page,VerbatimStep
3+
frommain.textimportExerciseStep,Page,VerbatimStep
64
frommain.utilsimportreturns_stdout
75

86

@@ -51,7 +49,7 @@ def greet(name):
5149
greet("Alice")
5250
greet("Bob")
5351

54-
classprint_twice_exercise(ExerciseStep):
52+
classchange_function_name(VerbatimStep):
5553
"""
5654
Note how the output of the program changed. `How are you?` is printed twice. You can think of the whole program as being
5755
equivalent to this:
@@ -77,6 +75,22 @@ class print_twice_exercise(ExerciseStep):
7775
one parameter called `name`.
7876
5. A colon `:`
7977
78+
Let's do some simple exercises. Change the name of the function from `greet` to `say_hello`.
79+
Make sure the whole program stays working as before, but don't change anything else.
80+
"""
81+
82+
program_in_text=False
83+
84+
defprogram(self):
85+
defsay_hello(name):
86+
print("Hello "+name+"!")
87+
print("How are you?")
88+
89+
say_hello("Alice")
90+
say_hello("Bob")
91+
92+
classprint_twice_exercise(ExerciseStep):
93+
""""
8094
Here's an exercise: write a function called `print_twice` which accepts one argument `x` and prints that argument twice.
8195
8296
For example, `print_twice("Hello")` should output:

‎backend/main/test_transcript.json‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15027,6 +15027,61 @@
1502715027
},
1502815028
"step":"how_are_you"
1502915029
},
15030+
{
15031+
"page":"Defining Functions",
15032+
"program": [
15033+
"def say_hello(name):",
15034+
" print(\"Hello\" + name +\"!\")",
15035+
" print(\"How are you?\")",
15036+
"",
15037+
"say_hello(\"Alice\")",
15038+
"say_hello(\"Bob\")"
15039+
],
15040+
"response": {
15041+
"birdseye_url":null,
15042+
"message":"",
15043+
"passed":true,
15044+
"result": [
15045+
{
15046+
"color":"white",
15047+
"text":"Hello Alice!"
15048+
},
15049+
{
15050+
"color":"white",
15051+
"text":"\n"
15052+
},
15053+
{
15054+
"color":"white",
15055+
"text":"How are you?"
15056+
},
15057+
{
15058+
"color":"white",
15059+
"text":"\n"
15060+
},
15061+
{
15062+
"color":"white",
15063+
"text":"Hello Bob!"
15064+
},
15065+
{
15066+
"color":"white",
15067+
"text":"\n"
15068+
},
15069+
{
15070+
"color":"white",
15071+
"text":"How are you?"
15072+
},
15073+
{
15074+
"color":"white",
15075+
"text":"\n"
15076+
},
15077+
{
15078+
"color":"white",
15079+
"text":">>>"
15080+
}
15081+
]
15082+
},
15083+
"step":"change_function_name"
15084+
},
1503015085
{
1503115086
"page":"Defining Functions",
1503215087
"program": [

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp