更新第三次实验

This commit is contained in:
Luthics 2022-11-06 14:04:19 +08:00
parent dd358ecfdf
commit e0c587e7bf
4 changed files with 31 additions and 0 deletions

5
test/3/1.py Normal file
View File

@ -0,0 +1,5 @@
n = int(input())
s = 1
for i in range(n):
s *= (i + 1)
print(s)

11
test/3/2.py Normal file
View File

@ -0,0 +1,11 @@
n = input()
a = int(n.split('-')[1]) # 暴力取出小数位数和精度
i = 1
s = 0
while (1 / (2 * i - 1) >= 10**(-a)): # 精度要求作为条件
if (i % 2 == 0):
s -= 1 / (2 * i - 1)
else:
s += 1 / (2 * i - 1)
i += 1
print(("{:." + str(a) + "f}").format(s * 4))

5
test/3/3.py Normal file
View File

@ -0,0 +1,5 @@
n = int(input())
a = [0, 1]
for i in range(2, n + 1):
a.append(a[i - 1] + a[i - 2]) # 递推
print(a[n])

10
test/3/4.py Normal file
View File

@ -0,0 +1,10 @@
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
for j in range(i + 1, n):
if (a[j] < a[i]):
ls = a[i]
a[i] = a[j]
a[j] = ls
for i in range(n):
print(a[i], end=" ")