选择列表中的随机变量

时间:2014-09-22 07:52:21

标签: python random

我在这里有一组问题,我需要随机选择用户,如果用户需要等待时间

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."

1 个答案:

答案 0 :(得分: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."