Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson13-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
a77eefa8
authored
Sep 04, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
5ec53ebb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
0 deletions
diy.py
sales_list1.txt
diy.py
View file @
a77eefa8
alist
=
[]
with
open
(
"sales_list.txt"
,
"r"
,
encoding
=
'utf-8'
)
as
f
:
#文件对象.readlines() 多行读取 将文件中的数据以列表形式读取进来
r
=
f
.
readlines
()
#遍历读取进来的列表
for
i
in
r
:
#字符串.split("符号") 功能:将字符串按括号里指定的符号进行划分,省略括号内的符号,默认为空格
date
=
i
.
split
()
#统计义卖款
sum
=
0
for
sale
in
date
[
1
:]:
sum
+=
int
(
sale
)
# sum = sum + int(sale)
name
=
date
[
0
]
+
" "
+
str
(
sum
)
+
"
\n
"
alist
.
append
(
name
)
with
open
(
"sales_list1.txt"
,
"a"
,
encoding
=
'utf-8'
)
as
f
:
#文件对象.writelines(列表)
f
.
writelines
(
alist
)
\ No newline at end of file
sales_list1.txt
0 → 100644
View file @
a77eefa8
悟空 348
诺依 380
小贝 182
李丽 201
宋扬 107
王明 245
李强 164
孙小白 222
苏琪 137
刘若若 147
刘阳 226
王胜男 123
王娇 131
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