Signed-off-by: big <1638587056@qq.com>

This commit is contained in:
big 2024-07-12 18:54:25 +08:00
commit d2a22c0249
19 changed files with 342 additions and 0 deletions

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# 默认忽略的文件
/shelf/
/workspace.xml

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (2)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/python程序.iml" filepath="$PROJECT_DIR$/.idea/python程序.iml" />
</modules>
</component>
</project>

10
.idea/python程序.iml Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.10 (2)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

19
20240629.py Normal file
View File

@ -0,0 +1,19 @@
#插入排序
num = [13,2,8,12,1,456,89]
for i in range(1,len(num)):
key = num[i] #获取未排序部分的第一项值
j = i-1 #设置已排序部分的最后一位编号
print("需要插入的值:", key)
while j>=0 and num[j]<key:
num[j+1] = num[j]
j -= 1
print(key,"放在了第",j+1)
num[j+1] = key
print(num)
'''
(n-1)*(n-1)
=n*n - n*1 - 1*n + 1*1
=n*n - 2*n + 1
时间复杂度 O(n^2)
'''

7
20240629排序.py Normal file
View File

@ -0,0 +1,7 @@
d1 = {"a":10,"b":20,"c":2,"d":7,"e":6}
l1 = list(d1)
for j in range(len(l1) - 1):
for i in range(len(l1) - 1):
if d1[l1[i]] > d1[l1[i+1]]:
d1[l1[i]],d1[l1[i+1]] = d1[l1[i+1]],d1[l1[i]]
print(d1)

View File

@ -0,0 +1,62 @@
import sys
import pygame
#初始化pygame
pygame.init()
#初始化显示
pygame.display.init()
#创建显示窗口
sc = pygame.display.set_mode((400,300))
#创建时钟对象
clock = pygame.time.Clock()
#设置变量运行游戏为真
is_running = True
#砖块初始化
zk_x = 7.5#第一块转的x坐标
zk_y = 5#第一块转的y坐标
zk_w = 30#砖块的宽度
zk_h = 10#砖块的高度
zk_list = []#初始化砖块列表
#行
for j in range(4):
#列
for i in range(11):
r = pygame.Rect(zk_x,zk_y,zk_w,zk_h)#创建砖块的矩形区域
zk_list.append(r)#将矩形区域加入列表中
zk_x += 35#更新x坐标
zk_y += 15#更新y坐标
zk_x = 7.5#重置x坐标
ballx = 200#小球的x坐标
bally = 150#
ball_speed_x = 2#
ball_speed_y = 2#
#游戏主循环
while is_running:
#背景填充黑色
sc.fill("black")
#遍历砖块列表
for z in zk_list:
#绘制砖块
pygame.draw.rect(sc,"white",z)
ball = pygame.draw.circle(sc, "white", (ballx, bally), 5)
ballx = ballx + ball_speed_x
bally = bally + ball_speed_y
if ballx > 395 or ballx < 5 :
ball_speed_x = -ball_speed_x
if bally > 295 or bally < 5 :
ball_speed_y = -ball_speed_y
#遍历事件
for event in pygame.event.get():
#如果事件为退出事件
if event.type == pygame.QUIT:
is_running = False
pygame.display.flip()#显示更新
clock.tick(60)#设置更新帧率为60
pygame.quit()#结束pygame初始化
sys.exit()#结束系统进程

15
20240702.py Normal file
View File

@ -0,0 +1,15 @@
h = int(input())
m = int(input())
s = int(input())
k = int(input())
s += k
if s >= 60:
s = s-60
m += s//60
s = s%60
if m >= 60:
h += m//60
m = m%60
print(h,m,s)

10
20240703.py Normal file
View File

@ -0,0 +1,10 @@
# 循环变量,用于记录每一次循环的数据
# 0 <= a < 100\
l1 = [12,45,67,89,0,34,56]
m = 0
for i in l1:
if i>m:
m = i
print(m)

19
20240704.py Normal file
View File

@ -0,0 +1,19 @@
import turtle
turtle.title("多边形")
turtle.bgcolor("black") # 设置背景颜色
turtle.speed(0) # 设置画笔速度
turtle.penup() # 抬笔
turtle.pendown() # 落笔
turtle.pencolor("white")# 设置画笔颜色
a = turtle.numinput("边数","请问需要绘制几边形") #获取用户输入,得到的是浮点型数据
a = int(a)#将变量a转换为整数类型
b = turtle.numinput("花瓣数量","这朵花有几个花瓣")
b = int(b)# 将b转换为整数
for j in range(b):
for i in range(a):
turtle.forward(100)#前进
turtle.left(360/a)#左转
turtle.left(360/b)
turtle.penup()
turtle.mainloop()

30
20240704b.py Normal file
View File

