Skip to content

Commit 1bc1b32

Browse files
authored
Add files via upload
1 parent 512f72c commit 1bc1b32

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4145
-0
lines changed
+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "4db5a065-6414-42d2-981d-2a4f5da0e9ba",
6+
"metadata": {},
7+
"source": [
8+
"Chapter 08\n",
9+
"# 无输入、无输出函数\n",
10+
"Book_1《编程不难》 | 鸢尾花书:从加减乘除到机器学习 "
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"id": "7d462c48-871d-462d-8555-47fd28fbbb3e",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"def say_hello():\n",
21+
" # 自定义函数:打印问候\n",
22+
" # 输入:无\n",
23+
" # 输出:无\n",
24+
" print(\"Hello!\")"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": null,
30+
"id": "6bf2dbb3-c37a-4cfe-bf25-4d9c17ddc682",
31+
"metadata": {},
32+
"outputs": [
33+
{
34+
"name": "stdout",
35+
"output_type": "stream",
36+
"text": [
37+
"Hello!\n"
38+
]
39+
}
40+
],
41+
"source": [
42+
"# 调用自定义函数\n",
43+
"say_hello()"
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": null,
49+
"id": "07b3009a-237c-4679-9d33-b02110f7b9e3",
50+
"metadata": {},
51+
"outputs": [],
52+
"source": []
53+
}
54+
],
55+
"metadata": {
56+
"kernelspec": {
57+
"display_name": "Python 3 (ipykernel)",
58+
"language": "python",
59+
"name": "python3"
60+
},
61+
"language_info": {
62+
"codemirror_mode": {
63+
"name": "ipython",
64+
"version": 3
65+
},
66+
"file_extension": ".py",
67+
"mimetype": "text/x-python",
68+
"name": "python",
69+
"nbconvert_exporter": "python",
70+
"pygments_lexer": "ipython3",
71+
"version": "3.10.9"
72+
}
73+
},
74+
"nbformat": 4,
75+
"nbformat_minor": 5
76+
}

Book1_Ch08_Python_Codes/Bk1_Ch08_02.ipynb

