码迷,mamicode.com
首页 > 编程语言 > 详细

Python简单剪刀石头布编程实例

时间:2018-12-26 16:00:20      阅读:633      评论:0      收藏:0      [点我收藏+]

标签:class   port   imp   用户   pytho   pre   div   computer   dom   

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(‘好吧,平局@_@‘)
else:
    print(‘电脑胜出!‘)

  

Python简单剪刀石头布编程实例

标签:class   port   imp   用户   pytho   pre   div   computer   dom   

原文地址:https://www.cnblogs.com/ptest/p/10178903.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!