圖片

第一題

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
n=int(input())
sum_a=1
for i in range(1,n+1,1):
sum_a=sum_a*i
print(sum_a)

temp=sum_a
sum_b=0
while temp // 10 !=0:
sum_b=sum_b+temp%10
temp=temp//10
sum_b=sum_b+temp
print(sum_b)

count=0
if sum_a==0:
print('0')
else:
while sum_a%10==0:
count+=1
sum_a=sum_a//10
print(count)

第一題測資


第二題

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def leap_month_sum_day(month,year): # 回傳該月份累積天數 
leap_year_day_add=[0,31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366]
not_leap_year_day_add=[0,31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365]
if leap_check(year):
return leap_year_day_add[month-1]
else:
return not_leap_year_day_add[month-1]

def leap_check(year):
if (year%400==0) or (year%4==0 and year%100!=0):
return 1
else:
return 0

date=list(map(int,input().split('/')))
sum_day=leap_month_sum_day(date[1],date[0])+date[2]
print(sum_day)

第二題測資


第三題

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
#6 7 8 9 8 7 8 9 8 9 7 8 9 5 9 8 7 8 7 8 6 7 8 9 3 9 8 7 8 7 7 8 9 8 9 8 9 7 8 9 6 7 8 7 8 7 9 8 9 2 7 8 9 8 9 8 9 7 5 3 5 6 7 2 5 3 9 4 6 4 7 8 9 6 8 7 8 9 7 8 7 4 4 2 5 3 8 7 5 6 4 5 6 1 6 5 7 8 7
# 前置作業
from math import sqrt
the_list=list(map(int,input().split()))
the_list.sort()
length=len(the_list)
print(the_list)
# 平均
averge=0
temp=0

for i in range (0,length,1):
temp=temp+the_list[i]
averge=temp/length
print(averge)

# 中位數
if length%2==0:
print((the_list[length//2-1]+the_list[length//2])/2)
else:
print(the_list[length//2])

# 眾數
ans = []
count = []
ans.append(the_list[0])
count.append(0)
j = 0
count[j] += 1
max_num = 0
for i in range(1, length, 1):
if the_list[i] == the_list[i - 1]:
count[j] += 1
else:
ans.append(the_list[i])
j += 1
count.append(0)
count[j] += 1
for i in range(0,len(count),1):
if max_num < count[i]:
max_num = count[i]

for i in range(0, j + 1, 1):
if count[i] == max_num:
print(ans[i],end='')
print("")# 換行
# 標準差
sum_square=0
for i in range(0,length,1):
sum_square=sum_square+(the_list[i]-averge)**2

sum_square=sum_square/length
sum_square=sqrt(sum_square)
print(sum_square)

第三題測資



作者: 微風