Skip to content

Commit f5da35d

Browse files
committed
modify functoin
1 parent e20ebcc commit f5da35d

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

Python_practice1.ipynb

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
{
3232
"output_type": "stream",
3333
"name": "stdout",
34-
"text": "The variables before swapping are: 20 35\nThe variables after swapping are: 35 20\n"
34+
"text": "The variables before swapping are: 23 45\nThe variables after swapping are: 45 23\n"
3535
}
3636
],
3737
"source": [
@@ -48,32 +48,32 @@
4848
"#\n",
4949
"# @Brief: 交换变量值\n",
5050
"#\n",
51-
"# @Parameter: var_one, var_two\n",
51+
"# @Parameter: x, y\n",
5252
"#\n",
53-
"# @Return: var_two, var_one\n",
53+
"# @Return: y, x\n",
54+
"def swap(x, y):\n",
55+
" return y, x\n",
5456
"\n",
5557
"\n",
56-
"def swap(var_one, var_two):\n",
57-
" return var_two, var_one\n",
58+
"var_one = input(\"Please input the first variable:\")\n",
59+
"var_two = input(\"Please input the second variable:\")\n",
60+
"print(\"The variables before swapping are:\", var_one, var_two)\n",
5861
"\n",
59-
"\n",
60-
"variable_one = input(\"Please input the first variable:\")\n",
61-
"variable_two = input(\"Please input the second variable:\")\n",
62-
"print(\"The variables before swapping are:\", variable_one, variable_two)\n",
63-
"variable_one, variable_two = swap(variable_one, variable_two)\n",
64-
"# variable_one, variable_two = variable_two, variable_one\n",
65-
"print(\"The variables after swapping are:\", variable_one, variable_two)\n"
62+
"var_one, var_two = swap(var_one, var_two)\n",
63+
"# var_one, var_two = var_two, var_one\n",
64+
"print(\"The variables after swapping are:\", var_one, var_two)\n",
65+
""
6666
]
6767
},
6868
{
6969
"cell_type": "code",
70-
"execution_count": 9,
70+
"execution_count": 2,
7171
"metadata": {},
7272
"outputs": [
7373
{
7474
"output_type": "stream",
7575
"name": "stdout",
76-
"text": "23 converts to Fahrenheit is 73.4\n"
76+
"text": "50 converts to Fahrenheit is 122.0\n"
7777
}
7878
],
7979
"source": [
@@ -84,14 +84,12 @@
8484
"# @Parameter: 摄氏度\n",
8585
"#\n",
8686
"# @Return: 华氏度\n",
87-
"\n",
88-
"\n",
89-
"def cel_to_fah(cel):\n",
87+
"def cel2fah(cel):\n",
9088
" return cel * 1.8 + 32\n",
9189
"\n",
9290
"\n",
9391
"celsius = eval(input(\"Please input celsius:\"))\n",
94-
"fahrenheit = cel_to_fah(celsius)\n",
92+
"fahrenheit = cel2fah(celsius)\n",
9593
"print(celsius, \"converts to Fahrenheit is\", fahrenheit)\n",
9694
""
9795
]
@@ -115,8 +113,6 @@
115113
"# @Parameter: 正整数\n",
116114
"#\n",
117115
"# @Return: 各位数之和\n",
118-
"\n",
119-
"\n",
120116
"def digit_sum(num):\n",
121117
" if num >= 10:\n",
122118
" remainder = num % 10\n",
@@ -149,8 +145,7 @@
149145
"num_left, num_right = num_split(number_str)\n",
150146
"sum = digit_sum(num_left)\n",
151147
"sum += digit_sum(num_right)\n",
152-
"print(\"%s: The sum of the individual digits is %d\" % (number_str, sum))\n",
153-
""
148+
"print(\"%s: The sum of the individual digits is %d\" % (number_str, sum))\n"
154149
]
155150
},
156151
{

0 commit comments

Comments
 (0)