378 发表于 2018-8-11 08:29:46

python 石头剪刀布游戏

import random  
winlist = [['石头,剪刀'],['剪刀,布'],['布,拳头']]
  
choicelist = ('石头','剪刀','布')
  
promt = '''请选择“石头,剪刀,布”:
  
    0.石头
  
    1.剪刀
  
    2.布
  
    3.退出
  
    输入数字1-4即可,请输入:'''
  
while True:
  
    userchoicenum = int(input(promt))
  
    if userchoicenum== 3:
  
      break
  
    userchoice = choicelist
  
    comchoice = random.choice(choicelist)
  
    bothchoice =
  
    if userchoice == comchoice:
  
      print('   平局')
  
      break
  
    elif bothchoice in winlist:
  
      print(' \n    你赢了!\n    你选择的是:%s计算机选择的是:%s' % (userchoice,comchoice))
  
      break
  
    else:
  
      print(' \n    计算机赢了!\n    你选择的是:%s计算机选择的是:%s' % (userchoice,comchoice))
  
      break
页: [1]
查看完整版本: python 石头剪刀布游戏