emmm为什么这里运行的结果只会出现一种,比如prize[0] and prize[1],只出现prize[1...
import randomprize = ["金币","钻石","一日体验卡","皮肤体验卡","限定皮肤","新品英雄"]
i = 3
summary = 0
while i:
a = random.randint(0,2)
summary = summary + a
i -= 1
continue
if summary == 6:
print(prize and prize)
elif 3 <= summary < 6:
print(prize and prize)
else:
print(prize and prize) 事实上,用了or也不行
打印多个内容需要用逗号分隔,不能用 and,and 属于逻辑操作符:
import random
prize = ["金币", "钻石", "一日体验卡", "皮肤体验卡", "限定皮肤", "新品英雄"]
i = 3
summary = 0
while i:
a = random.randint(0, 2)
summary = summary + a
i -= 1
continue
if summary == 6:
print(prize, prize)
elif 3 <= summary < 6:
print(prize, prize)
else:
print(prize, prize) zltzlt 发表于 2020-7-20 17:05
打印多个内容需要用逗号分隔,不能用 and,and 属于逻辑操作符:
如果想让prize与prize随机出现,那是需要重设条件吗 宅之御坂 发表于 2020-7-20 17:08
如果想让prize与prize随机出现,那是需要重设条件吗
不用,这样即可:
import random
prize = ["金币", "钻石", "一日体验卡", "皮肤体验卡", "限定皮肤", "新品英雄"]
i = 3
summary = 0
while i:
a = random.randint(0, 2)
summary = summary + a
i -= 1
continue
if summary == 6:
print(prize) # 从 prize 和 prize 之中随机选择一个
elif 3 <= summary < 6:
print(prize) # 从 prize 和 prize 之中随机选择一个
else:
print(prize) # 从 prize 和 prize 之中随机选择一个
页:
[1]