猜拳击的小游戏
if 循环:
#猜拳击的小游戏 0:石头 1:剪刀 2: 布
import random #直接导入产生随机数的模块
#计算机 人
person=int(input('请出拳:[0:石头 1:剪刀 2:布]'))
computer=random.randint(0,2)
if person==0 and computer==1:
print('你赢了')
pass
elif person==1 and computer==2:
print('你赢了')
pass
elif person==2 and computer==0:
print('你赢了')
pass
elif person==computer:
print('不错,平手')
pass
else:
print('哈哈')
pass
while 循环:
#猜拳击的小游戏 0:石头 1:剪刀 2: 布
import random
count=1
while count<=10:
person=int(input('请出拳:[0:石头 1:剪刀 2:布]'))
computer=random.randint(0,2)
if person==0 and computer==1:
print('你赢了')
pass
elif person==1 and computer==2:
print('你赢了')
pass
elif person==2 and computer==0:
print('你赢了')
pass
elif person==computer:
print('不错,平手')
pass
else:
print('哈哈')
pass
这是一个使用Python编写的猜拳游戏程序,包含了if和while两种循环实现方式。玩家可以选择石头、剪刀或布,计算机随机出拳,根据游戏规则判断胜负。游戏可以进行多次,直到达到指定的次数限制。
618





