欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

用Python實現(xiàn)石頭剪刀布游戲

 更新時間:2022年01月18日 15:02:26   作者:小鹿煥煥  
大家好,本篇文章主要講的是用Python實現(xiàn)石頭剪刀布游戲,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下

 從控制臺輸入要出的拳 —— 剪刀(0)/石頭(1)/布(2)

 電腦 **隨機** 出拳 

 比較勝負(fù)

增加錯誤輸入的檢測模塊

# -*- coding = utf-8 -*-
# @Time :  22:03
# @Author : huanhuan
# @File : test.py
# @Software : PyCharm
import random
 
 
def show(num):
    if num == 0:
        sign = "剪刀"
    elif num == 1:
        sign = "石頭"
    else:
        sign = "布"
    return sign
 
 
while True:
    try:
        com = random.randint(0, 2)
        people = int(input("請輸入(剪刀:0,石頭:1,布:2):"))
        if people > 3 or people < 0:
            print("請輸入正確的數(shù)字")
        else:
            print("玩家出%s,電腦出%s" % (show(people), show(com)))
            if (people == 0 and com == 2) \
                    or (people == 1 and com == 0) \
                    or (people == 2 and com == 1):
                print("玩家勝利")
            elif people == com:
                print("雙方平局")
            elif people == 3:
                print("結(jié)束游戲")
                break
            else:
                print("電腦勝利")
    except ValueError:
        print("請輸入數(shù)字而不是字母")

到此這篇關(guān)于用Python實現(xiàn)石頭剪刀布游戲的文章就介紹到這了,更多相關(guān)Python石頭剪刀布內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論