同步之前写好的程序

This commit is contained in:
Luthics 2022-10-20 20:59:33 +08:00
commit 3e07677d69
11 changed files with 65 additions and 0 deletions

5
homework/1/t1.py Normal file
View File

@ -0,0 +1,5 @@
x = float(input("清输入 x "))
if (x < 1):
print((x+1)**2) # x < 1
else:
print(4-(x-1)**0.5) # x >= 1

6
homework/1/t10.py Normal file
View File

@ -0,0 +1,6 @@
from math import *
a=[[0]*4]*4
for i in range(4):
a[i]=list(map(float,input().split()))
print (a)

11
homework/1/t2.py Normal file
View File

@ -0,0 +1,11 @@
n = int(input("请输入向量维数: "))
a = []
b = []
ans = 0
for i in range(n):
a.append(float(input("请输入第一个向量的 第"+str(i+1)+"个坐标: ")))
for i in range(n):
b.append(float(input("请输入第二个向量的 第"+str(i+1)+"个坐标: ")))
for i in range(n):
ans += a[i]*b[i]
print(ans)

7
homework/1/t3.py Normal file
View File

@ -0,0 +1,7 @@
n = int(input("请输入想要计算的 n "))
ans = 0 # 储存答案
to_mul = 1 # 计算阶乘的中间量,会储存 (n-1)!
for i in range(n):
to_mul *= (i+1)
ans += to_mul
print(ans)

5
homework/1/t4.py Normal file
View File

@ -0,0 +1,5 @@
n = int(input("请输入想要计算的 n "))
ans = 0 # 储存答案
for i in range(n):
ans += 1/(i+1)**2
print(ans)

5
homework/1/t5.py Normal file
View File

@ -0,0 +1,5 @@
n = int(input("请输入想要计算的 n "))
ans = 1 # 储存答案
for i in range(n):
ans *= 2*(i+1)*2*(i+1)/(2*i+1)/(2*i+3) # 根据公式计算
print(ans*2)

2
homework/1/t6.py Normal file
View File

@ -0,0 +1,2 @@
s = input("请输入待转换的字符串: ")
print(s.swapcase()) # 使用 swapcase 函数达到大小写互换的效果

10
homework/1/t7.py Normal file
View File

@ -0,0 +1,10 @@
a = [9, 34, 7, 26, 20, 16, 24, 149, 40, 41]
k = int(input("请输入想要查找的数字: "))
find = 0
for i in range(len(a)):
if (a[i] == k):
print("找到啦,你找的数是 a 中第 "+str(i)+" 个数") # 如果找到了
find = 1
break
if (find == 0): # 如果没找到
print("没找到你要的数字")

3
homework/1/t8.py Normal file
View File

@ -0,0 +1,3 @@
a = [1, 2, 3, 4, 5, 6]
x = int(input("请输入想要计算的 x : "))
print(str(a[5]*x**5+a[4]*x**4+a[3]*x**3+a[2]*x**2+a[1]*x+a[0])) #输出多项式

10
homework/1/t9.py Normal file
View File

@ -0,0 +1,10 @@
n = int(input("请输入想要计算的 n : ")) # 输入 n
if (n < 0): # 如果 n < 0
print("-", end="") # 先输出一个负号
n = -n # 再把 n 变成正的
elif (n == 0): # 如果 n = 0
print(0) # 直接输出 0 就可以
while (n > 0): # 实现逆序输出
print(n % 10, end="") # 每次输出 n 的最后一位
n /= 10 # 不断舍弃 n 的最后一位
n = int(n) # 解决浮点偏差

@ -0,0 +1 @@
Subproject commit 8de720524f2ffb84e159542109cf4a0e5a3617c4