python石頭剪刀布小遊戲(三局兩勝制)

2022-09-28 01:27:09 字數 1638 閱讀 2912

python 石頭剪刀布小遊戲(三局兩勝),供大家參考,具體內容如下

import random

all_choioces = ['石頭', '剪刀', '布']

win_list = [['石頭', '剪刀'], ['剪刀', '布'], ['布', '石頭']]

poeple_on = true

poewww.cppcns.comple_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計算機出的是:%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:

ponrxivhbeple_on = false

print('\033[32;1m遊戲結束\033[0m')

else:

www.cppcns.comprint('\033[31;1m計算機贏了\033[0m')

compute_add += 1

if compute_add == 2:

poeple_on = false

print('\033[32;1m遊戲結束\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,計算機出的是:%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計算機贏了\033[0m')

compute_add += 1

本文標題: python石頭剪刀布小遊戲(三局兩勝制)

本文位址:

python 石頭剪刀布小遊戲

import random import time print 石頭剪刀布小遊戲!time.sleep 3 for i in range 6 for k in range 5 i print end for j in range 2 i 1 print end print for i in rang...

python小遊戲 剪刀,石頭,布

小遊戲 剪刀,石頭,布 規則 剪刀可以剪布,石頭可以磕碰剪刀,而布可以抱住石頭 程式輸入 剪刀,石頭,布 與電腦隨機產生的剪刀,石頭,布做對比 choice 從序列中隨機生產乙個元素 from random import li 剪刀 石頭 布 while true n str input 請輸入剪刀...

python小遊戲 石頭剪刀布

import random pc random.randint 1,3 a none if pc 1 a 石頭 elif pc 2 a 剪刀 else a 布 player input 請輸入剪刀石頭布 if a 石頭 and player 剪刀 or a 剪刀 and player 布 or a ...