有效性检测:2024年5月2日依然有效。原因:记录了我的python学习历史,是史书性质的。
我会每周做一个python作品放在这里 以记录。
版本:python3.9.7
刚刚入门 不追求复杂程序 循序渐进。
自作多情系列没时间更新 所以先放着。
继续开源 第六周
没啥东西好开了 那就把最底层的码子框架开下
返回的大致原理就是:设定一个阈值,我这里是Flag,我设定:flag=0时就循环,所以在一小段的程序结束后,就可以通过循环回到开始菜单,再加一个清屏,就很完美了。
想要离开循环也很简单,我在程序结束后的选择中加入了使flag=1的选项,这样使用户得以退出程序。
这算是一个入门必须掌握的算法之一了吧。我称其为:阈值判断算法
ver="your_version"
#判断版本是否为最新
url="your_txt_path_on_internet"
getver=requests.get(url)
while Net==1:
if not getver.text==ver:
print("你的版本已经过时了!最新版是" + str(getver.text) + ",链接已经复制到了剪贴板(密码:your_pwd),请你尽快去下载并更新以体验最新功能!")
link = "your_link"
print("下一版本更新日志:your_website")
Net = 0
pyperclip.copy(link)
elif getver.text==ver:
print("你的版本"+str(ver)+"是最新版!")
Net=0
#继续欢迎用户
timenow=time.asctime(time.localtime(time.time()))
print("现在时间:"+str(timenow))
#开始程序!
Flag=0
while Flag==0:
print("选项1:Python入门选项 选项2:圆周率计算 选项3:猜数字高低")
print("选项4:比数字大小游戏 选项5:随机数生成 选项6:狼人杀[New!] 选项7:关于工具箱&ChangeLog")
chosen=input("请输入选项[1/2/3/4/5/6/7],输入0以退出:")
#程序1
if chosen=="0":
exit(0)
elif chosen=="1":
##程序内容##
value=str(input("done!体验其他程序[Y]还是退出[N]?"))
if value=="Y":
Flag=0
os.system("cls")
elif value=="N":
exit(0)
else:
input("输入错误!")
os.system("cls")
#程序2..3..4皆如此
第五周
哈哈期末考结束辣!!
由于正在制作GUI版本的无聊工具箱,所以原版可以开始逐渐开源了。
那就开源一个狼人杀的代码吧。
print("游戏介绍就不放了,大家应该是耳熟能详了。")
Flag = input("回车开始游戏[输入0退出]:")
#people = input("你们要玩几个人类型的(裁判没有包括在内)[6个人/8个人]:")
people="6"
if people == "6":
print("接下来裁判进行开局设置")
print("套餐是:2狼人1猎人1平民1女巫1预言家")
print("好的,裁判进入设置")
name_wolf1 = "unknown"
name_wolf2 = "unknown"
name_people = "unknown"
name_hunter = "unknown"
name_xrayer = "unknown"
sleep(0.5)
print("开始决定身份,如果有困难可以尝试使用无聊工具箱里面的随机数")
print("建议旁边开个记事本把名字复制过去(记得打乱顺序)方便后期填写!")
name_wolf1 = input("裁判请偷偷决定身份,告诉对应的人身份后,把一号狼人的名字输入在这里:")
name_wolf2 = input("把二号狼人的名字输入在这里:")
name_hunter = input("输入猎人的名字:")
name_people = input("输入平民的名字:")
name_witch = input("输入女巫的名字:")
name_xrayer = input("输入预言家名字:")
print("设置完成!开始游戏!")
os.system("cls")
wolf1_statu = "live"
wolf2_statu = "live"
people_statu = "live"
hunter_statu = "live"
witch_statu = "live"
xrayer_statu = "live"
game_statu = "not_finish"
witch_kill_time = 3
witch_save_time = 3
round=1
while (wolf1_statu == "live" or wolf2_statu == "live" or witch_statu == "live" or people_statu == "live" or hunter_statu == "live") and game_statu == "not_finish":
print("现在是第"+str(round)+"天")
death_list = []
print("天黑请闭眼")
sleep(0.5)
print("狼人请睁眼")
sleep(0.5)
print("来,1号狼人认识一下," + str(name_wolf2) + "是你的队友2号狼人")
sleep(0.5)
if wolf1_statu == "live":
wolf1_name_will_kill = input("请狼人一号输入要杀的人的名字(请一定输入准确/输入0不杀):")
if wolf1_name_will_kill == name_people:
people_statu = "dead"
death_list.append(name_people)
elif wolf1_name_will_kill == name_hunter:
hunter_statu = "dead"
death_list.append(name_hunter)
elif wolf1_name_will_kill == name_witch:
witch_statu = "dead"
death_list.append(name_witch)
elif wolf1_name_will_kill == name_xrayer:
xrayer_statu = "dead"
death_list.append(name_xrayer)
elif wolf1_name_will_kill == "0":
pass
else:
pass
sleep(0.5)
if wolf2_statu == "live":
print("昨晚" + str(death_list) + "被杀了,请二号狼人继续选择要杀的角色")
sleep(0.5)
print("二号狼人认识一下," + str(name_wolf1) + "是你的一号狼人队友")
wolf2_name_will_kill = input("请狼人二号输入要杀的人的名字(请一定输入准确/输入0不杀):")
if wolf2_name_will_kill == name_people:
people_statu = "dead"
death_list.append(name_people)
elif wolf2_name_will_kill == name_hunter:
hunter_statu = "dead"
death_list.append(name_hunter)
elif wolf2_name_will_kill == name_witch:
witch_statu = "dead"
death_list.append(name_witch)
elif wolf2_name_will_kill == name_xrayer:
xrayer_statu = "dead"
death_list.append(name_xrayer)
elif wolf2_name_will_kill == "0":
pass
if witch_statu == "live" and not witch_save_time == 0:
print("请女巫过来")
input("过来了请回车:")
print("昨晚" + str(death_list) + "死了")
sleep(0.5)
print("你要救吗[0.不救 1.救]:")
if_save = input("输入你的选择吧:")
if if_save == "0":
pass
elif if_save == "1":
save_who = input("救谁(写名字,准确输入):")
if save_who == name_hunter:
hunter_statu = "live"
death_list.remove(name_hunter)
elif save_who == name_people:
people_statu = "live"
death_list.remove(name_people)
elif save_who == name_xrayer:
xrayer_statu = "live"
death_list.remove(name_xrayer)
witch_save_time=witch_save_time-1
print("女巫救助完成!")
sleep(1)
if xrayer_statu == "live":
input("请预言家过来:")
sleep(0.5)
print("你拥有查看身份的权力,")
xrayer_will_check = input("请输入你想查看身份的人的名字(只能输入一个):")
sleep(0.5)
name_dic = {name_people: "平民", name_hunter: "猎人", name_witch: "女巫", name_wolf1: "狼人一号",
name_wolf2: "狼人二号"}
print(str(xrayer_will_check) + "的身份是" + str(name_dic[xrayer_will_check]))
input("看好了回车:")
os.system("cls")
if not (wolf1_statu == "dead" and wolf2_statu == "dead") and not (people_statu == "dead" and witch_statu == "dead" and xrayer_statu == "dead" and hunter_statu == "dead"):
sleep(0.5)
input("晚上活动完毕!回车进入第" + str(round + 1) + "天!")
os.system("cls")
print("天亮了!")
sleep(0.5)
if len(death_list) == 0:
print("昨晚是平安夜!")
else:
print("昨晚" + str(death_list) + "被杀了!")
input("讨论一下,好了按回车:")
sleep(0.5)
print("接下来开始投票,票数最多的将会被处死并公布身份。")
print("请一个一个来投票,裁判做好保密工作")
vote_count = 0
vote_people = 0
vote_hunter = 0
vote_wolf1 = 0
vote_wolf2 = 0
vote_witch = 0
vote_xrayer = 0
vote_list = []
while vote_count < 6:
vote_temp = input("请输入你觉得是狼人的人:")
vote_list.append(vote_temp)
vote_count = vote_count + 1
vote_people = vote_list.count(name_people)
vote_hunter = vote_list.count(name_hunter)
vote_wolf1 = vote_list.count(name_wolf1)
vote_wolf2 = vote_list.count(name_wolf2)
vote_xrayer = vote_list.count(name_xrayer)
vote_witch = vote_list.count(name_witch)
voted_list = [vote_people, vote_hunter, vote_wolf1, vote_wolf2, vote_xrayer, vote_witch]
vote_to_name_dic = {vote_people: name_people, vote_hunter: name_hunter, vote_wolf1: name_wolf1,
vote_wolf2: name_wolf2, vote_xrayer: name_xrayer, vote_witch: name_witch}
most_vote_name = vote_to_name_dic[max(voted_list)]
print(str(most_vote_name) + "票数最多,被处死!")
if most_vote_name == name_people:
people_statu = "dead"
elif most_vote_name == name_hunter:
hunter_statu = "dead"
elif most_vote_name == name_wolf1:
wolf1_statu = "dead"
elif most_vote_name == name_wolf2:
wolf2_statu = "dead"
elif most_vote_name == name_witch:
witch_statu = "dead"
elif most_vote_name == name_xrayer:
xrayer_statu = "dead"
round=round+1
else:
if wolf1_statu == "dead" and wolf2_statu == "dead":
print("平民胜利啦!")
print("公示身份:")
print(str(name_wolf1) + "狼人一号")
print(str(name_wolf2) + "狼人二号")
print(str(name_people) + "平民")
print(str(name_witch) + "女巫")
print(str(name_xrayer) + "预言家")
print(str(name_hunter) + "猎人")
game_statu = "finished"
elif people_statu == "dead" and witch_statu == "dead" and xrayer_statu == "dead" and hunter_statu == "dead":
print("狼人胜利啦!")
print(str(name_wolf1) + "狼人一号")
print(str(name_wolf2) + "狼人二号")
print(str(name_people) + "平民")
print(str(name_witch) + "女巫")
print(str(name_xrayer) + "预言家")
print(str(name_hunter) + "猎人")
game_statu = "finished"
round = round + 1
第四周
放一个已经集成在无聊工具箱里面的猜数字游戏。
这是目前最新版本,比目前已经发布的工具箱还要新。
游戏挺好玩的hhh就连续用计算器和朋友玩了3天多才失去兴趣
写成Python,可以作为一种记录,当然把自己喜欢玩的游戏写出来,又慢慢修复一大堆bug,成就感爆棚hhh!
老师说的是对的,只要学会if while for input
和一些杂七杂八的东西 交互类软件就搞定了。
这一串代码功能还是很丰富的,可以计分,判断作弊啥的。
其中的Flag
是为了集成在工具箱里面用来存储是否返回的阈值的一个变量,懒得删,可以不用管。
如果你想玩,推荐你去下载我的无聊工具箱
from os import sleep
import random
l = []
l2 = []
describe = input("想看介绍输入1,输入其他或者回车直接开始游戏:")
if describe == "1":
print("游戏介绍:")
sleep(1)
print("本游戏是我在课间时和同学使用计算器随机数发现的游戏。")
sleep(1)
print("没有其他任何条件的比较,单纯比运气。")
sleep(1)
print("我们会像一个专业的比赛一样,实行3局2胜或者5局3胜制度。")
sleep(1)
print("我不会写的太自动化,为了防止有人怀疑有作弊现象。")
sleep(1)
print("名字是开局双方自由规定的,不存在任何暗箱操作。")
sleep(1)
print("具体的玩法就是:程序负责生成5个或者10个随机数,由比赛者挑选最大的一个数,和对方比赛者挑选的数字进行比较,谁的数字大谁就拿下这一把。")
sleep(1)
print("就是这么简单。")
sleep(1)
print("别想在输入时作弊。程序会识别你输入的数字是不是在生成的随机数序列中(会在后来的更新中实现)。")
sleep(1)
print("如果你作弊了,程序会直接判定你输。")
sleep(1)
statu = 1
value = input("准备好开始游戏了吗[Y开始/N退出]")
if value == "Y":
Flag = 1
elif value == "N":
Flag = 0
else:
print("输入错误,我懒得写循环,那你直接爬吧。")
input("按回车退出:")
exit(0)
point1 = 0
point2 = 0
played = 0
cheat=0
player1="unknown"
player2="unknown"
while Flag == 1:
if statu > 5 and point1 == point2:
print("本局比分:" + str(point1) + ":" + str(point2))
print("本局平局!")
Flag = 0
if statu > 5 and Flag == 1:
print("上一局游戏已经结束!")
choose = input("再来一把还是玩玩其他的[Y继续N玩其他]:")
if choose == "Y":
Flag = 1
elif choose == "N":
Flag = 0
else:
input("输入错误,回车返回主界面!")
Flag = 0
if Flag == 1:
player1 = input("请输入一号玩家的名字:")
player2 = input("请输入二号玩家的名字:")
while statu <= 5 and Flag == 1:
if played == 1 and Flag == 1:
print("上一把比分:" + str(point1) + ":" + str(point2))
print("现在是第" + str(statu) + "把")
if played == 0 and Flag == 1:
max = int(input("请双方共同商议决定最大值[最小值为0]:"))
sleep(1)
print("开始游戏!")
input("请一号玩家" + str(player1) + "回车生成5个随机数:")
count = 0
while count < 5:
temp = str(random.randint(0, max))
print(temp)
l.append(int(temp))
count = count + 1
else:
print("生成完毕!")
num1 = int(input("请一号玩家" + str(player1) + "输入你选择的数字:"))
if not num1 in l:
print("一号玩家作弊!本局二号玩家赢!")
cheat=1
sleep(1)
print("一号玩家" + str(player1) + "选择的数字:" + str(num1))
if cheat==0:
input("请二号玩家" + str(player2) + "回车生成随机数:")
count = 0
while count < 5:
temp = str(random.randint(0, max))
print(temp)
l.append(int(temp))
count = count + 1
else:
print("生成完毕!")
num2 = int(input("请二号玩家" + str(player2) + "输入你选择的数字:"))
if not num2 in l:
print("二号玩家作弊!本局一号玩家赢!")
cheat=2
print("二号玩家" + str(player2) + "选择的数字:" + str(num2))
if (num1 < num2 and cheat == 0) or cheat == 1:
print("二号玩家" + str(player2) + "拿下第" + str(statu) + "把!")
point2 = point2 + 1
elif (num1 > num2 and cheat == 0) or cheat == 2:
print("一号玩家" + str(player1) + "拿下第" + str(statu) + "把!")
point1 = point1 + 1
elif num1 == num2:
print("你们平局!")
point1 = point1 + 1
point2 = point2 + 1
statu = statu + 1
played = 1
if point1 >= 3 or point2 >= 3:
if point1 > point2:
print("本局比分:" + str(point1) + ":" + str(point2))
print("一号玩家" + str(player1) + "胜出!")
input("回车回到主界面!")
Flag = 0
elif point2 > point1:
print("本局比分:" + str(point1) + ":" + str(point2))
print("二号玩家" + str(player2) + "胜出!")
input("回车回到主界面!")
Flag = 0
第三周
由于在开发无聊工具箱,所以程序会少发一些。
这周就整个最近写的猜密码吧。
就是if和while的堆栈,感觉是没啥技术含量,但是挺实用。
passwd=str(input("请输入你要设置的密码:"))
passwd2=str(input("请再次输入密码:"))
count=0
while not passwd == passwd2:
passwd=str(input("密码错误!请重新输入你要设置的密码:"))
passwd2=str(input("请再次输入你刚刚设置的密码:"))
count=count+1
while not passwd == passwd2:
passwd=str(input("密码错误了!请重新输入你要设置的密码:"))
passwd2=str(input("请再次输入你刚刚设置的密码:"))
count=count+1
if count>5:
print("爬")
exit(0)
else:
print("密码设置成功!")
print("接下来是登录环节")
inputcount=0
print("系统登录")
inputpasswd=str(input("请输入密码:"))
while not inputpasswd==passwd:
inputpasswd=str(input("密码错误!请再次输入密码!"))
inputcount=inputcount+1
if inputcount>5:
print('密码错误次数太多!退出程序!')
input("按回车退出!")
exit(0)
else:
input("登录成功!按回车退出登录界面!")
exit(0)
第二周 天干地支计算(附exe)
信息技术作业会有这个,可以参考下嘻嘻
year=int(input("请输入你要计算天干地支的年份:"))
tiangan=str((year-3)%10)
dizhi=str((year-3)%12)
tgdic={"1":"甲","2":"乙","3":"丙","4":"丁","5":"戊","6":"己","7":"庚","8":"辛","9":"壬","10":"癸"}
dzdic={"1":"子","2":"丑","3":"寅","4":"卯","5":"辰","6":"巳","7":"午","8":"未","9":"申","10":"酉","11":"戌","12":"亥"}
tg=tgdic[tiangan]
dz=dzdic[dizhi]
result=tg+dz
print("这一年是"+result+"年")
input("计算完成!回车退出!")
exit(0)
第一周 随机数生成
random这玩意py自带我都不知道。
import random
count=0
time=0
min=int(input("请输入最小整数:"))
max=int(input("请输入最大整数:"))
time=int(input("请输入生成个数:"))
while count<time:
print(random.randint(min,max))
count=count+1
else:
input("输出完成!按回车结束程序!")
第一周 BMI计算判断及输出
写了差不多有6分钟,写写搜搜也算是能写出来。
m=float(input("input your weight pls(kg):"))
h=float(input("input your height pls(cm):"))
M=float(m/((h/100)**2))
print ("your BMI is:",(round(M,2)))
F=str(input ("Do you want to know if you are heavy or not?[Y/N]:"))
if F=="N":
exit
elif F=="Y":
if M>21:
print("how motherfucking fat you are!")
elif M>=18:
print("Thanks to the god,your weight are normal.")
else:
print("you are the thinest person i have ever met before!")
2 条评论
how motherfucking fat you are..............................
You aren't fat, right?