-3

选择 = 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!")

input("按回车键退出:")

4

1 回答 1

4

您的条件被解析为

(pick == 4) or (6) or (12)

这总是正确的,因为三项(即 6 和 12)中至少有一项是正确的。

你要

if pick==4 or pick==6 or pick==12

或更简单地说

if pick in [4,6,12]
于 2013-10-10T15:05:58.200 回答