《python核心编程》(第二版)第六章课后习题 6-14 p162

 

def Rochambeau():
    while True:
        print """请输入选项:
            1 布
            2 石头
            3 剪子
            4 退出"""
        while True:
            player = raw_input()
            if player not in '1234':
                print '选项不正确,重新输入'
            else:
                break
        player = int(player)
        if player==4:
            break
        robot = random.choice([1,2,3])
        print 'versus ',robot
        rules1 = {1:'E',2:'P',3:'R'}
        rules2 = {1:'R',2:'E',3:'P'}
        rules3 = {1:'P',2:'R',3:'E'}
        rules = {1:rules1,2:rules2,3:rules3}
        score = rules[player][robot]
        res = {'P':'你赢啦','R':'你输啦','E':'平局'}
        print res[score]

运行结果:

python_利用元组实现剪刀石头布

 

相关文章:

  • 2022-12-23
  • 2021-12-23
  • 2022-01-21
  • 2022-03-08
  • 2021-10-25
  • 2021-08-24
  • 2022-12-23
猜你喜欢
  • 2021-04-25
  • 2021-09-06
  • 2021-11-20
  • 2022-12-23
  • 2021-11-21
相关资源
相似解决方案