python
import random
options = ['石头','剪刀','布']
while True:
user = input("出拳(石头/剪刀/布):")
if user not in options:
continue
bot = random.choice(options)#choice是random工具包里的一个函数,bot是标量,options是从哪里选
print(f"电脑出:{bot}")
if user == bot:
print("平局")
elif(user=="石头" and bot=="剪刀")or(user=="剪刀"and bot=="布")or(user=="布"and bot=="石头"):
print("你赢了!")
else:
print("你输了!")
range(1,10)生成一个从1到10的整序数列,左闭右开:1,2,3,4,5,6,7,8,9
random.choice(列表) = 从列表里随机挑一个
while True 条件永远为真,无限循环,break跳出循环