游戏 猜拳游戏

import random
#猜拳游戏

"""
首先用户需求分析:
猜拳游戏,石头、剪刀、布
用户猜三次
猜不到用户可以选择游戏退出,或继续游戏
1.人与机器人猜拳
用字典存贮人的信息
{1:‘石头’,2:'剪刀',3:'布'}
猜拳的结果:
人赢的概率:
‘石头’
if _ =='剪刀'and

"""
i = 0
while i <= 3:
person = {1: '石头',2: '剪刀',3: '布'}
robot = random.choice(('石头', '剪刀', '布'))
print('机器人出了' + robot)
b = 1
while b:
a = input('请输入数字1、2、3,(1、代表石头)、(2、代表剪刀)、(3、代表布) :')
try:
a = int(a)
except Exception as e:
print(e)
print('------请输入正整数不要大于3--------')
if isinstance(a, int):
try:
if a <= 0 or a > 3:
raise ValueError('输入的数字不能小于等于零或者大于3(超出范围了)')
except ValueError:
print('输入的数字不能小于等于零或者大于3(超出范围了)')
else:
b = 0
#人赢的情况
if (person[a] == '石头' and robot == '剪刀') or (person[a] == '剪刀' and robot == '布') or (
person[a] == '布' and robot == '石头'):
print('恭喜你赢了')
game = input('y/n退出游戏(y/游戏退出)、(n/游戏继续):')
if game == 'y':
print('游戏退出')
break
elif game == 'n':
print('游戏继续')

elif person[a] == robot:
print('平局')
i += 1
if i > 2:
game = input('y/n退出游戏(y/游戏退出)、(n/游戏继续):')
if game == 'y':
print('游戏退出')
break
elif game == 'n':
print('游戏继续')
i = 0

else:
print('你的运气值不在状态,你输了')
i += 1
if i > 2:
game = input('y/n退出游戏(y/游戏退出)、(n/游戏继续):')
if game == 'y':
print('游戏退出')
break
elif game == 'n':
print('游戏继续')
i = 0

这个猜拳还存在着bug不过我没有写跟 强制 数字 1、2、3、的代码结构一样

看看你们的逻辑思维怎么样代码结构怎么样

猜你喜欢

转载自www.cnblogs.com/wuheng-123/p/9099504.html