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) #查看生成的随机值

 代码

输出

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM