4、Python基础---while剪刀石头布(基于Python3.6)

import random

# 提示并获取用户的输入
player = int(input("请输入 0剪刀 1石头 2布:"))

# 电脑出一个
computer = random.randint(0, 2)

# 判断用户的输入,然后显示对应的结果
# if玩家获胜的条件
if (player == 0 and computer == 2) or (player == 1 and computer == 0) or (player == 2 and computer == 1):
    print("赢了")
elif player == computer:
    print("平局")
else:
    print("输了")
发布了48 篇原创文章 · 获赞 49 · 访问量 1865

猜你喜欢

转载自blog.csdn.net/bjniujw1024/article/details/104379683