提交 f302e734 编写于 作者: 秦英杰

fix:函数习题

上级 21b5fdec
...@@ -4,24 +4,8 @@ ...@@ -4,24 +4,8 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="a58667c7-f41c-4f13-881e-dc86f57d3cdc" name="Changes" comment=""> <list default="true" id="a58667c7-f41c-4f13-881e-dc86f57d3cdc" name="Changes" comment="fix:基础语法">
<change beforePath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/material_theme_project_new.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/material_theme_project_new.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/modules.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/python-demo.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/python-demo.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/01_Python入门语法/02_Python中的注释.py" beforeDir="false" afterPath="$PROJECT_DIR$/01_Python入门语法/02_Python中的注释.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/01_Python入门语法/04_Python中的数据类型.py" beforeDir="false" afterPath="$PROJECT_DIR$/01_Python入门语法/04_Python中的数据类型.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/01_Python入门语法/08_Python的字符串格式化.py" beforeDir="false" afterPath="$PROJECT_DIR$/01_Python入门语法/08_Python的字符串格式化.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/02_Python判断语句/01_布尔类型和比较运算符.py" beforeDir="false" afterPath="$PROJECT_DIR$/02_Python判断语句/01_布尔类型和比较运算符.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/02_Python判断语句/05_if_elif_else语句的使用.py" beforeDir="false" afterPath="$PROJECT_DIR$/02_Python判断语句/05_if_elif_else语句的使用.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/03_Python循环语句/01_while循环练习题_求1-100的和.py" beforeDir="false" afterPath="$PROJECT_DIR$/03_Python循环语句/01_while循环练习题_求1-100的和.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/03_Python循环语句/06_for循环练习题-数一数有几个a.py" beforeDir="false" afterPath="$PROJECT_DIR$/03_Python循环语句/06_for循环练习题-数一数有几个a.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/03_Python循环语句/07_for循环的基础语法.py" beforeDir="false" afterPath="$PROJECT_DIR$/03_Python循环语句/07_for循环的基础语法.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/03_Python循环语句/08_range语句.py" beforeDir="false" afterPath="$PROJECT_DIR$/03_Python循环语句/08_range语句.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/03_Python循环语句/12_循环中断.py" beforeDir="false" afterPath="$PROJECT_DIR$/03_Python循环语句/12_循环中断.py" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
...@@ -31,37 +15,40 @@ ...@@ -31,37 +15,40 @@
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component> </component>
<component name="ProjectColorInfo"><![CDATA[{ <component name="ProjectColorInfo">{
"associatedIndex": 7 &quot;associatedIndex&quot;: 7
}]]></component> }</component>
<component name="ProjectId" id="2jYDu6oib9nSDoOVTbxbUyGqmRv" /> <component name="ProjectId" id="2jYDu6oib9nSDoOVTbxbUyGqmRv" />
<component name="ProjectLevelVcsManager">
<OptionsSetting value="false" id="Update" />
</component>
<component name="ProjectViewState"> <component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"Python.01_while循环练习题_求1-100的和.executor": "Debug", &quot;Python.01_while循环练习题_求1-100的和.executor&quot;: &quot;Debug&quot;,
"Python.03_while循环的基础案例-猜数字.executor": "Debug", &quot;Python.03_while循环的基础案例-猜数字.executor&quot;: &quot;Debug&quot;,
"Python.05_while循环的嵌套案例-九九乘法表.executor": "Debug", &quot;Python.05_while循环的嵌套案例-九九乘法表.executor&quot;: &quot;Debug&quot;,
"Python.06_for循环练习题-数一数有几个a.executor": "Debug", &quot;Python.06_for循环练习题-数一数有几个a.executor&quot;: &quot;Debug&quot;,
"Python.07_for循环的基础语法.executor": "Debug", &quot;Python.07_for循环的基础语法.executor&quot;: &quot;Debug&quot;,
"Python.08_range语句.executor": "Debug", &quot;Python.08_range语句.executor&quot;: &quot;Debug&quot;,
"Python.09_变量作用域.executor": "Debug", &quot;Python.09_变量作用域.executor&quot;: &quot;Debug&quot;,
"Python.10_for循环打印九九乘法表.executor": "Debug", &quot;Python.10_for循环打印九九乘法表.executor&quot;: &quot;Debug&quot;,
"Python.12_循环中断.executor": "Debug", &quot;Python.12_循环中断.executor&quot;: &quot;Debug&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"git-widget-placeholder": "main", &quot;git-widget-placeholder&quot;: &quot;main&quot;,
"last_opened_file_path": "/Users/qinyingjie/Documents/python-workspace/python-demo", &quot;last_opened_file_path&quot;: &quot;/Users/qinyingjie/Documents/python-workspace/python-demo&quot;,
"node.js.detected.package.eslint": "true", &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
"node.js.detected.package.tslint": "true", &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
"node.js.selected.package.eslint": "(autodetect)", &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
"node.js.selected.package.tslint": "(autodetect)", &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
"nodejs_package_manager_path": "npm", &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
"settings.editor.selected.configurable": "configurable.group.appearance", &quot;settings.editor.selected.configurable&quot;: &quot;configurable.group.appearance&quot;,
"vue.rearranger.settings.migration": "true" &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
} }
}]]></component> }</component>
<component name="RunManager" selected="Python.12_循环中断"> <component name="RunManager" selected="Python.12_循环中断">
<configuration name="07_for循环的基础语法" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> <configuration name="07_for循环的基础语法" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="python-demo" /> <module name="python-demo" />
...@@ -204,13 +191,29 @@ ...@@ -204,13 +191,29 @@
<option name="number" value="Default" /> <option name="number" value="Default" />
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1721555336016</updated> <updated>1721555336016</updated>
<workItem from="1721555337062" duration="1175000" /> <workItem from="1721555337062" duration="3261000" />
<workItem from="1721649016652" duration="574000" />
<workItem from="1721739596602" duration="899000" />
<workItem from="1721787987928" duration="42000" />
</task>
<task id="LOCAL-00001" summary="fix:基础语法">
<option name="closed" value="true" />
<created>1721556543911</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1721556543911</updated>
</task> </task>
<option name="localTasksCounter" value="2" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" /> <option name="version" value="3" />
</component> </component>
<component name="VcsManagerConfiguration">
<MESSAGE value="fix:基础语法" />
<option name="LAST_COMMIT_MESSAGE" value="fix:基础语法" />
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl"> <component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/python_demo$06_for_a.coverage" NAME="06_for循环练习题-数一数有几个a Coverage Results" MODIFIED="1721556053815" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/03_Python循环语句" /> <SUITE FILE_PATH="coverage/python_demo$06_for_a.coverage" NAME="06_for循环练习题-数一数有几个a Coverage Results" MODIFIED="1721556053815" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/03_Python循环语句" />
<SUITE FILE_PATH="coverage/python_demo$09_.coverage" NAME="09_变量作用域 Coverage Results" MODIFIED="1721556377642" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/03_Python循环语句" /> <SUITE FILE_PATH="coverage/python_demo$09_.coverage" NAME="09_变量作用域 Coverage Results" MODIFIED="1721556377642" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/03_Python循环语句" />
......
""" """
演示函数基础定义练习案例:自动查核酸 演示函数基础定义练习案例:自动查核酸
""" """
# 定义函数 # 定义函数
def check(): def check():
# 编写函数体输出信息 # 编写函数体输出信息
print("欢迎来到黑马程序员!\n请出示您的健康码以及72小时核酸证明!") print("欢迎来到黑马程序员!\n请出示您的健康码以及72小时核酸证明!")
# 调用函数 # 调用函数
check() check()
\ No newline at end of file
...@@ -8,7 +8,7 @@ def list_while_func(): ...@@ -8,7 +8,7 @@ def list_while_func():
使用while循环遍历列表的演示函数 使用while循环遍历列表的演示函数
:return: None :return: None
""" """
my_list = ["传智教育", "黑马程序员", "Python"] my_list = ["传智教育", "程序员", "Python"]
# 循环控制变量通过下标索引来控制,默认0 # 循环控制变量通过下标索引来控制,默认0
# 每一次循环将下标索引变量+1 # 每一次循环将下标索引变量+1
# 循环条件:下标索引变量 < 列表的元素数量 # 循环条件:下标索引变量 < 列表的元素数量
......
...@@ -2,10 +2,12 @@ ...@@ -2,10 +2,12 @@
演示函数使用参数 演示函数使用参数
""" """
# 定义2数相加的函数,通过参数接收被计算的2个数字 # 定义2数相加的函数,通过参数接收被计算的2个数字
def add(x, y, z): def add(x, y, z):
result = x + y + z result = x + y + z
print(f"{x} + {y} + {z}的计算结果是:{result}") print(f"{x} + {y} + {z}的计算结果是:{result}")
# 调用函数,传入被计算的2个数字 # 调用函数,传入被计算的2个数字
add(5, 6, 7) add(5, 6, 7)
...@@ -2,22 +2,28 @@ ...@@ -2,22 +2,28 @@
演示特殊字面量:None 演示特殊字面量:None
""" """
# 无return语句的函数返回值 # 无return语句的函数返回值
def say_hi(): def say_hi():
print("你好呀") print("你好呀")
result = say_hi() result = say_hi()
print(f"无返回值函数,返回的内容是:{result}") print(f"无返回值函数,返回的内容是:{result}")
print(f"无返回值函数,返回的内容类型是:{type(result)}") print(f"无返回值函数,返回的内容类型是:{type(result)}")
# 主动返回None的函数 # 主动返回None的函数
def say_hi2(): def say_hi2():
print("你好呀") print("你好呀")
return None return None
result = say_hi2() result = say_hi2()
print(f"无返回值函数,返回的内容是:{result}") print(f"无返回值函数,返回的内容是:{result}")
print(f"无返回值函数,返回的内容类型是:{type(result)}") print(f"无返回值函数,返回的内容类型是:{type(result)}")
# None用于if判断 # None用于if判断
def check_age(age): def check_age(age):
if age > 18: if age > 18:
...@@ -25,6 +31,7 @@ def check_age(age): ...@@ -25,6 +31,7 @@ def check_age(age):
else: else:
return None return None
result = check_age(16) result = check_age(16)
if not result: if not result:
# 进入if表示result是None值 也就是False # 进入if表示result是None值 也就是False
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
演示对函数进行文档说明 演示对函数进行文档说明
""" """
# 定义函数,进行文档说明 # 定义函数,进行文档说明
def add(x, y): def add(x, y):
""" """
...@@ -14,5 +15,5 @@ def add(x, y): ...@@ -14,5 +15,5 @@ def add(x, y):
print(f"2数相加的结果是:{result}") print(f"2数相加的结果是:{result}")
return result return result
add(5, 6)
add(5, 6)
...@@ -2,9 +2,12 @@ ...@@ -2,9 +2,12 @@
演示嵌套调用函数 演示嵌套调用函数
""" """
# 定义函数func_b # 定义函数func_b
def func_b(): def func_b():
print("---2---") print("---2---")
# 定义函数func_a,并在内部调用func_b # 定义函数func_a,并在内部调用func_b
def func_a(): def func_a():
print("---1---") print("---1---")
...@@ -13,5 +16,7 @@ def func_a(): ...@@ -13,5 +16,7 @@ def func_a():
func_b() func_b()
print("---3---") print("---3---")
# 调用函数func_a # 调用函数func_a
func_a() func_a()
...@@ -42,14 +42,17 @@ ...@@ -42,14 +42,17 @@
# global关键字,在函数内声明变量为全局变量 # global关键字,在函数内声明变量为全局变量
num = 200 num = 200
def test_a(): def test_a():
print(f"test_a: {num}") print(f"test_a: {num}")
def test_b(): def test_b():
global num # 设置内部定义的变量为全局变量 global num # 设置内部定义的变量为全局变量
num = 500 num = 500
print(f"test_b: {num}") print(f"test_b: {num}")
test_a() test_a()
test_b() test_b()
print(num) print(num)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册