song - 无bug版的猜拳游戏

"""
石头1  布2  剪刀3
赢
电脑 我们 结果
1    2   -1
2    3   -1
3    1   2
输
电脑 我们 结果
1    3   -2
2    1   1
3    2   1
平局
电脑 我们 结果
1     1   0
2     2   0
3    3   0

"""
import random
computer = random.randint(1,3)  # int
# 电脑出拳
# 我们出拳
we = input("你出什么呀?")     # str
# 把字符串转成数字
we = int(we)
# 判断
if we > 3 or we < 1:
    print("你是什么人?")
else:
    if we == 1:
        print("我们出了石头")
    elif we == 2:
        print("我们出了布")
    elif we == 3:
        print("我们出了剪刀")
    if computer == 1:
        print("电脑出了石头")
    elif computer == 2:
        print("电脑出了布")
    elif computer == 3:
        print("电脑出了剪刀")
    if computer-we == -1 or computer-we == 2:
        print("你赢了")
    elif computer-we == -2 or computer-we == 1:
        print("你输了")
    elif computer-we == 0:
        print("平局")

发布了414 篇原创文章 · 获赞 19 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/houlaos/article/details/104578409
今日推荐