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
5cd324b7
authored
Aug 21, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
578e41ee
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
9 deletions
1.py
2.py
__pycache__/func.cpython-37.pyc
func.py
1.py
0 → 100644
View file @
5cd324b7
import
func
a
=
func
.
new_input
()
b
=
sum
(
a
)
print
(
b
)
\ No newline at end of file
2.py
0 → 100644
View file @
5cd324b7
try
:
#尝试执行的语句,该语句可能会出现错误
age
=
int
(
input
(
"今年的年龄"
))
except
:
#当程序出现错误时
print
(
'要输入整数啊'
)
else
:
#当程序没有出错时进入else语句
if
age
<
18
:
print
(
"不可以喝酒哦"
)
print
(
"程序结束"
)
\ No newline at end of file
__pycache__/func.cpython-37.pyc
0 → 100644
View file @
5cd324b7
File added
func.py
View file @
5cd324b7
total
=
[]
def
new_input
():
while
True
:
total
=
[]
unit
=
input
(
"请输入:"
)
while
True
:
if
unit
==
'q'
:
unit
=
input
(
"请输入:"
)
break
if
unit
==
'q'
:
else
:
break
total
.
append
(
unit
)
else
:
print
(
total
)
#try-except-else异常捕捉结构
\ No newline at end of file
try
:
unit
=
int
(
unit
)
except
:
print
(
"请重新输入数字,输入一个整数"
)
else
:
total
.
append
(
unit
)
return
total
#return 是返回,可以将函数内部的数据返回到函数调用的地方
#返回到函数调用处没有办法直接看到结果,需要配合print函数来输出查看
def
sum
(
money
):
#money 是一个参数,是形参
count
=
0
for
i
in
money
:
count
+=
i
return
count
# p = new_input()
# print(p)
# a = sum(p)#p是一个列表,存储菜品单价的列表
# print(a)
\ No newline at end of file
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