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
139d8e2b
authored
Nov 13, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
ecbbd9f6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
10 deletions
diy.py
sales_list.txt
diy.py
View file @
139d8e2b
with
open
(
r
"c:\Users\ThinkPad\Documents\lesson13-1\sales_list.txt"
,
"r"
,
encoding
=
"UTF-8"
)
as
file
:
with
open
(
r
'c:\Users\ThinkPad\Documents\lesson13-1\sales_list.txt'
,
'r'
,
encoding
=
'UTF-8'
)
as
file
:
a
=
file
.
readlines
()
a
=
file
.
readlines
()
# print(a)
# print(a)
for
i
in
a
:
final_sum
=
[]
data
=
i
.
split
()
for
i
in
a
:
#用for...in... 把每一行的数据遍历
data
=
i
.
split
()
#把字符串切分成更细的一个个的字符串
print
(
data
[
1
:])
print
(
data
[
1
:])
sum
=
0
sum
=
0
#先把总数设为0
for
sales
in
data
[
1
:]:
for
sales
in
data
[
1
:]:
#遍历列表中第1个数据和之后的数据
sum
=
sum
+
int
(
sales
)
sum
=
sum
+
int
(
sales
)
#然后依次加起来,但sales是字符串,所以要更换
result
=
data
[
0
]
+
str
(
sum
)
result
=
data
[
0
]
+
str
(
sum
)
#结果就是学生姓名和总义卖款,后面加上换行符,写入的时候更清晰
print
(
result
)
print
(
result
)
#打印看看
final_sum
.
append
(
result
)
#每次把结果都补充到列表中
with
open
(
r'c:\Users\ThinkPad\Documents\lesson13-1\sales_list.txt'
,
'a'
,
encoding
=
'UTF-8'
)
as
file
:
file
.
writelines
(
final_sum
)
sales_list.txt
View file @
139d8e2b
...
@@ -10,4 +10,4 @@
...
@@ -10,4 +10,4 @@
刘若若 11 11 13 11 20 15 13 29 24
刘若若 11 11 13 11 20 15 13 29 24
刘阳 11 15 22 11 23 26 22 15 17 52 12
刘阳 11 15 22 11 23 26 22 15 17 52 12
王胜男 27 15 15 26 13 12 15
王胜男 27 15 15 26 13 12 15
王娇 12 11 12 12 15 35 23 11
王娇 12 11 12 12 15 35 23 11悟空348诺依380小贝182李丽201宋扬107王明245李强164孙小白222苏琪137刘若若147刘阳226王胜男123王娇131
\ 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