Python 如何使变量应用于多个数字

Python 如何使变量应用于多个数字,python,Python,选择=4、6和12谢谢 import random print("Are you feeling lucky today?") loop='y' while loop=='y': pick=int(input("Select your dice(4,6,12) then press enter:")) if pick in [4,6,12]: print("The "+str(pick) +" sided dice was thrown and your sc

选择=4、6和12谢谢

import random 
print("Are you feeling lucky today?")
loop='y'
while loop=='y':
    pick=int(input("Select your dice(4,6,12) then press enter:"))
    if pick in [4,6,12]:
         print("The "+str(pick) +" sided dice was thrown and your score is "+str(random.randint(1,pick)))
else:
    print("Invalid number. You are meant to select a 4, 6 or 12 sided dice!")
loop=input('Dare to go again?(y/n)?')
if loop=='n':
    print("Thanks for playing!")

输入(“按enter键退出:”)

您的条件被解析为

(pick == 4) or (6) or (12)
这总是正确的,因为三个项目(即6和12)中至少有一个是正确的

你想要

if pick==4 or pick==6 or pick==12
或者更简单地说

if pick in [4,6,12]

我想说的可能的重复是,当运行时pick=4和6,12只对4起作用,我不希望它也对6和12起作用