Fork me on GitHub

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

  

posted @ 2018-12-26 14:16  上海_布丁  阅读(10394)  评论(0编辑  收藏  举报