详见以下代码
import random
yue=0;ri=0;ri_1=0;ri_2=0;shi=0;fen=1;loops=0;outnumber=0
while outnumber==0:
if yue==9 and ri==15 and shi==1 and fen==0:
loops = str(loops)
outnumber += 1
else:
yue = random.randint(1,12)
if yue==1 or 3 or 5 or 7 or 8 or 10 or 12:
ri_1 = random.randint(1,31)
ri = ri_1
else:
ri_2 = random.randint(1,30)
ri = ri_2
shi = random.randint(1,24)
fen = random.randint(1,60)
loops += 1
print('\n你用了'+loops+'次才找到正确答案')