看了好多人写的同项目代码,好长,想着写个短的。
import time,random
def pd(n,t):
if (n == 0 and t == 4) or (n == 1 and t == 1) or (n == 2 and t == 2) or (n == 3 and t == 3):
time.sleep(1)
print("哈哈!n""你赢了!赢了!")
elif (n == 0 and t == 2) or (n == 1 and t == 3) or (n == 2 and t == 4) or (n == 3 and t == 1):
time.sleep(1)
print('诶呀'*3,'输了')
else :
print('是不是没吃饭,又平局n这都赢不了,再来一局')
# 用字典,让电脑输出玩家和电脑出的是什么
# n= 0 1 2 3
guass = ['老虎','鸡','虫子','棒棒']
# t= 1 2 3 4
while True :
while True:
t = int(input('输入数字,1-4'))
if t in [1,2,3,4]:
break
print('数字不对,只能输入1-4')
s = t -1
npc = random.randint(0,3)
b =guass[npc]
c =guass[s]
time.sleep(1)
print('电脑出的是:',b)
time.sleep(1)
print('你出的是:',c)
pd(npc,t)
n = input('继续按任意键,退出按N')
if n == 'n':
break
果然代码还是得自己敲,实践出真知。测试的时候发现玩家输入标点符号的时候报错,查询了一下,好像需要正则表达式,这个不会还在学,后边再说。
下一步打算,基础语法会了,试试实战,写一个听书小程序,边写边学,实践出真知。
Tips
- 您发布的文章将会展示至 里程碑专区 ,您也可以在 专区 内查看其他创作者的纪念日文章
- 优质的纪念文章将会获得神秘打赏哦



