Commit 707b42fb by BellCodeEditor

auto save

parent ccd55b71
t=float(input('请输入体重(公斤):'))
s=float(input('请输入身高(米):'))
bmi=t/s**2
if bmi>=28:
print('肥胖')
elif bmi>=18.5 and bmi<=23.9:
print('正常')
elif bmi>=24.0 and bmi<=27.9:
print('过重')
elif bmi<=18.4:
print('偏瘦')
a=[90,99,67,98,89,30,77,59,61,88]
name=['a','b','c','d','e','f','g','h','i','j']
for i in a:
if i<60:
c=a.index(i)
b=name[c]
print(b,'的成绩为:',i)
\ No newline at end of file
while True:
a=float(input('请输入购买的苹果重量(斤):'))
if a<6:
a*=5
print('一共%.2f元。'%(a))
elif 10>=a>=6:
a*=(5*0.8)
print('一共%.2f元。'%(a))
elif a>10:
a*=(5*0.7)
print('一共%.2f元。'%(a))
\ No newline at end of file
a=['to','be','or','not','to','be','that','is','a','question']
s={}
for i in a:
b=a.count(i)
s[i]=b
print(s)
\ No newline at end of file
a=int(input('请输入一个大于一的自然数:'))
s=0
while a!=1:
if a%2==0:
s+=1
a/=2
elif a%2!=0:
s+=1
a*=3
a+=1
print(s)
\ No newline at end of file
a='白日依山尽'
b='黄河入海流'
c='欲穷千里目'
d='更上一层楼'
print('%s,%s,%s,%s。'%(a,b,c,d))
\ No newline at end of file
import random
num=random.randint(1,100)
while True:
a=int(input('请输入要猜的数字(1-100):'))
if a==num:
print('恭喜你,猜对了。')
exit()
elif a>num:
print('猜大了')
else:
print('猜小了')
\ No newline at end of file
for j in range(1,10):
for i in range(1,j+1):
print("%d*%d=%d"%(i,j,i*j),end='\t')
print(' ')
\ No newline at end of file
yhm='xiaoming'
mima=1234
while True:
b=input('用户名:')
c=int(input('密码:'))
if b==yhm and c==mima:
print('登录成功')
break
else:
print('登录失败,请重新输入')
\ No newline at end of file
j=0
for i in range(1,101):
if i%2==0:
continue
j+=i
print(j)
\ No newline at end of file
score=[59,90,80,100,70,20,50,88,87,66]
s=0
for i in score:
if i<60:
s+=1
print(s)
\ No newline at end of file
score=[]
for i in range(10):
a=int(input('请输入成绩:'))
score.append(a)
print('班级成绩为:',score)
a=sum(score)/10
print('班级平均分为:',int(a))
\ No newline at end of file
a=input('请输入一段字符串:')
s=''
for i in a:
if 'a' in i:
continue
s+=i
print(s)
\ No newline at end of file
month=['January','February','March','April','May','June','July','August','September','October','November','December']
a=int(input('请输入月份:'))
while True:
if a<13 and a>0:
break
a=int(input('请重新输入:'))
a-=1
print(month[a])
\ No newline at end of file
import pygame import pygame
import random
import json
from pygame import locals from pygame import locals
pygame.init() # 初始化 pygame.init() # 初始化
# 创建一个窗口 pygame.mixer_music.load('纯音乐 - level! (Inst_).mp3')
pygame.mixer_music.play()
class Block(pygame.sprite.Sprite):
def __init__(self,image1,image2,image3):
super().__init__()
self.image=random.choice([image1,image2,image3])
self.rect=self.image.get_rect()
self.rect.x=1000
self.rect.y=500-self.rect.height
self.score=1
class Player(pygame.sprite.Sprite):
def __init__(self,image):
super().__init__()
self.image=image
self.rect=self.image.get_rect()
self.rect.x = 150
self.rect.y = 400
# 创建一个窗口
pygame.display.set_caption('悟空酷跑')
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 载入图片 # 载入图片
...@@ -9,27 +29,122 @@ background = pygame.image.load('bg.png') # 背景 ...@@ -9,27 +29,122 @@ background = pygame.image.load('bg.png') # 背景
road = pygame.image.load('road.png') # 路 road = pygame.image.load('road.png') # 路
stone = pygame.image.load('stone.png') # 石头 stone = pygame.image.load('stone.png') # 石头
cacti = pygame.image.load('cacti.png') # 仙人掌 cacti = pygame.image.load('cacti.png') # 仙人掌
apple = pygame.image.load('bush.png') # 灌木丛 bush = pygame.image.load('bush.png') # 灌木丛
hero = [pygame.image.load('hero1.png'), hero = [pygame.image.load('hero1.png'),
pygame.image.load('hero2.png'), pygame.image.load('hero2.png'),
pygame.image.load('hero3.png'), pygame.image.load('hero3.png'),
pygame.image.load('hero4.png'), pygame.image.load('hero4.png'),
pygame.image.load('hero5.png')] pygame.image.load('hero5.png')]
ziti=pygame.font.Font('STKAITI.TTF',18)
index = 0 index = 0
ob=Block(bush,stone,cacti)
y=400
jumpstate='running'
t=30
wk=hero[index]
road_x=0
bg_x=0
time=0
gamestate=True
score=0
speed=8
old_score=0
yinyue=pygame.mixer.Sound('score.wav')
block_list=pygame.sprite.Group()
with open('score.txt','r',encoding='utf-8') as f:
content=f.read()
record=json.loads(content)
one=record['第1名']
two=record['第2名']
three=record['第3名']
while True: while True:
wk=hero[index]
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
if event.type ==locals.KEYDOWN:
if jumpstate=='running':
if event.key==locals.K_SPACE:
jumpstate='up'
speed=8+score//3
if gamestate==True:
wk=Player(hero[index])
if jumpstate=='running':
index+=1 index+=1
if index>4: if index>4:
index=0 index=0
if jumpstate=='up':
if t>0:
y-=t
wk.rect.y=y
t-=1.5
else:
jumpstate='down'
if jumpstate=='down':
if t<=30:
y+=t
wk.rect.y=y
t+=1.5# 1.5
else:
jumpstate='running'
t=30
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) bg_x-=1
screen.blit(road, (0, 500)) if bg_x<=-1000:
screen.blit(wk, (150, 400)) bg_x=0
screen.blit(background, (bg_x, 0))
road_x-=speed
if road_x<=-1000:
road_x=0
screen.blit(road, (road_x, 500))
screen.blit(wk.image, (150, wk.rect.y))
# if ob.rect.x <=0-ob.rect.width:
# ob=Block(bush,stone,cacti)
# ob.rect.x-=8
time+=1
if time>=60:
time=0
num=random.randint(0,50)
if num>20:
ob=Block(bush,stone,cacti)
block_list.add(ob)
for sprite in block_list:
sprite.rect.x-=speed
screen.blit(sprite.image,(sprite.rect.x,sprite.rect.y))
if sprite.rect.x <= 0-sprite.rect.width:
sprite.kill()
if pygame.sprite.collide_rect(wk,sprite):
gameover=pygame.image.load('gameover.png')
screen.blit(gameover,(400,200))
gamestate=False
if score>three:
if score>one:
record["第1名"]=score
record["第2名"]=one
record["第3名"]=two
elif score>two:
record["第2名"]=score
record["第3名"]=two
else:
record["第3名"]=score
record=json.dumps(record,ensure_ascii=False)
with open("score.txt","w",encoding='utf-8')as f:
f.write(record)
else:
if sprite.rect.x+sprite.rect.width<wk.rect.x:
score+=sprite.score
sprite.score=0
if score>old_score:
yinyue.play()
old_score=score
scoreSurf=ziti.render('分数:'+str(score),True,(255,255,255))
screen.blit(scoreSurf,(880,20))
scoreSurf=ziti.render('第1名'+str(one),True,(255,255,255))
screen.blit(scoreSurf,(880,50))
scoreSurf=ziti.render('第2名'+str(two),True,(255,255,255))
screen.blit(scoreSurf,(880,80))
scoreSurf=ziti.render('第3名'+str(three),True,(255,255,255))
screen.blit(scoreSurf,(880,110))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPS.tick(60) FPS.tick(60)
\ No newline at end of file
{"第1名": 0, "第2名": 0, "第3名": 0} {"第1名": 61, "第2名": 59, "第3名": 54}
\ No newline at end of file \ No newline at end of file
File added
'''while True:
'''while True:
a=eval(input('请输入长宽高(厘米):'))
b=sum(a)
if b>=60 and b<=203:
print('可以托运')
else:
print('不可以托运')'''
'''a=input('请输入一串中文:')
b=0
for i in a:
if i=='。' or i=='?' or i=='!':
b+=1
print('这段话中共有',b,'句话')'''
'''from turtle import *
pencolor('blue')
pensize(10)
fillcolor('red')
begin_fill()
for i in range(5):
forward(100)
right(144)
end_fill()
done()'''
'''from turtle import *
from math import *
fillcolor('red')
forward(100)
left(120)
for i in range(2):
forward(200)
left(120)
forward(100)
begin_fill()
circle(58)
end_fill()
left(90)
forward(sqrt(30000))
hideturtle()
done()
print(30000/175)
a=0
b=0
c=0
while True:
text=input('请输入考级科目(一级,二级,三级):')
if text=='一级':
a+=1
elif text=='二级':
b+=1
elif text=='三级':
c+=1
elif text=='结束了':
print('一号教室有',a,'人')
print('二号教室有',b,'人')
print('三号教室有',c,'人')
print('一共参加考试有',a+b+c,'人')
break
else:
print('本科目仅有一级,二级和三级')'''
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment