-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuestion.py
48 lines (39 loc) · 943 Bytes
/
Question.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
### 1.计算平方和
def Sum(n):
sum = 0
for i in range(1,n+1):
sum += i*i
return sum
n = int(input("请输入:"))
print(Sum(n))
### 2.列表的反转
a = [1,2,3,4,5]
a.reverse()
print('列表反转结果是: ',a)
a = [1,2,3,4,5]
b = []
for i in a:
b = [i] + b
print(b)
### 3.寻找最大值
def max_num(list):
return max(list)
list = [4,7,1,9,3]
print(max_num(list))
def max_num(list):
_max = list[0]
for i in list:
if (i > _max):
_max = i
return _max
list = [4,7,1,9,3]
print(max_num(list))
### 7.计算平均值
def calculate_scores(scores):
max_socre = max(scores)
min_score = min(scores)
average_score = round(sum(scores)/len(scores),2)
return {"最高分":max_socre, "最低分":min_score, "平均分": average_score }
scores=[85, 90, 78, 92, 88]
print(calculate_scores(scores))
### 13.猜数字