2014-09-22 60 views
-3

我有一組的問題在這裏,我需要隨機的用戶選擇,如果用戶丟失了等待時間需要列表內選擇一個隨機變量

decades = 100 
ans = 0 

ans = int (input ("halves of 40 = ")) 
if ans == 20: 
    print ans, " is a right ans good job!" 
else: 
    print ans, "is a Wrong ans best of luck for next quation." 
ans = int (input ("halves of 10 = ")) 
if ans == 5: 
    print ans, " is a right ans good job!" 
else: 
    print ans, "is a Wrong ans best of luck for next quation." 
ans = int (input ("halves of 90 = ")) 
if ans == 45: 
    print ans, " is a right ans good job!" 
else: 
    print ans, "is a Wrong ans best of luck for next quation." 
ans = int (input ("halves of 20 = ")) 
if ans == 10: 
    print ans, " is a right ans good job!" 
else: 
    print ans, "is a Wrong ans best of luck for next quation." 
ans = int (input ("halves of 80 = ")) 
if ans == 40: 
    print ans, " is a right ans good job!" 
else: 
    print ans, "is a Wrong ans best of luck for next quation." 
ans = int (input ("halves of 30 = ")) 
if ans == 15: 
    print ans, " is a right ans good job!" 
else: 
    print ans, "is a Wrong ans best of luck for next quation." 

ans = int (input ("halves of 100 = ")) 
if ans == 50: 
    print ans, " is a right ans good job!" 
else: 
    print ans, "is a Wrong ans best of luck for next quation." 

ans = int (input ("halves of 60 = ")) 
if ans == 30: 
    print ans, " is a right ans good job!" 
else: 
    print ans, "is a Wrong ans best of luck for next quation." 
ans = int (input ("halves of 50 = ")) 
if ans == 25: 
    print ans, " is a right ans good job!" 
else: 
    print ans, "is a Wrong ans best of luck for next quation." 
ans = int (input ("halves of 70 = ")) 
if ans == 35: 
    print ans, " is a right ans good job!" 
else: 
    print ans, "is a Wrong ans best of luck for next quation." 
+3

聽起來不錯,你有問題嗎? – EdChum 2014-09-22 07:53:52

+0

我需要隨機選擇其中一個問題以便遊戲按照要求運行 – 2014-09-22 07:57:01

+1

@EdChum,仔細閱讀,他有一組問題 – Elisha 2014-09-22 07:57:09

回答

0

你可能想要做這樣的事情即:

import random 
tries = 10 
questions = [("halves of 40 = ",20), 
      ("halves of 10 = ",5), 
      ("halves of 90 = ",45), 
      ("halves of 20 = ",10), 
      ("halves of 80 = ",40), 
      ("halves of 30 = ",15), 
      ("halves of 100 = ",50)] 

for i in xrange(tries): 
    q = random.choice(questions) 
    ans = int (input (q[0])) 
    if ans == q[1]: 
     print ans, " is a right ans good job!" 
    else: 
     print ans, "is a Wrong ans best of luck for next quation."