|
31 | 31 | {
|
32 | 32 | "output_type": "stream",
|
33 | 33 | "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" |
35 | 35 | }
|
36 | 36 | ],
|
37 | 37 | "source": [
|
|
48 | 48 | "#\n",
|
49 | 49 | "# @Brief: 交换变量值\n",
|
50 | 50 | "#\n",
|
51 |
| - "# @Parameter: var_one, var_two\n", |
| 51 | + "# @Parameter: x, y\n", |
52 | 52 | "#\n",
|
53 |
| - "# @Return: var_two, var_one\n", |
| 53 | + "# @Return: y, x\n", |
| 54 | + "def swap(x, y):\n", |
| 55 | + " return y, x\n", |
54 | 56 | "\n",
|
55 | 57 | "\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", |
58 | 61 | "\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 | + "" |
66 | 66 | ]
|
67 | 67 | },
|
68 | 68 | {
|
69 | 69 | "cell_type": "code",
|
70 |
| - "execution_count": 9, |
| 70 | + "execution_count": 2, |
71 | 71 | "metadata": {},
|
72 | 72 | "outputs": [
|
73 | 73 | {
|
74 | 74 | "output_type": "stream",
|
75 | 75 | "name": "stdout",
|
76 |
| - "text": "23 converts to Fahrenheit is 73.4\n" |
| 76 | + "text": "50 converts to Fahrenheit is 122.0\n" |
77 | 77 | }
|
78 | 78 | ],
|
79 | 79 | "source": [
|
|
84 | 84 | "# @Parameter: 摄氏度\n",
|
85 | 85 | "#\n",
|
86 | 86 | "# @Return: 华氏度\n",
|
87 |
| - "\n", |
88 |
| - "\n", |
89 |
| - "def cel_to_fah(cel):\n", |
| 87 | + "def cel2fah(cel):\n", |
90 | 88 | " return cel * 1.8 + 32\n",
|
91 | 89 | "\n",
|
92 | 90 | "\n",
|
93 | 91 | "celsius = eval(input(\"Please input celsius:\"))\n",
|
94 |
| - "fahrenheit = cel_to_fah(celsius)\n", |
| 92 | + "fahrenheit = cel2fah(celsius)\n", |
95 | 93 | "print(celsius, \"converts to Fahrenheit is\", fahrenheit)\n",
|
96 | 94 | ""
|
97 | 95 | ]
|
|
115 | 113 | "# @Parameter: 正整数\n",
|
116 | 114 | "#\n",
|
117 | 115 | "# @Return: 各位数之和\n",
|
118 |
| - "\n", |
119 |
| - "\n", |
120 | 116 | "def digit_sum(num):\n",
|
121 | 117 | " if num >= 10:\n",
|
122 | 118 | " remainder = num % 10\n",
|
|
149 | 145 | "num_left, num_right = num_split(number_str)\n",
|
150 | 146 | "sum = digit_sum(num_left)\n",
|
151 | 147 | "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" |
154 | 149 | ]
|
155 | 150 | },
|
156 | 151 | {
|
|
0 commit comments