Python简单剪刀石头布编程实例
Posted 上海_布丁
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python简单剪刀石头布编程实例相关的知识,希望对你有一定的参考价值。
import random # 电脑人随机出拳 computer = random.randint(1, 3) user = int(input(‘请出拳:1/拳头,2/剪刀,3/布‘)) if computer == 1: computer = ‘拳头‘ elif computer == 2: computer = ‘剪刀‘ else: computer = ‘布‘ if user == 1: user = ‘拳头‘ elif user == 2: user = ‘剪刀‘ else: user = ‘布‘ print(‘电脑人出的是%s,用户出的是%s‘ % (computer, user)) if ((user == 1 and computer == 2) or (user == 2 and computer == 3) or (user == 3 and computer == 1)): print(‘用户胜出~_~‘) elif user == computer: print(‘好吧,平局@[email protected]‘) else: print(‘电脑胜出!‘)
以上是关于Python简单剪刀石头布编程实例的主要内容,如果未能解决你的问题,请参考以下文章