编程语言
首页 > 编程语言> > python练习:猜拳游戏

python练习:猜拳游戏

作者:互联网

'''
石头(1) 剪刀(2) 布(3)
电脑赢:1-2,2-3,3-1
平局:1-1, 2-2,3-3
我赢:1-3,2-1,3-2
'''

import random
user = int(input("请输入猜拳数字 石头(1) 剪刀(2) 布(3): "))
# computer 是一个int类型
computer = random.randint(1, 3)
print(computer, "-", user)

if user == computer:
    print("平局")
elif (computer == 1 and user == 3) or (computer == 2 and user ==1) or (computer ==3 and user == 2):
    print("用户赢")
else:
    print("电脑赢")

标签:random,猜拳,python,练习,int,computer,user,print,平局
来源: https://blog.csdn.net/hongIQ/article/details/123168695