Compare commits
No commits in common. "master" and "1.0" have entirely different histories.
|
@ -0,0 +1 @@
|
|||
print(sum(list(range(1,101,2))))
|
5
test.py
5
test.py
|
@ -1,3 +1,2 @@
|
|||
import turtle
|
||||
turtle.circle(500,steps=100)
|
||||
turtle.done()
|
||||
|
||||
print(bool(1) and str(bool(0)) or bool(int(2/3)))
|
21
哥德巴赫猜想.py
21
哥德巴赫猜想.py
|
@ -1,21 +0,0 @@
|
|||
def is_zhi(n):
|
||||
if n==1:
|
||||
return 0
|
||||
if n==2:
|
||||
return 1
|
||||
is_zhi=1
|
||||
|
||||
for i in range(2,n):
|
||||
if n%i==0:
|
||||
is_zhi=0
|
||||
return is_zhi
|
||||
|
||||
def gede(n1,n2):
|
||||
if is_zhi(n1) and is_zhi(n2):
|
||||
print(n1, n2)
|
||||
return n1
|
||||
gede(n1-1,n2+1)
|
||||
#print(n1,n2,is_zhi(n1) , is_zhi(n2))
|
||||
|
||||
n=int(input())
|
||||
gede(n-1,1)
|
22
哥德巴赫高效.py
22
哥德巴赫高效.py
|
@ -1,22 +0,0 @@
|
|||
def sieve_of_eratosthenes(n):
|
||||
primes = [True] * (n + 1) # 创建一个布尔列表,初始时所有元素设为True
|
||||
p = 2
|
||||
while p * p <= n:
|
||||
# 如果 primes[p] 未被标记为 False, 则是一个质数
|
||||
if primes[p]:
|
||||
# 更新所有 p 的倍数,从 p*p 开始标记为 False
|
||||
for i in range(p * p, n + 1, p):
|
||||
primes[i] = False
|
||||
p += 1
|
||||
|
||||
# 收集所有质数
|
||||
prime_numbers = [p for p in range(2, n + 1) if primes[p]]
|
||||
return prime_numbers
|
||||
|
||||
|
||||
n=int(input())
|
||||
numbers=sieve_of_eratosthenes(n)
|
||||
for i in numbers:
|
||||
if n-i in numbers:
|
||||
print(i,n-i)
|
||||
break
|
17
斐波那契数列.py
17
斐波那契数列.py
|
@ -1,17 +0,0 @@
|
|||
# 1 1 2 3 5 8 13
|
||||
def feibo(n):
|
||||
if n==1 or n==2:
|
||||
return 1
|
||||
if list[n]!=0:
|
||||
return list[n]
|
||||
else:
|
||||
a=(feibo(n-1)+feibo(n-2))%(1000000007)
|
||||
list[n]=a
|
||||
return a
|
||||
|
||||
n=int(input())
|
||||
|
||||
list=[0]*(n+1)
|
||||
|
||||
b=feibo(n)
|
||||
print(b)
|
12
斐波那契数列正向.py
12
斐波那契数列正向.py
|
@ -1,12 +0,0 @@
|
|||
n=int(input())
|
||||
one_num=1
|
||||
two_num=1
|
||||
for i in range(3,n+1):
|
||||
new_num=one_num+two_num
|
||||
two_num=one_num
|
||||
if new_num>1000000007:
|
||||
one_num=new_num%(1000000007)
|
||||
else:
|
||||
one_num = new_num
|
||||
|
||||
print(one_num)
|
167
机器猫的选择.py
167
机器猫的选择.py
|
@ -1,167 +0,0 @@
|
|||
import turtle
|
||||
t = turtle.Turtle()
|
||||
t.speed(0)
|
||||
# 画头
|
||||
t.color('blue','blue')
|
||||
t.penup()
|
||||
# t.goto(0,100)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(75)
|
||||
t.end_fill()
|
||||
|
||||
# 画脸
|
||||
t.color('white','white')
|
||||
t.penup()
|
||||
# t.goto(0,72)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(60)
|
||||
t.end_fill()
|
||||
#画左眼框
|
||||
t.color('black','white')
|
||||
t.penup()
|
||||
t.goto(-15,100)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(17)
|
||||
# t.fillcolor('white')
|
||||
t.end_fill()
|
||||
|
||||
# 画右眼眶
|
||||
t.color('black','white')
|
||||
t.penup()
|
||||
t.goto(20,100)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(17)
|
||||
# t.fillcolor('white')
|
||||
t.end_fill()
|
||||
|
||||
|
||||
# 画左眼珠
|
||||
t.color('black')
|
||||
t.penup()
|
||||
#t.goto(-8,110)
|
||||
t.goto(-13,115)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(7)
|
||||
t.fillcolor('black')
|
||||
t.end_fill()
|
||||
t.penup()
|
||||
#t.goto(-7,115)
|
||||
t.goto(-12,120)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(3)
|
||||
t.fillcolor('white')
|
||||
t.end_fill()
|
||||
|
||||
#笑眯眯
|
||||
# t.penup()
|
||||
# t.goto(-8,110)
|
||||
# t.pendown()
|
||||
# t.setheading(90)
|
||||
# t.circle(7,180)
|
||||
|
||||
# 画右眼珠
|
||||
t.color('black')
|
||||
t.penup()
|
||||
#t.goto(13,110)
|
||||
t.goto(18,105)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(7)
|
||||
t.fillcolor('black')
|
||||
t.end_fill()
|
||||
t.penup()
|
||||
#t.goto(12,115)
|
||||
t.goto(17,110)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(3)
|
||||
t.fillcolor('white')
|
||||
t.end_fill()
|
||||
|
||||
#笑眯眯
|
||||
# t.penup()
|
||||
# t.goto(25,110)
|
||||
# t.pendown()
|
||||
# t.setheading(90)
|
||||
# t.circle(7,180)
|
||||
|
||||
#画鼻子
|
||||
t.color('red','red')
|
||||
t.penup()
|
||||
t.goto(2,75)
|
||||
#t.goto(-8,85)#笑眯眯
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(10)
|
||||
# t.fillcolor('red')
|
||||
t.end_fill()
|
||||
|
||||
# 画嘴巴
|
||||
t.color('black')
|
||||
t.penup()
|
||||
t.goto(-35,60)
|
||||
t.pendown()
|
||||
t.setheading(-85) #设置小海龟启动时的运动方向
|
||||
t.circle(35,170) #绘制一条弧线,表示机器猫的嘴巴
|
||||
# # 画竖线
|
||||
t.color('black')
|
||||
t.penup()
|
||||
t.goto(2,30) #将画笔移动到坐标(2,30)的位置
|
||||
t.pendown()
|
||||
t.goto(2,75) #绘制一条直线,表示机器猫的‘人中’
|
||||
|
||||
|
||||
# 画胡子
|
||||
# 左边第一根胡子
|
||||
t.penup()
|
||||
t.goto(-20,70)
|
||||
t.pendown()
|
||||
t.goto(-45,80)
|
||||
|
||||
# 左边第二根胡子
|
||||
t.penup()
|
||||
t.goto(-20,60)
|
||||
t.pendown()
|
||||
t.goto(-47,60)
|
||||
|
||||
# 左边第三根胡子
|
||||
t.penup()
|
||||
t.goto(-20,50)
|
||||
t.pendown()
|
||||
t.goto(-47,40)
|
||||
|
||||
# 右边第三根胡子
|
||||
t.penup()
|
||||
t.goto(20,50)
|
||||
t.pendown()
|
||||
t.goto(47,40)
|
||||
|
||||
|
||||
# 右边第二根胡子
|
||||
t.penup()
|
||||
t.goto(20,60)
|
||||
t.pendown()
|
||||
t.goto(47,60)
|
||||
|
||||
|
||||
# 右边第一根胡子
|
||||
t.penup()
|
||||
t.goto(20,70)
|
||||
t.pendown()
|
||||
t.goto(45,80)
|
||||
|
||||
|
||||
# 隐藏画笔
|
||||
t.hideturtle()
|
||||
|
||||
turtle.done()
|
||||
|
||||
|
||||
|
||||
|
9
汉诺塔.py
9
汉诺塔.py
|
@ -1,9 +0,0 @@
|
|||
def han(start,end,temp,n):
|
||||
if n==1:
|
||||
return 0;
|
||||
else:
|
||||
han(start, temp, end, n - 1)
|
||||
print(n, start, "---->", end)
|
||||
han(temp, start, end, n - 1)
|
||||
|
||||
han("A","B","C",5)
|
92
游戏.py
92
游戏.py
|
@ -1,92 +0,0 @@
|
|||
import sys
|
||||
import pygame as py
|
||||
import time
|
||||
|
||||
#初始化
|
||||
py.init()
|
||||
py.display.init()
|
||||
|
||||
#创建屏幕
|
||||
a=py.display.set_mode((400,320))
|
||||
running = True
|
||||
#设置小球x、y坐标
|
||||
ball_x = 200
|
||||
ball_y = 240
|
||||
#设置小球x、y坐标速度
|
||||
ball_x_speed = 2
|
||||
ball_y_speed = -3
|
||||
# 显示小球
|
||||
ball = py.draw.circle(a, 'blue', (ball_x, ball_y), 10)
|
||||
#创建球拍
|
||||
qp = py.Rect(160,270,80,20)
|
||||
#设置分数
|
||||
poins = 0
|
||||
#砖块列表
|
||||
zk_list = []
|
||||
#把砖块添加砖块列表
|
||||
for j in range(3):
|
||||
for i in range(5):
|
||||
r = py.Rect(i*78+14,j*45+35,60,37)
|
||||
zk_list.append(r)
|
||||
while running:
|
||||
# a的背景设为(238,238,238)
|
||||
a.fill((238,238,238))
|
||||
#判断退出事件
|
||||
for e in py.event.get():
|
||||
if e.type == py.QUIT:
|
||||
running = False
|
||||
#球拍的移动
|
||||
keys = py.key.get_pressed()#py.key.get_pressed() : 所有按钮是否按下的逻辑值以序列的形式的变量
|
||||
if keys[py.K_LEFT] and qp.x > 0 :#py.K_LEFT : 左方向键
|
||||
qp.x -= 5
|
||||
if keys[py.K_RIGHT] and qp.x < 320 :#py.K_RIGHT : 右方向键
|
||||
qp.x += 5
|
||||
#球碰到边界的反弹
|
||||
if ball_x > 390 or ball_x < 10:
|
||||
ball_x_speed = - ball_x_speed
|
||||
if ball_y < 10:
|
||||
ball_y_speed = - ball_y_speed
|
||||
#球碰到球拍的反弹
|
||||
if ball.colliderect(qp):#判断球是否碰到球拍
|
||||
ball_y_speed = -ball_y_speed
|
||||
#球的移动
|
||||
ball_x = ball_x + ball_x_speed
|
||||
ball_y = ball_y + ball_y_speed
|
||||
#球打碎砖块
|
||||
for r in zk_list:
|
||||
if ball.colliderect(r):#判断球是否碰到砖块
|
||||
ball_y_speed = -ball_y_speed
|
||||
zk_list.remove(r)
|
||||
poins += 1
|
||||
# 球碰到下边界
|
||||
if ball_y > 310:
|
||||
# 终断循环
|
||||
running = False
|
||||
# 球打完了砖块
|
||||
if not zk_list :
|
||||
# 创建字体(完美)
|
||||
text = py.font.Font(None, 50).render('prefect!!', True, (0, 0, 0))
|
||||
# 显示字体(完美)
|
||||
a.blit(text, (150, 100))
|
||||
time.sleep(5)
|
||||
#终断循环
|
||||
running = False
|
||||
# 画出所有砖块
|
||||
for zk in zk_list:
|
||||
py.draw.rect(a, 'red', zk)
|
||||
# 显示球拍
|
||||
py.draw.rect(a, (0, 0, 0), rect=qp)
|
||||
# 显示小球
|
||||
ball = py.draw.circle(a, 'blue', (ball_x, ball_y), 10)
|
||||
# 创建字体(得分)
|
||||
text = py.font.Font(None, 30).render(f'poins:{poins}', True, (0, 0, 0))
|
||||
# 显示字体(得分)
|
||||
a.blit(text, (10, 10))
|
||||
#更新显示
|
||||
py.display.flip()
|
||||
# 把帧率设为100(一帧为每秒更新1篇画面)
|
||||
py.time.Clock().tick(50)
|
||||
#pygame初始化
|
||||
py.quit()
|
||||
#结束系统进程
|
||||
sys.exit()
|
316
绘制机器猫.py
316
绘制机器猫.py
|
@ -1,316 +0,0 @@
|
|||
import turtle
|
||||
t = turtle.Turtle()
|
||||
# 画头
|
||||
t.color('blue','blue')
|
||||
t.penup()
|
||||
# t.goto(0,100)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(75)
|
||||
t.end_fill()
|
||||
|
||||
# 画脸
|
||||
t.color('white','white')
|
||||
t.penup()
|
||||
# t.goto(0,72)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(60)
|
||||
t.end_fill()
|
||||
#画左眼框
|
||||
t.color('black','white')
|
||||
t.penup()
|
||||
t.goto(-15,100)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(17)
|
||||
# t.fillcolor('white')
|
||||
t.end_fill()
|
||||
|
||||
# 画右眼眶
|
||||
t.color('black','white')
|
||||
t.penup()
|
||||
t.goto(20,100)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(17)
|
||||
# t.fillcolor('white')
|
||||
t.end_fill()
|
||||
|
||||
|
||||
# 画左眼珠
|
||||
t.color('black')
|
||||
t.penup()
|
||||
t.goto(-8,110)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(7)
|
||||
t.fillcolor('black')
|
||||
t.end_fill()
|
||||
t.penup()
|
||||
t.goto(-7,115)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(3)
|
||||
t.fillcolor('white')
|
||||
t.end_fill()
|
||||
|
||||
# 画右眼珠
|
||||
t.color('black')
|
||||
t.penup()
|
||||
t.goto(13,110)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(7)
|
||||
t.fillcolor('black')
|
||||
t.end_fill()
|
||||
t.penup()
|
||||
t.goto(12,115)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(3)
|
||||
t.fillcolor('white')
|
||||
t.end_fill()
|
||||
|
||||
|
||||
#画鼻子
|
||||
t.color('red','red')
|
||||
t.penup()
|
||||
t.goto(2,75)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(10)
|
||||
# t.fillcolor('red')
|
||||
t.end_fill()
|
||||
|
||||
# 画嘴巴
|
||||
t.color('black')
|
||||
t.penup()
|
||||
t.goto(-25,35)
|
||||
t.pendown()
|
||||
t.setheading(-25) #设置小海龟启动时的运动方向
|
||||
t.circle(60,55) #绘制一条弧线,表示机器猫的嘴巴
|
||||
# # 画竖线
|
||||
t.color('black')
|
||||
t.penup()
|
||||
t.goto(2,30) #将画笔移动到坐标(2,30)的位置
|
||||
t.pendown()
|
||||
t.goto(2,75) #绘制一条直线,表示机器猫的‘人中’
|
||||
|
||||
|
||||
# 画胡子
|
||||
# 左边第一根胡子
|
||||
t.penup()
|
||||
t.goto(-20,70)
|
||||
t.pendown()
|
||||
t.goto(-45,80)
|
||||
|
||||
# 左边第二根胡子
|
||||
t.penup()
|
||||
t.goto(-20,60)
|
||||
t.pendown()
|
||||
t.goto(-47,60)
|
||||
|
||||
# 左边第三根胡子
|
||||
t.penup()
|
||||
t.goto(-20,50)
|
||||
t.pendown()
|
||||
t.goto(-47,40)
|
||||
|
||||
# 右边第三根胡子
|
||||
t.penup()
|
||||
t.goto(20,50)
|
||||
t.pendown()
|
||||
t.goto(47,40)
|
||||
|
||||
|
||||
# 右边第二根胡子
|
||||
t.penup()
|
||||
t.goto(20,60)
|
||||
t.pendown()
|
||||
t.goto(47,60)
|
||||
|
||||
|
||||
# 右边第一根胡子
|
||||
t.penup()
|
||||
t.goto(20,70)
|
||||
t.pendown()
|
||||
t.goto(45,80)
|
||||
|
||||
|
||||
# 绘制身体
|
||||
# 1.绘制蓝色的身体
|
||||
t.color('blue','blue')
|
||||
t.penup()
|
||||
t.goto(-55,0)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
# t.fillcolor('blue')
|
||||
t.right(120)
|
||||
t.goto(-55,-100)
|
||||
t.left(90)
|
||||
t.goto(55,-100)
|
||||
t.left(90)
|
||||
t.goto(55,0)
|
||||
t.end_fill()
|
||||
|
||||
# 2.白色的大肚子
|
||||
t.color('white','white')
|
||||
t.penup()
|
||||
t.goto(40,-45)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(40)
|
||||
# t.fillcolor('white')
|
||||
t.end_fill()
|
||||
#
|
||||
#3.红色的丝带
|
||||
t.color('red','red')
|
||||
t.penup()
|
||||
t.goto(-70,5)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
# t.fillcolor('red')
|
||||
t.right(120)
|
||||
t.goto(-70,-5)
|
||||
t.left(90)
|
||||
t.goto(70,-5)
|
||||
t.left(90)
|
||||
t.goto(70,5)
|
||||
t.end_fill()
|
||||
|
||||
# 4.白色的腿
|
||||
t.color('white','white')
|
||||
t.penup()
|
||||
t.goto(14,-100)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.setheading(90)
|
||||
# t.fillcolor('white')
|
||||
t.circle(14,180)
|
||||
t.end_fill()
|
||||
|
||||
|
||||
# 机器猫的脚
|
||||
# 1.左脚
|
||||
t.color('black','white')
|
||||
t.penup()
|
||||
t.goto(-14,-110)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.setheading(90)
|
||||
# t.fillcolor('white')
|
||||
t.circle(20)
|
||||
t.end_fill()
|
||||
|
||||
|
||||
# 2.右脚
|
||||
t.color('black','white')
|
||||
t.penup()
|
||||
t.goto(55,-110)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
# t.fillcolor('white')
|
||||
t.circle(20)
|
||||
t.end_fill()
|
||||
|
||||
|
||||
# 绘制机器猫的胳膊
|
||||
# 左胳膊
|
||||
t.color('blue','blue')
|
||||
t.penup()
|
||||
t.goto(-55,-5)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.goto(-90,-50)
|
||||
t.right(90)
|
||||
t.goto(-70,-60)
|
||||
t.right(90)
|
||||
t.goto(-55,-30)
|
||||
t.end_fill()
|
||||
|
||||
# 右胳膊
|
||||
t.color('blue','blue')
|
||||
t.penup()
|
||||
t.goto(55,-5)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.goto(90,-50)
|
||||
t.right(90)
|
||||
t.goto(70,-60)
|
||||
t.right(90)
|
||||
t.goto(55,-30)
|
||||
t.end_fill()
|
||||
|
||||
# 绘制机器猫的手
|
||||
# 1.左手
|
||||
t.color('black','white')
|
||||
t.penup()
|
||||
t.goto(-70,-60)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
# t.setheading(90)
|
||||
t.circle(15)
|
||||
t.end_fill()
|
||||
|
||||
# 2.右手
|
||||
t.color('black','white')
|
||||
t.penup()
|
||||
t.goto(100,-65)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
t.circle(15)
|
||||
t.end_fill()
|
||||
|
||||
|
||||
# 绘制铃铛
|
||||
# 1.黄色实心圆表示铜陵
|
||||
t.color('yellow','yellow')
|
||||
t.penup()
|
||||
t.goto(10,-5)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
# t.fillcolor('yellow')
|
||||
t.circle(10)
|
||||
t.end_fill()
|
||||
|
||||
# 2.黑色矩形表示花纹
|
||||
t.color('black','black')
|
||||
t.penup()
|
||||
t.goto(-10,0)
|
||||
t.pendown()
|
||||
t.left(90)
|
||||
t.goto(-10,-5)
|
||||
t.right(90)
|
||||
t.goto(10,-5)
|
||||
t.right(90)
|
||||
t.goto(10,0)
|
||||
t.right(90)
|
||||
t.goto(-10,0)
|
||||
|
||||
|
||||
# 3.黑色实心圆表示撞击的金属丸
|
||||
t.color('black','black')
|
||||
t.penup()
|
||||
t.goto(-5,-10)
|
||||
t.pendown()
|
||||
t.begin_fill()
|
||||
# t.fillcolor('black')
|
||||
t.circle(5)
|
||||
t.end_fill()
|
||||
|
||||
|
||||
# #绘制口袋
|
||||
t.penup()
|
||||
t.goto(-26,-40)
|
||||
t.pendown()
|
||||
t.setheading(-90)
|
||||
t.circle(25,180)
|
||||
t.goto(-26,-40)
|
||||
|
||||
|
||||
# 隐藏画笔
|
||||
t.hideturtle()
|
||||
turtle.done()
|
||||
|
||||
|
21
质数筛.py
21
质数筛.py
|
@ -1,21 +0,0 @@
|
|||
def sieve_of_eratosthenes(n):
|
||||
primes = [True] * (n + 1) # 创建一个布尔列表,初始时所有元素设为True
|
||||
p = 2
|
||||
while p * p <= n:
|
||||
# 如果 primes[p] 未被标记为 False, 则是一个质数
|
||||
if primes[p]:
|
||||
# 更新所有 p 的倍数,从 p*p 开始标记为 False
|
||||
for i in range(p * p, n + 1, p):
|
||||
primes[i] = False
|
||||
p+=1
|
||||
while primes[p]==0:
|
||||
p+=1
|
||||
|
||||
# 收集所有质数
|
||||
prime_numbers = [p for p in range(2, n + 1) if primes[p]]
|
||||
return prime_numbers
|
||||
|
||||
|
||||
# 测试算法
|
||||
n = 10000
|
||||
print(f"小于等于 {n} 的所有质数: {sieve_of_eratosthenes(n)}")
|
Loading…
Reference in New Issue