@ -0,0 +1,30 @@
'''
#print(round(132.56,-3))
n = int(input())
nums = []
for i in range(n):
a = int(input())
nums.append(a)
for i in nums:
f=0
for j in range(1,i+1):
for k in range(1,i+1):
if j*j + k*k == i:
f = 1
print("Yes")
break
if f == 1:
break
else:
print("No")'''
N = int(input())
k = int(input())
Sum = 0
for i in range(1,N+1):
for j in str(i):
if j == str(k):
Sum+=1
print(Sum)

18
20240706.py Normal file
View File

@ -0,0 +1,18 @@
t = int(input())
b = []
for i in range(t):
n = int(input())
a = input()
a = [int(j) for j in a.split()]
b.append(a)
for i in range(t):
m = max(b[i])
for j in b[i]:
if m%j != 0:
break
else:
print("Yes")
continue
print("No")

21
20240706b.py Normal file
View File

@ -0,0 +1,21 @@
l1 = [6, 4, 2, 1, 5]#未排序
for i in range(1,5):
print(i)
#第一次循环 i=1 key=4 j=0
#第二次循环 i=2 key=2 j=1
for i in range(1,len(l1)):
key = l1[i]
j = i-1
# l1 [4,6,2,1,5]
while j>=0 and key<l1[j]:
l1[j+1] = l1[j]#右移
# l1 [6,6,4,2,1,5]
j=j-1
l1[j+1] = key
print(l1)
l2 = [89,5,6,8,4,12,56,49,7]

13
20240709b递归.py Normal file
View File

@ -0,0 +1,13 @@
def fun(n):
#print(n)
if n == 1 or n==0:
return n
else:
return fun(n-1) + fun(n-2)
print(fun(8))
# 基本情况 n==1 or n==0 返回n
# 递归步骤 f(n) = f(n-1) + f(n-2)
# 1,3,5,7,9,11......

27
20240709递归.py Normal file
View File

@ -0,0 +1,27 @@
# 数列
# 13579
def fibonacci(n):
if n <= 1: # 基本情况第1项和第2项都是1
return n
else: # 递归情况第n项是前两项的和
return fibonacci(n - 1) + fibonacci(n - 2)
# n = 3
# n = 2
# n=1 结果1
# n=0 结果0
# 结果 1
# n = 1 结果1
# 结果 2
print(fibonacci(6))
# 阶乘 5的阶乘5*4*3*2*1
# 基本情况n==1, 返回1
# 递归过程n*f(n-1)
# 8的阶乘
# ---------------------------------
# n项的数列1,2,3,4,5,6,7,8......
# 使用递归求前n项数值的和
# 基本情况n==1
# 递归过程n+f(n-1)
# 前10项的和

25
20240710.py Normal file
View File

@ -0,0 +1,25 @@
# 基本情况列表长度小于等于1
# 递归过程:找中间值,与中间值进行比较,返回左,中,右连接后的结果
l = [5,3,7,6,4,1]
def fun(lst):
if len(lst) <= 1:
return lst
else:
mid = lst[0]
print("当前中间值:",mid)
left = []
right = []
for i in range(1,len(lst)):
if lst[i] < mid:
left.append(lst[i])
else:
right.append(lst[i])
print("左侧列表:",left)
print("右侧列表:", right)
return fun(left)+[mid]+fun(right)
fun(l)
# 使用快速排序实现对以下列表的排序,[98,89,78,69,53,78,99]

29
20240712.py Normal file
View File

@ -0,0 +1,29 @@
# 选择排序
a = [5,2,1,8,9,2,6,7]
for i in range(0,len(a)-1):
min_i = i # 设置最小值所对应的位置
for j in range(i+1, len(a)):
if a[j] < a[min_i]:
min_i = j # 更新最小值所对应的位置
a[i],a[min_i] = a[min_i],a[i] # 交换第i项和第最小值项
print(a)
'''
a = [5,2,1,8,9,2,6,7]
第一轮
i = 0 min_i = 0
j = 1 a[1] < a[0]? min_i = 1
j = 2 a[2] < a[1]? min_i = 2
j = 3 a[3] < a[2]? min_i = 2
j = 4 a[4] < a[2]? min_i = 2
j = 5 a[5] < a[min_i]? min_i = 2
j = 6 a[j] < a[min_i]? min_i = 2
j = 7 a[j] < a[min_i]? min_i = 2
a[i],a[min_i]交换 [1,2,5,8,9,2,6,7]
i = 1 min_i = 1
j = 2 a[j]<a[min_i]? min_i = 1
...
...
'''

16
main.py Normal file
View File

@ -0,0 +1,16 @@
# 这是一个示例 Python 脚本。
# 按 Shift+F10 执行或将其替换为您的代码。
# 按 双击 Shift 在所有地方搜索类、文件、工具窗口、操作和设置。
def print_hi(name):
# 在下面的代码行中使用断点来调试脚本。
print(f'Hi, {name}') # 按 Ctrl+F8 切换断点。
# 按间距中的绿色按钮以运行脚本。
if __name__ == '__main__':
print_hi('PyCharm')
# 访问 https://www.jetbrains.com/help/pycharm/ 获取 PyCharm 帮助