目录
优点:
答案一:
答案二:
优点: 根据老师进度编写,小白一枚,只为记录每次进步,欢迎大家提出意见与建议。 答案一:#用户
user = int(input('请输入:剪刀(0)、石头(1)、布(2):'))
if user == 0 :
chinese = "剪刀"
elif user == 1:
chinese = "石头"
else:
chinese = "布"
print("你的输入为%s(%d)"%(chinese,user))
#电脑
import random #调用随机库
computer=random.randint(0,2)
print("随机生成数字为%d"%computer)
#判断输赢
if user == 0 and computer == 0 :
print("哈哈,这次不算再来一次吧!")
if user == 0 and computer == 1 :
print("哈哈,你赢了!)")
if user == 0 and computer ==2 :
print("哈哈,你输了!")
elif user == 1 and computer == 0 :
print("哈哈,你赢了!")
if user==1 and computer == 1 :
print("哈哈,这次不算再来一次吧!")
if user == 1 and computer == 2:
print("哈哈,你输了!")
else :
if user == 2 and computer ==0 :
print("哈哈,你输了!")
if user ==2 and computer == 1:
print("哈哈,你赢了!")
if user ==2 and computer ==2:
print("哈哈,这次不算再来一次吧!")
答案二:
优化后的答案,真的是太妙了!!!竟然能想到取余,这是我的一位同学告诉我的方法,真的是太优美了!!!
#用户
user = int(input('请输入:剪刀(0)、石头(1)、布(2):'))
if user == 0 :
chinese = "剪刀"
elif user == 1:
chinese = "石头"
else:
chinese = "布"
print("你的输入为%s(%d)"%(chinese,user))
len=3
#电脑
import random #调用随机库
computer=random.randint(0,2)
print("随机生成数字为%d"%computer)
#判断输赢
if (user+2)%len == computer:
print("哈哈,你赢了!")
elif (user+1)%len == computer:
print("哈哈,你输了!")
else :
print("哈哈,这次不算再来一次吧!")



