Commit 383f33d9 by BellCodeEditor

auto save

parent c6188a1e
# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本'
# 打开、创建文件,这里的路径要换成自己哦~
file1= open(r'C:\Users\CM\Desktop\book.txt','w',encoding='utf-8')
# 写入数据
file1.write('小兰:12本\n')
file1.write('小丽:11本\n')
file1.write('李文:9本\n')
file1.write('张伟:16本\n')
# 关闭文件
file1.close()
\ No newline at end of file
# 补充捐赠明细,两种写法:
# 补充数据的第一种写法:
file= open(r'C:\Users\CM\Desktop\book.txt','a',encoding='utf-8')
file.write('小强:10本\n')
file.write('李明:15本\n')
file.close()
# 补充数据的第二种写法:
with open(r'C:\Users\CM\Desktop\book.txt','a',encoding='utf-8') as file:
file.write('小强:10本\n')
file.write('李明:15本\n')
\ No newline at end of file
# 完成修改数据前的遍历和条件判断,找下'小强:10本'在不在数据中,以及小兰的数据'小兰:12本'在不在
with open(r'C:\Users\CM\Desktop\book.txt','r',encoding='utf-8') as file1:
for data in file1:
if '小强:10本' in data:
print('小强数据在文件中')
if '小兰:12本'in data:
print('小兰数据在文件中')
\ No newline at end of file
# 修改小强的数据为11本,以及小兰的数据'小兰:12本'修改为14本,最后读取修改后的数据
new_data=''
with open(r'C:\Users\CM\Desktop\book.txt','r',encoding='utf-8') as file1:
for data in file1:
if '小强:10本'in data:
data=data.replace('小强:10本','小强:11本')
if '小兰:12本'in data:
data=data.replace('小兰:12本','小兰:14本')
new_data +=data
with open(r'C:\Users\CM\Desktop\book.txt','w',encoding='utf-8') as file1:
file1.write(new_data)
with open(r'C:\Users\CM\Desktop\book.txt','r',encoding='utf-8') as file1:
a=file1.read()
print(a)
import pygame
from pygame import locals
pygame.init()
screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock()
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
x, y = 240, 120
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
exit()
x += 30
screen.blit(background, (0, 0))
screen.blit(right, (x, y)) #
screen.blit(body, (210, 120))
screen.blit(body, (180, 120))
screen.blit(body, (180, 90))
screen.blit(food, (360, 300))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(3)
\ No newline at end of file
import pygame
from pygame import locals
# 初始化pygame,为使用硬件做准备
pygame.init()
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 背景
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
x, y = 240, 120
position = [(180, 90), (180, 120), (210, 120), (x, y)]
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
x += 30 #
position.append((x, y))
position.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去
screen.blit(right, position[-1]) #
# 将贪吃蛇的身体画上去
for i in range(len(position)-1):
screen.blit(body, position[i])
# 将果实画上去
screen.blit(food, (360, 300))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(3)
\ No newline at end of file
import pygame
from pygame import locals
# 初始化pygame,为使用硬件做准备
pygame.init()
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 背景
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png') # 头 朝右
food = pygame.image.load('apple.png') # 食物 苹果
body = pygame.image.load('body.png')
left = pygame.image.load('left.png')
up = pygame.image.load('up.png')
down = pygame.image.load('down.png')
x, y = 240, 120
position = [(180, 90), (180, 120), (210, 120), (x, y)]
setheading = "right"
snake_head = right
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
elif event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and setheading != "left":
setheading = 'right'
snake_head = right
if event.key == locals.K_LEFT and setheading != "right":
setheading = 'left'
snake_head = left
if event.key == locals.K_UP and setheading != "down":
setheading = 'up'
snake_head = up
if event.key == locals.K_DOWN and setheading != "up":
setheading = 'down'
snake_head = down
# 设置贪吃蛇的头部坐标
if setheading == "right":
x += 30
elif setheading == "left":
x -= 30
elif setheading == "up":
y -= 30
else:
y += 30
position.append((x, y))
position.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去
screen.blit(snake_head, position[-1])
# 将贪吃蛇的身体画上去
for i in range(len(position)-1):
screen.blit(body, position[i])
# 将果实画上去
screen.blit(food, (360, 300))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(3)
\ No newline at end of file
# a_b = "Python"
# print(a_b)
# c = input("请输入你的名字:")
# print(c)
# a = 3
# print(a ** 2)
# a = "python"
# d = a[0:3]
# print(d)
# a = [1, 0.5, "Python"]
# # print(a[0:2])
# a.append("Scratch")
# print(a)
# a.pop()
# print(a)
# a = [1, 2]
# b = (1, 2)
# a[0] = 0
# b[0] = 0
# a = {"小明" : 90, "小红" : 80, "小黄" : 70}
# # print(a["小明"])
# a["小明"] = 100
# print(a)
# b = "error"
# a = True
# print(a)
# c = "1"
# print(c == 1)
# a = 90
# if a >= 60:
# print("成绩合格")
# else:
# print("成绩不合格")
# score = 90
# if score >= 85:
# print("成绩优秀")
# elif score >= 60:
# print("成绩合格")
# else:
# print("成绩不合格")
# i = 0
# while i < 5:
# i = i + 1
# print(i)
# a = "python"
# e = 0
# for i in a:
# print(i)
# a = ["Python", "Scratch", [1, 2]]
# for i in a:
# print(i)
a = {"小明" : "ss", "小红" : [80,90], "小黄" : 70}
# for i in a:
# print(i)
# print("石头")
# print(a[i])
# print(a["小明"])
# for i in range(0, 10):
# print(i)
def sum(x, y, z):
# print(x+y+z)
return x+y
a = sum(1, 2, 3)
def sum(x, y, z):
# print(x+y+z)
return x+y+z
b = sum(1, 2, 3)
print(a, b)
\ No newline at end of file
# print("1")
# a = input("请输出你的名字:")
# print("2")
# print(a)
# a = "Python"
# print(a[1])
# b = "语言"
# c = a+b
# print(c)
# b = 1
# c = "python"
# print(type(b))
# print(type(c))
# a = "1"
# print(type(a))
# a = [1, 0.5, "Python"]
# # print(a[0:2])
# # print(a[1])
# # print(a[2])
# # a[0] = 0
# # print(a[0])
# a.append("Scratch")
# # print(a[3])
# a.pop()
# print(a)
# d = ["石头", ["py", "src"]]
# e = ("石头", ["py", "src"])
# e[0] = 1
# a = {"小明" : 90, "小红" : 80, "小黄" : 70}
# print(a["小明"])
# b = {"小明" : "py", "小红" : ["s", "b"], "小黄" : 70}
# b["小明"] = "scr"
# print(b)
# a = True
# print(type(a))
# a = 1
# print(a == 1)
# print(a == "1")
# a = 1
# b = 2
# c = 3
# print((a < b) and (b < c))
# if True:
# print("yes")
# int()
# a = "90"
# print(type(a))
# b = int(a)
# print(type(b))
# score = int(input("请输入你的成绩:"))
# if score >= 85:
# print("成绩优秀")
# elif score >= 60:
# print("成绩合格")
# else:
# print("成绩不合格")
# i = 0
# while i < 5:
# i = i + 1
# print(i)
# if i == 3:
# break
# a = "Python"
# for i in a:
# print(i)
# b = ["python", "scratch"]
# for i in b:
# print(i)
a = {"小明" : 90, "小红" : 80, "小黄" : 70}
for i in a:
print(a[i])
import pygame
from pygame import locals
# 初始化pygame,为使用pygame做准备
pygame.init()
# 创建一个窗口
??
\ No newline at end of file
size = (660,480)
screen = pygame.display.set_mode(size)
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
exit()
screen.blit(background, (0,0))
screen.blit(right, (240,120))
screen.blit(body, (210,120))
screen.blit(body, (180,120))
screen.blit(body, (180,90))
screen.blit(food, (360, 300))
pygame.display.update()
\ 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