python⽯头剪⼑布⼩游戏(三局两胜制)Python ⽯头剪⼑布⼩游戏(三局两胜),供⼤家参考,具体内容如下
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]
python可以做什么游戏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:
poeple_on = False
print('\033[32;1m游戏结束\033[0m')
else:
print('\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
以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论