-3

I have a set of questions here that I need to randomly select for the user and if the user loses a waiting time is required

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."
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • 3
    That sounds great, do you have a question? – EdChum Sep 22 '14 at 07:53
  • i need to randomly select one of the questions in order for the game to function as required to do so – Sunny Singh Sep 22 '14 at 07:57
  • 1
    @EdChum, read carefully, he have set of questions – Elisha Sep 22 '14 at 07:57
  • @EdChum do you know how to write a code that would randomly select one of the questions within the code – Sunny Singh Sep 22 '14 at 07:58
  • See related: http://stackoverflow.com/questions/22732330/selecting-a-random-number-within-a-seriespython?rq=1 and this:http://stackoverflow.com/questions/306400/how-do-i-randomly-select-an-item-from-a-list-using-python?rq=1 – EdChum Sep 22 '14 at 08:07

1 Answers1

0

you might want to do something like that:

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."
Elisha
  • 4,811
  • 4
  • 30
  • 46