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
23cf2c63
authored
Nov 15, 2020
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
86467fcb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
16 deletions
__pycache__/返回.cpython-37.pyc
总和.py
返回.py
__pycache__/返回.cpython-37.pyc
View file @
23cf2c63
No preview for this file type
总和.py
0 → 100644
View file @
23cf2c63
import
返回
import
返回
a
=
返回
.
diancan
()
b
=
返回
.
sum
()
\ No newline at end of file
返回.py
View file @
23cf2c63
def
d
iancan
():
def
d
iancan
():
def
diancan
():
def
diancan
():
total
=
[]
total
=
[]
while
True
:
while
True
:
unit
=
input
(
"请输入:"
)
unit
=
input
(
"请输入:"
)
if
unit
==
'q'
:
if
unit
==
'q'
:
break
break
else
:
else
:
try
:
try
:
#尝试执行
unit
=
int
(
unit
)
unit
=
int
(
unit
)
#尝试执行把输入的unit转换成整数类型
except
:
except
:
print
(
"请重新输入一个数字"
)
print
(
"请重新输入一个数字"
)
#报错的话就会有重新输入的报错提示
else
:
else
:
total
.
append
(
unit
)
total
.
append
(
unit
)
#如果可以转换就在列表末尾添加输入的unit
return
total
return
total
#返回列表
def
sum
(
money
):
def
sum
(
money
):
# 计算价钱的函数 money是形参 也就是上边刚才输入的列表
count
=
0
count
=
0
#计算累加和的变量
for
i
in
money
:
for
i
in
money
:
#遍历money列表
count
=
count
+
i
count
+=
i
#依次计算列表中的价格
return
count
return
count
#返回count
zhangdan
=
diancan
()
#zhangdan是我们的列表
a
=
diancan
()
#用来接收diancan()函数中的列表
zonghe
=
sum
(
zhangdan
)
b
=
sum
(
a
)
#把diancan()函数中的列表当做sum()中的实参
print
(
zonghe
)
print
(
b
)
#打印出计算的结果
\ No newline at end of file
\ 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