-
Notifications
You must be signed in to change notification settings - Fork 0
/
00Homework.py
55 lines (42 loc) · 1.35 KB
/
00Homework.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import random
def answer130105():
path = input("请输入文档路径:")
targetWord = input("请输入要删除的字符")
with open(path, "r+", encoding="utf-8") as file:
oldText = file.read()
# newText = oldText.replace(targetWord, "")
newText = oldText.replace(targetWord, "九")
file.seek(0)
file.truncate()
file.write(newText)
pass
def answer130304():
# 生成虚拟数据
# scoreList = []
# for i in range(70):
# score = random.randint(0,100)
# score = str(score)+" "
# scoreList.append(score)
# print(scoreList)
# path = input("请输入文档路径:")
# with open(path,"r+",encoding="utf-8") as file:
# file.writelines(scoreList)
path = input("请输入文档路径:")
with open(path, "r+", encoding="utf-8") as file:
text = file.read()
scoreList = text.split(" ")
# scoreList.sort()
# tempList = []
# for scoreStr in scoreList:
# tempList.append(int(scoreStr))
tempList = [int(scoreStr) for scoreStr in scoreList]
tempList.sort()
print(tempList)
total = 0
for score in scoreList:
total += int(score)
print(total)
print("avg=", total / len(scoreList))
pass
# answer1301()
answer130105()