Python 石頭剪刀布小游戲(三局兩勝),供大家參考,具體內(nèi)容如下
import randomall_choioces = ['石頭', '剪刀', '布']win_list = [['石頭', '剪刀'], ['剪刀', '布'], ['布', '石頭']]poeple_on = Truepoeple_add = 0compute_add =0while 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 randomall_choioces = ['石頭', '剪刀', '布']win_list = [['石頭', '剪刀'], ['剪刀', '布'], ['布', '石頭']]poeple_add = 0compute_add = 0while 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í)有所幫助,也希望大家多多支持武林站長(zhǎng)站。
|
新聞熱點(diǎn)
疑難解答
圖片精選