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
07b6f4cb
authored
May 29, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
bbe03836
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
4 deletions
diy.py
diy.py
View file @
07b6f4cb
with
open
(
r'c:\Users\Admin\Documents\lesson13-1\sales_list.txt'
,
'r'
,
encoding
=
'utf-8'
)
as
files
:
a
=
files
.
readlines
()
print
(
a
)
\ No newline at end of file
with
open
(
r'c:\Users\Admin\Documents\lesson13-1\sales_list.txt'
,
'r'
,
encoding
=
'utf-8'
)
as
files
:
#read 读取
a
=
files
.
readlines
()
#逐行读取
# print(a)
finally_sum
=
[]
for
i
in
a
:
#循环遍历
result
=
i
.
split
()
#分割默认为为列表
# print(result[1:])
sum
=
0
for
sale
in
result
[
1
:]:
sum
=
sum
+
int
(
sale
)
#累加义卖款 int()整数
count
=
result
[
0
]
+
str
(
sum
)
+
'
\n
'
#名字和义卖款做拼接
finally_sum
.
append
(
count
)
with
open
(
r'c:\Users\Admin\Desktop\test.txt'
,
'w'
,
encoding
=
'utf-8'
)
as
files
:
files
.
writelines
(
finally_sum
)
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