python猜拳游戏三局两胜制_python石头剪刀布小游戏(三局两胜制)
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)布 請(qǐng)選擇:'''
ind = int(input(put))
poeple = all_choioces[ind]
print('你出的:%s,計(jì)算機(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ì)算機(jī)贏了\033[0m')
compute_add += 1
if compute_add == 2:
poeple_on = False
print('\033[32;1m游戲結(jié)束\033[0m')
第二種簡(jiǎn)單的格式
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)布 請(qǐng)選擇:'''
ind = int(input(put))
poeple = all_choioces[ind]
print('你出的:%s,計(jì)算機(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ì)算機(jī)贏了\033[0m')
compute_add += 1
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持。
總結(jié)
以上是生活随笔為你收集整理的python猜拳游戏三局两胜制_python石头剪刀布小游戏(三局两胜制)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: eigrp配置实验_路由器 OSPF 动
- 下一篇: es6箭头函数_ES6语法之-箭头函数