石头剪刀布:猜拳小游戏
规则:石头锤剪刀,剪刀咔布,布包石头
软件:PyCharm
语言:python
级别:primary
人机对战,敢不敢来挑战!
if __name__ == '__main__':
print("请输入您的筹码:")
print('notes: 1.石头 2.剪刀 3.布')
a = eval(input(''))
b = random.randint(1, 3)`
if a == b:
print('平手')
elif a - b == -1 or a - b == 2:
print('恭喜你,你赢啦!')
else:
print('不要灰心,再来一次吧!')
notes:仔细观察规则,不难发现,’1.石头 2.剪刀 3.布‘的编号按规则‘石头锤剪刀,剪刀咔布,布包石头‘,赢时,差值为-1/2, a - b == -1 or a - b == 2
def tip(judge, name):
# 或者在这里判断,用一个值来接
# print('电脑' if isRobot else '玩家') 三目运算符
if judge == 1:
print(name + '出的石头')
elif judge == 2:
print(name + '出的剪刀')
else:
print(name + '出的布')
(期盼带给你欢乐,祝你学习愉快~)