python石頭剪刀布小游戲(三局兩勝制)
更新時間:2021年01月20日 15:05:09 作者:A_Gorilla
這篇文章主要為大家詳細(xì)介紹了python石頭剪刀布小游,三局兩勝制,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
Python 石頭剪刀布小游戲(三局兩勝),供大家參考,具體內(nèi)容如下
import random
all_choioces = ['石頭', '剪刀', '布']
win_list = [['石頭', '剪刀'], ['剪刀', '布'], ['布', '石頭']]
poeple_on = True
poeple_add = 0
compute_add =0
while poeple_on:
compute = random.choice(all_choioces)
put ='''(0)石頭(1)剪刀(2)布 請選擇:'''
ind = int(input(put))
poeple = all_choioces[ind]
print('你出的:%s,計算機(jī)出的是:%s' % (poeple, compute))
if poeple == compute:
print('\033[32;1m平局\033[0m')
elif [poeple, compute] in win_list:
print('\033[31;1m你贏了\033[0m')
poeple_add += 1
if poeple_add == 2:
poeple_on = False
print('\033[32;1m游戲結(jié)束\033[0m')
else:
print('\033[31;1m計算機(jī)贏了\033[0m')
compute_add += 1
if compute_add == 2:
poeple_on = False
print('\033[32;1m游戲結(jié)束\033[0m')
第二種簡單的格式
import random
all_choioces = ['石頭', '剪刀', '布']
win_list = [['石頭', '剪刀'], ['剪刀', '布'], ['布', '石頭']]
poeple_add = 0
compute_add = 0
while poeple_add < 2 and compute_add < 2 :
compute = random.choice(all_choioces)
put ='''(0)石頭(1)剪刀(2)布 請選擇:'''
ind = int(input(put))
poeple = all_choioces[ind]
print('你出的:%s,計算機(jī)出的是:%s' % (poeple, compute))
if poeple == compute:
print('\033[32;1m平局\033[0m')
elif [poeple, compute] in win_list:
print('\033[31;1m你贏了\033[0m')
poeple_add += 1
else:
print('\033[31;1m計算機(jī)贏了\033[0m')
compute_add += 1
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
詳解Python的Django框架中manage命令的使用與擴(kuò)展
這篇文章主要介紹了Python的Django框架中manage命令的使用與擴(kuò)展,manage.py使得用戶借助manage命令在命令行中能實(shí)現(xiàn)諸多簡便的操作,需要的朋友可以參考下2016-04-04
python基于三階貝塞爾曲線的數(shù)據(jù)平滑算法
這篇文章主要介紹了python基于三階貝塞爾曲線的數(shù)據(jù)平滑算法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
Pytest參數(shù)化parametrize使用代碼實(shí)例
這篇文章主要介紹了Pytest參數(shù)化parametrize使用代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-02-02
如何解決Selenium包安裝成功卻無法導(dǎo)入的問題
這篇文章主要介紹了如何解決Selenium包安裝成功卻無法導(dǎo)入的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-08-08
python接口自動化(十七)--Json 數(shù)據(jù)處理---一次爬坑記(詳解)
這篇文章主要介紹了python Json 數(shù)據(jù)處理,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04

