码迷,mamicode.com
首页 > 其他好文 > 详细

剪刀石头布(三局两胜)

时间:2020-02-19 23:41:05      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:input   com   bre   win   put   nbsp   代码   最简   NPU   

(1)通过最简单的选择和循环实现(但代码过长)
import random
computer_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

剪刀石头布(三局两胜)

标签:input   com   bre   win   put   nbsp   代码   最简   NPU   

原文地址:https://www.cnblogs.com/yzdmh/p/12333721.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!