+142
Large diffs are not rendered by default.
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "88be5776-4573-4ed6-9dd5-28960cab3b26",
6+
"metadata": {},
7+
"source": [
8+
"Chapter 08\n",
9+
"# 两个输入、一个输出函数\n",
10+
"Book_1《编程不难》 | 鸢尾花书:从加减乘除到机器学习 "
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 1,
16+
"id": "4fc5a11b-6b88-45ce-87c4-cfb195e646de",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"# 自定义函数\n",
21+
"def add_numbers(a, b):\n",
22+
" result = a + b\n",
23+
" return result"
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": 2,
29+
"id": "095a34bb-2bc7-46d0-b24b-ecf1ccae2bf0",
30+
"metadata": {},
31+
"outputs": [
32+
{
33+
"name": "stdout",
34+
"output_type": "stream",
35+
"text": [
36+
"8\n"
37+
]
38+
}
39+
],
40+
"source": [
41+
"sum = add_numbers(3, 5) # 调用函数\n",
42+
"print(sum) # 输出8"
43+
]
44+
}
45+
],
46+
"metadata": {
47+
"kernelspec": {
48+
"display_name": "Python 3 (ipykernel)",
49+
"language": "python",
50+
"name": "python3"
51+
},
52+
"language_info": {
53+
"codemirror_mode": {
54+
"name": "ipython",
55+
"version": 3
56+
},
57+
"file_extension": ".py",
58+
"mimetype": "text/x-python",
59+
"name": "python",
60+
"nbconvert_exporter": "python",
61+
"pygments_lexer": "ipython3",
62+
"version": "3.10.9"
63+
}
64+
},
65+
"nbformat": 4,
66+
"nbformat_minor": 5
67+
}
+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "b1c0457f-855e-4044-bf90-97e7d2b38a9f",
6+
"metadata": {},
7+
"source": [
8+
"Chapter 08\n",
9+
"# 两个输入、多个输出函数\n",
10+
"Book_1《编程不难》 | 鸢尾花书:从加减乘除到机器学习 "
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 1,
16+
"id": "a3238c05-8ff5-400b-843e-8d00690bcca4",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"# 自定义函数\n",
21+
"def arithmetic_operations(a, b):\n",
22+
" add = a + b\n",
23+
" sub = a - b\n",
24+
" mul = a * b\n",
25+
" div = a / b\n",
26+
" return add, sub, mul, div"
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": 2,
32+
"id": "5ae2c0c2-5852-40c9-89a8-d5ee59c9212c",
33+
"metadata": {},
34+
"outputs": [],
35+
"source": [
36+
"# 调用函数并输出结果\n",
37+
"a, b = 10, 5\n",
38+
"result = arithmetic_operations(a, b)"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": 3,
44+
"id": "d5773ff3-b4cd-47e8-b884-2bff521ab360",
45+
"metadata": {},
46+
"outputs": [
47+
{
48+
"name": "stdout",
49+
"output_type": "stream",
50+
"text": [
51+
"Addition: 15\n",
52+
"Subtraction: 5\n",
53+
"Multiplication: 50\n",
54+
"Division: 2.0\n"
55+
]
56+
}
57+
],
58+
"source": [
59+
"print(\"Addition: \", result[0])\n",
60+
"print(\"Subtraction: \", result[1])\n",
61+
"print(\"Multiplication: \", result[2])\n",
62+
"print(\"Division: \", result[3])"
63+
]
64+
}
65+
],
66+
"metadata": {
67+
"kernelspec": {
68+
"display_name": "Python 3 (ipykernel)",
69+
"language": "python",
70+
"name": "python3"
71+
},
72+
"language_info": {
73+
"codemirror_mode": {
74+
"name": "ipython",
75+
"version": 3
76+
},
77+
"file_extension": ".py",
78+
"mimetype": "text/x-python",
79+
"name": "python",
80+
"nbconvert_exporter": "python",
81+
"pygments_lexer": "ipython3",
82+
"version": "3.10.9"
83+
}
84+
},
85+
"nbformat": 4,
86+
"nbformat_minor": 5
87+
}
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "d44f2d28-3ad7-4537-a462-6f504744e055",
6+
"metadata": {},
7+
"source": [
8+
"Chapter 08\n",
9+
"# 函数输入有默认值\n",
10+
"Book_1《编程不难》 | 鸢尾花书:从加减乘除到机器学习 "
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 1,
16+
"id": "77087f0f-17b1-42a6-bc94-87744ac01c07",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"# 自定义函数\n",
21+
"def greet(name, greeting='Hello'):\n",
22+
" print(f\"{greeting}, {name}!\")"
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": 2,
28+
"id": "60b98759-f679-4b11-977c-842c136d3cfb",
29+
"metadata": {},
30+
"outputs": [
31+
{
32+
"name": "stdout",
33+
"output_type": "stream",
34+
"text": [
35+
"Hello, James!\n"
36+
]
37+
}
38+
],
39+
"source": [
40+
"# 使用默认的问候语调用函数\n",
41+
"greet('James') # 输出 \"Hello, James!\""
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": 3,
47+
"id": "131321ba-23d6-412d-9383-d421286e9f7f",
48+
"metadata": {},
49+
"outputs": [
50+
{
51+
"name": "stdout",
52+
"output_type": "stream",
53+
"text": [
54+
"Good morning, James!\n"
55+
]
56+
}
57+
],
58+
"source": [
59+
"# 指定自定义的问候语调用函数\n",
60+
"greet('James', 'Good morning') \n",
61+
"# 输出 \"Good morning, James!\""
62+
]
63+
}
64+
],
65+
"metadata": {
66+
"kernelspec": {
67+
"display_name": "Python 3 (ipykernel)",
68+
"language": "python",
69+
"name": "python3"
70+
},
71+
"language_info": {
72+
"codemirror_mode": {
73+
"name": "ipython",
74+
"version": 3
75+
},
76+
"file_extension": ".py",
77+
"mimetype": "text/x-python",
78+
"name": "python",
79+
"nbconvert_exporter": "python",
80+
"pygments_lexer": "ipython3",
81+
"version": "3.10.9"
82+
}
83+
},
84+
"nbformat": 4,
85+
"nbformat_minor": 5
86+
}

0 commit comments

Comments
 (0)