更新第二次作业剩下的题目

This commit is contained in:
Luthics 2022-10-20 21:59:07 +08:00
parent a273b013ab
commit 6f80c04be3
8 changed files with 91 additions and 0 deletions

6
homework/2/11.py Normal file
View File

@ -0,0 +1,6 @@
x = []
ans = 0
for i in range(4):
x.append(list(map(float, input().split())))
ans += x[i][i] + x[i][3-i]
print(ans)

15
homework/2/12.py Normal file
View File

@ -0,0 +1,15 @@
from math import *
def zs(n): # 朴素质数判断
if (n == 1):
return False
for i in range(2, floor(sqrt(n))+1):
if (n % i == 0):
return False
return True
for i in range(1, 99):
if (zs(i) and zs(i+2)):
print(i, i+2)

10
homework/2/13.py Normal file
View File

@ -0,0 +1,10 @@
from math import *
n, a = map(int, input().split())
ans = 0
for i in range(n):
ans += a*pow(10, i)*(n-i)
print(floor(ans))

8
homework/2/14.py Normal file
View File

@ -0,0 +1,8 @@
ans = 0
a = 2
b = 1
for i in range(20):
ans += a/b
a = a+b
b = a-b
print(round(ans, 2))

17
homework/2/15.py Normal file
View File

@ -0,0 +1,17 @@
from math import *
def zs(n): # 朴素质数判断
if (n == 1):
return False
for i in range(2, floor(sqrt(n))+1):
if (n % i == 0):
return False
return True
s = []
for i in range(2,1000):
if(zs(i)):
s.append(i)
print(s)

6
homework/2/16.py Normal file
View File

@ -0,0 +1,6 @@
x = list(map(int, input().split()))
y = list(map(int, input().split()))
s = x+y
s.sort()
for i in range(len(s)):
print(s[i], end=" ")

8
homework/2/17.py Normal file
View File

@ -0,0 +1,8 @@
n= int (input())
x= []
for i in range(n):
x.append(input().split()[0])
s= input()
for i in range(n):
if(s==x[i]):
print(i,end=" ")

21
homework/2/18.py Normal file
View File

@ -0,0 +1,21 @@
from math import *
def S(a, b, c):
p = (a+b+c)/2
ans = (p*(p-a)*(p-b)*(p-c))**0.5
return round(ans, 2)
def dis(a, b):
return sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)
s = []
for i in range(3):
s.append(list(map(float, input().split())))
a = dis(s[0], s[1])
b = dis(s[1], s[2])
c = dis(s[2], s[0])
print("{:.2f}".format(S(a, b, c)))