Commit 2e219d18 by BellCodeEditor

save project

parent 70035170
p=3.14
r=float(input("请输入一个大于0的半径"))
a=2*r
b=a*p
c=p*r*r
print("圆的直径是:%.2f"%a)
print("圆的周长是:%.2f"%b)
print("圆的面积是:%.2f"%c)
\ No newline at end of file
x=int(input())
a=x//100
c=x%10
b=(x-a*100)//10
print("百:",a,"十:",b,"个:",c)
\ No newline at end of file
a=int(input())
b=a//3600
c=(a-b*3600)//60
d=a-b*3600-c*60
print(b,c,d)
x=int(input())
a=x//100
c=x%10
b=(x-a*100)//10
print("百:",a,"十:",b,"个:",c)
\ No newline at end of file
import pygame import pygame
from pygame import locals from pygame import locals
import random
pygame.init() # 初始化 pygame.init() # 初始化
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.sprite - 1
class Player(pygame.sprite.Sprite):
def __init__(self,image):
self.image = image
self.rect = self.image.get_rect()
self.rect.x = 150
self.rect.x = 400
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((1000, 600)) screen = pygame.display.set_mode((1000, 600))
FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPS = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
pygame.display.set_caption("悟空酷跑")
# 载入图片 # 载入图片
background = pygame.image.load('bg.png') # 背景 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'), 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')]
index = 0 index = 0
y = 400 y = 400
q = "runing" jumpState = "runing"
t = 30 t = 30
obst bg_x = 0
road_x = 0
bg_x = 0
time = 0
gamestate = True
# obstacle = Block(bush,cacti,stone)
block_list =pygame.sprite.Group()
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -29,32 +56,67 @@ while True: ...@@ -29,32 +56,67 @@ while True:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
if event.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
if q == "runing" if jumpState == "runing":
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
q = "up" jumpState = "up"
if q == "up":
if t > 0: wukong = Player(hero[index])
y -= t if jumpState == "runing": # 跑步状态下
t -= 2
else:
q = "down"
if q == "down":
if t <= 30:
y += t
t += 2
else:
q = "runing"
m = hero[index]
if q == "runing":
index += 1 index += 1
if index == 5: if index >= 5:
i ndex = 0 index = 0
# 将背景图画上去 if gamestate == True:
screen.blit(background, (0, 0)) if jumpState == "up": # 起跳状态
screen.blit(road, (0, 500)) if t > 0:
screen.blit(m, (150, 400)) y -= t
# 刷新画面 t -= 2
pygame.display.update() else:
FPS.tick(60) jumpState = "down"
\ No newline at end of file if jumpState == "down": # 降落状态
if t <= 30:
y += t
t += 2
else:
jumpState = "runing"
t =30
# 将背景图画上去
bg_x -= 1
if bg_x<=-1000:
bg_x = 0
screen.blit(background, (bg_x, 0))
road_x -= 8
if road_x<=-1000:
road_x = 0
screen.blit(road, (road_x, 500))
screen.blit(wukong.image,(150, y)) # 悟空
# 绘制障碍物
#if obstacle.rect.x <= 0-obstacle.rect.width:
# obstacle = Block(bush,cacti,stone)
#obstacle.rect.x -= 8
#obstacle.draw()
# +++++++++++++++++++++++++++++++++++++++
# 创建障碍物对象
time += 1
if time >= 60:
time = 0
r = random.randint(0, 50)
if r > 20:
obstacle = Block(bush,cacti,stone)
block_list.add(obstacle)
for sprite in block_list:
sprite.rect.x -= 8
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(wukong, sprite):
gameover = pygame.image.load('gameover.png')
screen.blit(gameover,(400,200))
gamestate = False
# print(len(block_list))
# 刷新画面
pygame.display.update()
FPS.tick(60)
\ No newline at end of file
import turtle
turtle.penup()
turtle.goto(-100,100)
turtle.pendown()
turtle.forward(200)
turtle.right(90)
turtle.forward(200)
turtle.right(90)
turtle.forward(200)
turtle.right(90)
turtle.forward(200)
turtle.right(90)
turtle.penup()
turtle.goto(0,-50)
turtle.pendown()
turtle.fillcolor('blue')
turtle.begin_fill()
turtle.circle(50)
turtle.speed(50)
turtle.end_fill()
turtle.done()
\ No newline at end of file
import turtle
import turtle
turtle.pencolor("red")
turtle.pensize(2)
turtle.forward(-100)
turtle.forward(200)
turtle.left(90)
turtle.circle(100,450)
turtle.left(90)
turtle.forward(200)
#turtle.hideturtle()
turtle.done()
\ No newline at end of file
N = input("请输入奶牛的头数")
N = input("请输入奶牛的头数")
N = int(N)
m = N*20*7
print(N,"头奶牛7天可以产",m,"千克的牛奶")
\ No newline at end of file
import turtle
import turtle
turtle.penup()
turtle.goto(0,-200)
turtle.pendown()
turtle.circle(200)
turtle.penup()
turtle.goto(-100,50)
turtle.pendown()
turtle.fillcolor('blue')
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(100,50)
turtle.pendown()
turtle.fillcolor('blue')
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(0,50)
turtle.pendown()
turtle.circle(-50,steps=3)
turtle.penup()
turtle.goto(-150,-70)
turtle.pendown()
turtle.goto(0.-170)
turtle.goto(150,-70)
turtle.done()
\ No newline at end of file
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