Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson11_1
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
475783d0
authored
Oct 10, 2024
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
365efaec
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
9 deletions
921.py
__pycache__/func.cpython-37.pyc
func.py
lx.py
921.py
0 → 100644
View file @
475783d0
try
:
# 尝试执行的代码
except
:
# 如果try下面的代码报错,就执行except下面的代码
else
:
# 如果try下面的代码没有报错,就执行else下面的代码
# 不缩进的代码最终会被执行
def
函数名(形式参数):
函数主体
函数名(实际参数)
\ No newline at end of file
__pycache__/func.cpython-37.pyc
0 → 100644
View file @
475783d0
File added
func.py
View file @
475783d0
def
new_input
():
total
=
[]
while
True
:
def
new_input
():
# 自定义函数用来将价格添加到列表中
total
=
[]
# 创建空列表,用来保存菜品价格
while
True
:
unit
=
input
(
"请输入:"
)
if
unit
==
'q'
:
if
unit
==
'q'
:
# 如果按下“q”,跳出循环 quit
break
else
:
total
.
append
(
unit
)
print
(
total
)
new_input
()
\ No newline at end of file
else
:
# 如果没有按下“q”
try
:
# 尝试执行的代码
unit
=
int
(
unit
)
except
:
# 如果try下面的代码报错,就执行except下面的代码
print
(
"要输入整数呀"
)
else
:
# 如果try下面的代码没有报错,就执行else下面的代码
total
.
append
(
unit
)
return
total
# 返回已经添加完菜品价格的列表
def
sum
(
money
):
# 定义一个用来计算总价的函数
c
=
0
for
i
in
money
:
c
+=
i
# c=c+i
return
c
result
=
new_input
()
# 调用new_input()
a
=
sum
(
result
)
# 调用sum(money)
print
(
result
)
# 打印/输出result
print
(
a
)
# 打印总价
lx.py
0 → 100644
View file @
475783d0
import
func
a
=
func
.
new_input
()
b
=
func
.
sum
(
a
)
print
(
"本次跳水比赛的总分为:"
,
b
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment