python 小案例demo01

#-*- codeing = utf-8 -*-
#@Time : 2020/10/26 23:52
#@Author : 柒夜
#@File : demo01.py
#@Software : PyCharm

# 1、 猜拳 (用if elif else)

import random
user = int(input("请猜拳:(0为石头 1为剪刀 2为布)"))

a = random.randint(0,2)
result = ""
if a == 0:
result = "石头"
elif a == 1:
result = "剪刀"
elif a == 2:
result = "布"

if user == a:
print("平局 对方出了%s"%result)
elif user == 0 and a == 1:
print("恭喜您赢了,对方出了%s"%result)
elif user == 0 and a == 2:
print("很遗憾 您输了 对方出了%s"%result)
elif user == 1 and a == 0:
print("很遗憾您输了 对方出了%s"%result)
elif user == 1 and a == 2:
print("恭喜您赢了 对方出了%s"%result)
elif user == 2 and a == 0:
print("恭喜您赢了 对方出了%s"%result)
elif user == 2 and a == 1:
print("很遗憾 您输了 对方出了%s"%result)
else:
print("输入错误")


posted @ 2020-10-27 14:09  AxeBurner  阅读(91)  评论(0编辑  收藏  举报