学习目标:
1. 掌握如何加载random包,以及生成随机数
2. 掌握if、elif、else语句的使用
代码展示:
import random
u = int(input("请输入剪刀(0),石头(1),布(2):"))
s = random.randint(0,2) #电脑生成随机数0、1、2
if (u == 0) and (s == 2) or (u == 1) and (s == 0) or (u == 2) and (s == 1):
print("你赢了")
elif u == s:
print("平局")
else:
print("你输了")
如果小伙伴有不同的答案,或者问题可以在评论区留言哦!