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

fix:函数习题

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