剪刀石头布(三局两胜)
Posted yzdmh
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了剪刀石头布(三局两胜)相关的知识,希望对你有一定的参考价值。
(1)通过最简单的选择和循环实现(但代码过长)
import random
computer_win_count = 0
people_win_count = 0
people_win_count = 0
while True:
computer = random.randint(0,2)
people = int(input("请做出选择(0:石头 1:剪刀 2:布):"))
if computer == people == 0:
print("电脑:石头 玩家:石头 结果:平局")
elif computer == people == 1:
print("电脑:剪刀 玩家:剪刀 结果:平局")
elif computer == people == 2:
print("电脑:布 玩家:布 结果:平局")
elif computer == 0 and people == 1:
print("电脑:石头 玩家:剪刀 结果:你输了")
computer_win_count += 1
elif computer == 0 and people == 2:
print("电脑:石头 玩家:布 结果:你赢了")
people_win_count += 1
elif computer == 1 and people == 0:
print("电脑:剪刀 玩家:石头 结果:你赢了")
people_win_count += 1
elif computer == 1 and people == 2:
print("电脑:剪刀 玩家:布 结果:你输了")
computer_win_count += 1
elif computer == 2 and people == 0:
print("电脑:布 玩家:石头 结果:你输了")
computer_win_count += 1
elif computer == 2 and people == 1:
print("电脑:布 玩家:剪刀 结果:你赢了")
people_win_count += 1
if computer_win_count == 2 and people_win_count < 2:
print("最终结果:电脑获胜")
break
if computer_win_count < 2 and people_win_count == 2:
print("最终结果:你获胜")
break
computer = random.randint(0,2)
people = int(input("请做出选择(0:石头 1:剪刀 2:布):"))
if computer == people == 0:
print("电脑:石头 玩家:石头 结果:平局")
elif computer == people == 1:
print("电脑:剪刀 玩家:剪刀 结果:平局")
elif computer == people == 2:
print("电脑:布 玩家:布 结果:平局")
elif computer == 0 and people == 1:
print("电脑:石头 玩家:剪刀 结果:你输了")
computer_win_count += 1
elif computer == 0 and people == 2:
print("电脑:石头 玩家:布 结果:你赢了")
people_win_count += 1
elif computer == 1 and people == 0:
print("电脑:剪刀 玩家:石头 结果:你赢了")
people_win_count += 1
elif computer == 1 and people == 2:
print("电脑:剪刀 玩家:布 结果:你输了")
computer_win_count += 1
elif computer == 2 and people == 0:
print("电脑:布 玩家:石头 结果:你输了")
computer_win_count += 1
elif computer == 2 and people == 1:
print("电脑:布 玩家:剪刀 结果:你赢了")
people_win_count += 1
if computer_win_count == 2 and people_win_count < 2:
print("最终结果:电脑获胜")
break
if computer_win_count < 2 and people_win_count == 2:
print("最终结果:你获胜")
break
以上是关于剪刀石头布(三局两胜)的主要内容,如果未能解决你的问题,请参考以下文章