Signed-off-by: sairate <sairate@sina.cn>

This commit is contained in:
sairate 2024-07-11 12:20:22 +08:00
commit e70ffbfdd8
18 changed files with 420 additions and 0 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

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

7
.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.12 (pythonProject)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (pythonProject)" 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/pythonProject.iml" filepath="$PROJECT_DIR$/.idea/pythonProject.iml" />
</modules>
</component>
</project>

10
.idea/pythonProject.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="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

1
lambada.py Normal file
View File

@ -0,0 +1 @@
print(sum(list(range(1,101,2))))

40
五星红旗.py Normal file
View File

@ -0,0 +1,40 @@
import turtle
turtle.speed(0)#设置速度为最快
def wujiao(size,x,y,angle=0):
#初始化开始位置和方向
turtle.penup()
turtle.goto(x,y)
turtle.setheading(angle)
turtle.pendown()
#循环绘制五角星
turtle.color("yellow","yellow")
turtle.begin_fill()
for i in range(5):
turtle.forward(size)
turtle.left(72)
turtle.forward(size)
turtle.right(144)
turtle.end_fill()
#绘制背景色
turtle.color("red","red")
turtle.begin_fill()
turtle.penup()
turtle.goto(-300,200)
turtle.pendown()
turtle.goto(300,200)
turtle.goto(300,-200)
turtle.goto(-300,-200)
turtle.goto(-300,200)
turtle.end_fill()
#五角星的绘制和参数
wujiao(30, -250, 150)
wujiao(9, -170, 180, 30)
wujiao(9, -140, 145, 45)
wujiao(9, -150, 120, 0)
wujiao(9, -170, 90, -30)
turtle.penup()
turtle.goto(0,0)
turtle.pendown()
turtle.write("中国",font=("华文行楷",50))
turtle.hideturtle()
turtle.done()#结束绘制

72
刘家赫.py Normal file
View File

@ -0,0 +1,72 @@
import turtle
import random
def move(x1, y1,x2, y2):
t1.penup()
t2.penup()
t1.goto(x1, y1)
t2.goto(x2, y2)
t1.pendown()
t2.pendown()
def draw(r,g,b,n,step):
for i in range(1,3*n+1):
if i>2*n:
t1.pencolor("white")
t2.pencolor("white")
t1.forward(step)
t2.forward(step)
t1.left(360/n)
t2.right(360/n)
elif (n%2==1):
t1.pencolor(r,g,b)
t2.pencolor(r,g,b)
t1.forward(step)
t2.forward(step)
t1.left(360/n)
t2.right(360/n)
else:
t1.pencolor("white")
t2.pencolor("white")
t1.forward(step)
t2.forward(step)
t1.left(360/n)
t2.right(360/n)
t1=turtle.Turtle()
t2=turtle.Turtle()
t2.left(180)
n=int(input())
step=int(input())
t1.speed(10)
t2.speed(10)
t1.pensize(5)
t2.pensize(5)
x1,y1=0,0
x2,y2=0,0
move(x1, y1,x2, y2)
while 1:
for i in range(5):
g=random.random()
b=random.random()
draw(1,g,0,n,step)
x1+=step
x2-=step
move(x1, y1, x2, y2)
for i in range(5):
g=random.random()
b=random.random()
draw(1,0,0,n,step)
x1-=step
x2+=step
move(x1, y1, x2, y2)
turtle.down()

28
判卷.py Normal file
View File

@ -0,0 +1,28 @@
b='ABCCBACBAC'
n=int(input('请输入人数'))
list=[]
for i in range(0,n):
temp=input()
while len(temp)!=len(b):
temp=input("重新输入:")
list.append(temp)
score=[0]
correct_daan=[""]
count=1
for j in list:
score.append(0)
correct_daan.append("")
daan=j
for i in range(0, 10):
if daan[i] == b[i]:
correct_daan[count] += b[i]
score[count] += 10
else:
correct_daan[count] += 'X'
count+=1
for i in range(1,len(score)):
print("{}号学员,{}分数".format(i,score[i]),correct_daan[i])

24
多人判卷.py Normal file
View File

@ -0,0 +1,24 @@
correct_answer="AAAAABBBBB"
n=int(input("请输入判卷人数"))
user_answer_list=[0]
user_score_list=[0]
mark_answer_list=[0]
for i in range(n):
user_answer_list.append(input("请输入{}号人的答案".format(i+1)))
for i in range(1,n+1):
user_score_list.append(0)
mark_answer_list.append("")
for j in range(len(correct_answer)):
if user_answer_list[i][j]==correct_answer[j]:
user_score_list[i]+=10
mark_answer_list[i]+=correct_answer[j]
else:
mark_answer_list[i]+="X"
for i in range(1,n+1):
print("{}号人成绩为{}分,矫正{}".format(i,user_score_list[i],mark_answer_list[i]))

