Python:猜拳游戏

import random #导入包
play = int(input("请输入(石头0 剪刀1 布2):")) #这里的int必须加上
i = random.randint(0,2) # 随机生成 0.1.2 其中一个值,并赋值给i

if (play == 0 and i == 2) or (play == 1 and i == 0) or (play == 2 and i == 1):
    print("输了!")
elif play == i:
    print("平!")
else:
    print("赢了!")

print(i) #查看生成的随机值

 代码

输出

 

posted @ 2018-01-05 14:39  伪装会代码的测试  阅读(4105)  评论(0)    收藏  举报