用户:
蒟蒻OIer1048576查看:17 回复:7 评论:17 创建时间:2020-07-02T07:47:47
———————————————————————————防喵—————————————————————————————
理论题(50分)
难度:
只要会if for while else elif def 递归 list dict tuple set 基本排序算法 面向对象
就行!
实操题(50分)
交出你最得意作品的源代码~!!
from tkinter import *
import tkinter.filedialog as f
import tkinter.colorchooser as c
import tkinter.messagebox as m
import tkinter.simpledialog as s
import sys
import os
import time
import calendar
str9=time.localtime(time.time())
str5=str(time.ctime())
root = Tk()
root.title('记事本')
root.width=400
root.weight=400
menubar = Menu(root)
text1=Text(root)
text1.pack(fill=BOTH,expand=True)
def ac():
a7 = s.askinteger(title='年份询问',prompt='请输入日历的年份:', initialvalue=str9.tm_year)
a8 = s.askinteger(title='月份询问',prompt='请输入日历的月份:', initialvalue=str9.tm_mon)
cal = calendar.month(a7,a8)
text1.insert(0.0,cal)
def at():
text1.insert(0.0,str5)
def DN():
text1.insert(0.0,os.getcwd())
def New():
text1.delete('1.0',END)
def save():
str1=text1.get(1.0,END)
rs=f.asksaveasfilename(title='保存',filetype=[('python源文件','.py'),('文本','txt')])
ff=open(rs,'w',encoding='utf-8')
ff.write(str1)
ff.close()
def window():
text1.delete('1.0',END)
rs=f.askopenfilename(title='打开',filetype=[('python源文件','.py'),('文本','txt')])
try:
ff=open(rs,'r',encoding='utf-8')
str1=ff.read()
text1.insert(0.0,str1)
except:
pass
finally:
ff.close()
def Quit():
quit()
sys.exit()
def textcolor():
r1,r2=c.askcolor(title='字体颜色',color='red')
text1.config(fg=r2)
def BGcolor():
r1,r2=c.askcolor(title='页面颜色',color='red')
text1.config(bg=r2)
def texthelp():
m.showinfo(title='关于',message='这是一个关于记录时间的程序!')
def about():
r3=s.askstring(title='帮助',prompt='具体请见官方文档!其余,请问您有什么问题吗?')
def change():
str1=text1.get(1.0,END)
r4=s.askstring(title='被替换',prompt='请输入要替换的字符:')
r5=s.askstring(title='替换项',prompt='请输入要把他替换的项:')
str2=''
for x in str1:
if str(r4) == x:
str2 += str(r5)
else:
str2 += x
text1.delete('1.0',END)
text1.insert(0.0,str2)
filemenu=Menu(menubar,tearoff=False)
filemenu.a喵_command(label='新建',command=New)
filemenu.a喵_command(label='打开',command=window)
filemenu.a喵_separator()
filemenu.a喵_command(label='保存',command=save)
filemenu.a喵_command(label='退出',command=Quit)
menubar.a喵_cascade(label='文件',menu=filemenu)
root.config(menu=menubar)
Runmenu=Menu(menubar,tearoff=False)
Runmenu.a喵_command(label='字体颜色',command=textcolor)
Runmenu.a喵_separator()
Runmenu.a喵_command(label='页面颜色',command=BGcolor)
menubar.a喵_cascade(label='个性化',menu=Runmenu)
root.config(menu=menubar)
Windowmenu=Menu(menubar,tearoff=False)
Windowmenu.a喵_command(label='帮助',command=about)
Windowmenu.a喵_command(label='关于',command=texthelp)
menubar.a喵_cascade(label='关于',menu=Windowmenu)
root.config(menu=menubar)
Change=Menu(menubar,tearoff=False)
Change.a喵_command(label='替换',command=change)
menubar.a喵_cascade(label='替换',menu=Change)
root.config(menu=menubar)
Time=Menu(menubar,tearoff=False)
Time.a喵_command(label='时间',command=at)
Time.a喵_command(label='日历',command=ac)
menubar.a喵_cascade(label='添加',menu=Time)
root.config(menu=menubar)
mainloop()
点赞0
评论
Chengxuyee_已退import pgzrun
import random
import math
WIDTH = 450
HEIGHT = 570
score = 0
game_state = 'start'
speed = 6
shoot = False
t = 0
attack = False
life = 3
spaceship = Actor('spaceship',(200, 500))
diamond = Actor('diamond', (100, -200))
enermy = Actor('enermy', (300, -200))
spaceship_bullet = Actor('bullet1', (200, -100))
enermy_bullet = Actor('bullet2', (200, -100))
heart = Actor('heart', (300, -5000))
def draw():
global game_state, shoot, score, life
if game_state == 'start':
screen.blit('space', (-20, 0))
screen.draw.text('Spacecraft', (115, 260), fontsize=60)
screen.draw.text('Press SPACE to start!',
(85, 320), fontsize=40)
if keyboard.space:
game_state = 'play'
elif game_state == 'play':
screen.blit('space',(0, 0))
screen.draw.text('score:' + str(score),
(10, 10), fontsize=30)
screen.draw.text('life:' + str(life),
(370, 10), fontsize=30)
spaceship.draw()
diamond.draw()
enermy.draw()
spaceship_bullet.draw()
enermy_bullet.draw()
heart.draw()
else:
screen.blit('space', (0, 0))
spaceship.draw()
screen.draw.text('Game Over!', (90, 230),
color='red', fontsize=60)
screen.draw.text('Your score:' + str(score),
(125, 280), fontsize=40)
screen.draw.text('Press SPACE to restart!',
(70, 320), fontsize=40)
if keyboard.space:
game_state = 'play'
place_object(enermy)
place_object(diamond)
score = 0
Health = 0
life = 3
def place_object(obj):
obj.x = random.randint(20, WIDTH - 20)
obj.y = random.randint(-200, -40)
def update():
global score, game_state, shoot, t, attack, life
if game_state == 'play':
enermy.y += speed - 2
enermy.x = WIDTH / 2 * (1 + math.sin(1.2 * t))
t += 0.02
diamond.y += speed
heart.y += speed
if enermy.y > HEIGHT + 100:
place_object(enermy)
if diamond.y > HEIGHT + 100:
place_object(diamond)
if heart.y > HEIGHT + 100:
place_object(heart)
if keyboard.left:
spaceship.x -= 5
elif keyboard.right:
spaceship.x +=5
if spaceship.x < 0:
spaceship.x = 0
elif spaceship.x > WIDTH:
spaceship.x = WIDTH
if keyboard.a:
shoot = True
init_pos = spaceship.x, spaceship.y - 30
spaceship_bullet.pos = init_pos[0], init_pos[1]
if shoot:
if spaceship_bullet.y > -20:
spaceship_bullet.y -= 10
else:
shoot = False
spaceship_bullet.x = -160
if enermy.y > 0 and attack == False:
if enermy.x - spaceship.x < 20 and enermy.x - spaceship.x > -20:
enermy_bullet.pos = enermy.x, enermy.y + 20
attack = True
if attack:
if enermy_bullet.y < HEIGHT + 500:
enermy_bullet.y += speed + 2
else:
attack = False
if enermy.collidepoint(spaceship_bullet.pos):
place_object(enermy)
score += 10
if spaceship.collidepoint(diamond.pos):
place_object(diamond)
score += 10
spaceship_collide(enermy)
spaceship_collide(enermy_bullet)
if heart.y > HEIGHT + 100:
heart.x = random.randint(50, WIDTH - 50)
heart.y = random.randint(-10000, -5000)
if spaceship.collidepoint(heart.pos):
life += 1
heart.x = random.randint(50, WIDTH - 50)
heart.y = random.randint(-10000, -5000)
def spaceship_collide(obj):
global life, game_state
if spaceship.collidepoint(obj.pos):
place_object(obj)
life -= 1
if life == 0:
game_state = 'game over'
pgzrun.go()点赞0
评论
乐观的超能鸭E2Alimport turtle
import random
import time
__Pen = turtle.Pen()
_E6_83_85_E5_86_B5 = []
_E5_BE_97_E5_88_B0_E6_95_91_E6_B2_BB = 0.02
_E6_9C_AA_E5_BE_97_E5_88_B0_E6_95_91_E6_B2_BB = 0.2
_E7_97_8A_E6_84_88_E6_97_B6_E9_97_B4 = 10
_E6_8A_97_E4_BD_93_E6_97_B6_E9_97_B4 = 30
_E5_BA_8A_E4_BD_8D = turtle.numinput('有多少床位', '请输入数字', 10)
time = 1
_E6_AD_BB_E4_BA_A1_E4_BA_BA_E6_95_B0 = 0
_E6_AD_A3_E5_B8_B8_E4_BA_BA_E6_95_B0 = 990
_E5_8F_91_E7_97_85_E4_BA_BA_E6_95_B0 = 0
_E6_BD_9C_E4_BC_8F_E6_9C_9F_E4_BA_BA_E6_95_B0 = 10
_E6_9C_89_E6_8A_97_E4_BD_93_E4_BA_BA_E6_95_B0 = 0
for __count in range(1000):
_E6_83_85_E5_86_B5.append('正常')
while (turtle.numinput('是否继续', '0为继续,1为结束', 0, 0, 1) == 0):
for __count in range(4320):
i = random.randint(0, 999)
if (_E6_83_85_E5_86_B5[i] == '正常'):
_E6_83_85_E5_86_B5[i] = ('潜伏期' + str((time + random.randint(2, 14))))
_E6_BD_9C_E4_BC_8F_E6_9C_9F_E4_BA_BA_E6_95_B0 += 1
_E6_AD_A3_E5_B8_B8_E4_BA_BA_E6_95_B0 -= 1
elif (('潜伏期' in _E6_83_85_E5_86_B5[i]) and time == _E6_83_85_E5_86_B5[i][3:len(_E6_83_85_E5_86_B5[i])]):
if (_E5_BA_8A_E4_BD_8D > 0):
_E6_83_85_E5_86_B5[i] = ('入院' + str((time + 7)))
_E6_BD_9C_E4_BC_8F_E6_9C_9F_E4_BA_BA_E6_95_B0 -= 1
_E5_BA_8A_E4_BD_8D -= 1
else:
_E6_83_85_E5_86_B5[i] = ('发病' + str((time + 7)))
_E5_8F_91_E7_97_85_E4_BA_BA_E6_95_B0 += 1
elif (('入院' in _E6_83_85_E5_86_B5[i]) and _E6_83_85_E5_86_B5[i][3:len(_E6_83_85_E5_86_B5[i])] == time):
if (random.random() < 0.03):
_E6_83_85_E5_86_B5[i] = '喵'
_E6_AD_BB_E4_BA_A1_E4_BA_BA_E6_95_B0 += 1
else:
_E6_83_85_E5_86_B5[i] = ('痊愈日' + str((time + 3)))
elif (('发病' in _E6_83_85_E5_86_B5[i]) and _E6_83_85_E5_86_B5[i][3:len(_E6_83_85_E5_86_B5[i])] == time):
if (random.random() <= 0.2):
_E6_83_85_E5_86_B5[i] = '喵'
_E6_AD_BB_E4_BA_A1_E4_BA_BA_E6_95_B0 += 1
else:
_E6_83_85_E5_86_B5[i] = (str((time + 3)) + '日痊愈1')
elif (('痊愈日' in _E6_83_85_E5_86_B5[i]) and _E6_83_85_E5_86_B5[i][3:len(_E6_83_85_E5_86_B5[i])]):
_E6_83_85_E5_86_B5[i] = ('有抗体至' + str((time + 30)))
_E6_9C_89_E6_8A_97_E4_BD_93_E4_BA_BA_E6_95_B0 += 1
_E5_8F_91_E7_97_85_E4_BA_BA_E6_95_B0 -= 1
if ('1' not in _E6_83_85_E5_86_B5[i]):
_E5_BA_8A_E4_BD_8D += 1
elif (('发病' in _E6_83_85_E5_86_B5[i]) and _E5_BA_8A_E4_BD_8D > 0):
_E6_83_85_E5_86_B5[i] = ('入院' + _E6_83_85_E5_86_B5[i][3:len(_E6_83_85_E5_86_B5[i])])
else:
pass
time += 1
print((str(_E6_AD_A3_E5_B8_B8_E4_BA_BA_E6_95_B0) + '人正常'), (str(_E6_BD_9C_E4_BC_8F_E6_9C_9F_E4_BA_BA_E6_95_B0) + '人处于潜伏期'), (str(_E5_8F_91_E7_97_85_E4_BA_BA_E6_95_B0) + '人已发病'), (str(_E6_9C_89_E6_8A_97_E4_BD_93_E4_BA_BA_E6_95_B0) + '人有抗体'), (str(_E6_AD_BB_E4_BA_A1_E4_BA_BA_E6_95_B0) + '人已喵'))
#长按enter试试(试试就逝世)点赞0
评论