68
巡线.py Normal file
View File

@ -0,0 +1,68 @@
import cv2
import numpy as np
def region_of_interest(img, vertices):
mask = np.zeros_like(img)
cv2.fillPoly(mask, vertices, 255)
masked_image = cv2.bitwise_and(img, mask)
return masked_image
def draw_lines(img, lines):
if lines is None:
return
img = np.copy(img)
blank_image = np.zeros((img.shape[0], img.shape[1], 3), dtype=np.uint8)
for line in lines:
for x1, y1, x2, y2 in line:
cv2.line(blank_image, (x1, y1), (x2, y2), (0, 255, 0), thickness=5)
img = cv2.addWeighted(img, 0.8, blank_image, 1, 0.0)
return img
def process(image):
height = image.shape[0]
width = image.shape[1]
region_of_interest_vertices = [
(0, height),
(width // 2, height // 2),
(width, height)
]
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
canny_image = cv2.Canny(gray_image, 100, 200)
cropped_image = region_of_interest(canny_image,
np.array([region_of_interest_vertices], np.int32))
lines = cv2.HoughLinesP(cropped_image,
rho=2,
theta=np.pi / 180,
threshold=50,
lines=np.array([]),
minLineLength=40,
maxLineGap=100)
image_with_lines = draw_lines(image, lines)
return image_with_lines
def main():
cap = cv2.VideoCapture(0)
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
frame = process(frame)
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
main()

21
平方数.py Normal file
View File

@ -0,0 +1,21 @@
list=[]
count=0
n=int(input())
for i in range(n):
list.append(int(input()))
for i in list:
num=i
result=0
for x in range(1,int((num/2)**0.5)+1):
if num-x**2==(int((num-x**2)**0.5))**2:
print("Yes")
result=1
break
count += 1
print(count)
if result==0:
print("No")

20
开关灯.py Normal file
View File

@ -0,0 +1,20 @@
list=[0]
count=0
n=int(input())
for i in range(n):
list.append(0)
for i in range(2,n+1):
for j in range(i,n+1,i):
if j%i==0:
if list[j]==0:
list[j]=1
else:
list[j]=0
count+=1
print(count)
for i in range(1,n+1):
if list[i]==0:
print(i,end=" ")

18
循环.py Normal file
View File

@ -0,0 +1,18 @@
import turtle
import random
n=int(input())
turtle.speed(0)
turtle.pensize(10)
turtle.fillcolor("red")
turtle.begin_fill()
for j in range(18):
for i in range(n):
r = random.random()
g = random.random()
b = random.random()
turtle.pencolor(1, g, b)
turtle.forward(100)
turtle.right(360/n)
turtle.right(20)
turtle.end_fill()
turtle.done()

18
猜数字.py Normal file
View File

@ -0,0 +1,18 @@
import random
num=random.randint(1,100)
count=0
while 1:
input_num=int(input("请输入猜测的数字:"))
if input_num>num:
print("猜大了")
elif input_num<num:
print("猜小了")
else:
print("猜对了")
break
count+=1
if count>5:
print("猜了{}次,菜".format(count))
else:
print("猜了%d次,真厉害"%count)

49
美丽的雪花.py Normal file
View File

@ -0,0 +1,49 @@
import turtle
import random
# listx=[0]
# listy=[0]
#
# listcx = []
# listcy = []
#
# for p in range(25):
# listcx.append(0)
# listcy.append(0)
# listx.append(0)
# listy.append(0)
t=turtle.Turtle()
t.speed(0)
for i in range(40):
step = random.randint(20, 50)
r=random.random()
g=random.random()
b=random.random()
x = random.randint(-400, 400)
y = random.randint(-300, 300)
# is_xing=0
# while is_xing==0:
# is_xing=1
# x = random.randint(-400, 400)
# y = random.randint(-300, 300)
# for j in range(i-1):
# listcx[j] = abs(x - listx[j])
# listcy[j] = abs(y - listy[j])
# for k in range(i+1):
# if listcy[k] <= 200 or listcy[k] <= 200:
# is_xing = 0
# listx[i]=x
# listy[i]=y
t.penup()
t.goto(x,y)
t.pendown()
t.pencolor(r, g, b)
for a in range(6):
t.forward(step)
t.penup()
t.goto(x,y)
t.pendown()
t.right(60)

16
螺旋.py Normal file
View File

@ -0,0 +1,16 @@
import turtle
pen=turtle.Turtle()
pen.speed(0)
n=int(turtle.numinput("边数","请输入边数:"))
name=turtle.textinput("姓名","请输入姓名:")
colors=["red","green","blue","yellow","black"]
angle=360/n+1
for i in range(360):
pen.pencolor(colors[i%n])
pen.penup()
pen.forward(i*10)
pen.pendown()
pen.write(name,font=("华文行楷",int(i/50)))
pen.right(angle)
pen.pensize(i/20)