废话不多说直接上代码
user_num = int(input("请输入:剪刀:(0)、石头(1)布(2)"))
user = 0
if user_num == 0:
user = "剪刀(0)"
elif user_num == 1:
user = "石头(1)1"
elif user_num == 2 :
user = "布(2)"
print("你的输入为:",user)
import random
computer_num = random.randint(0,2)
print("随机数字为:",computer_num)
if user_num == computer_num:
print("啊哈,是平局!")
elif user_num == 0 and computer_num ==1:
print("你输了")
elif user_num == 0 and computer_num == 2:
print("你赢了")
elif user_num == 1 and computer_num == 0:
print("你赢了")
elif user_num == 1 and computer_num == 2:
print("你输了")
elif user_num == 2 and computer_num == 0:
print("你输了")
elif user_num == 2 and computer_num == 1:
print("你赢了")
怎么说呢这东西就是要注意一下循环逻辑,和判断条件,剩余的也就很简单了。
如果有更好的方法可以再评论区或者邮箱发给作者