Avoid repetitive answer in python

user93097373

I am making a flash card program to help me memorize python keywords and terms. but sometimes it repeat the answer for me which is obvious to anyone to guess.

What is: Exception 1- Another name for runtime error 2- Another name for runtime error 3- The meaning of a program

So how do I avoid this repetitive ?

while count < 10:
os.system('clear')
wordnum = random.randint(0, len(F1c)-1)
print "What is:  ", F1c[wordnum], ""
options = [random.randint(0,len(F2c)-1),random.randint(0,len(F2c)-1),
random.randint(0,len(F2c)-1)]
options[random.randint(0, 2)] = wordnum
print '1 -', F2c[options[0]],
print '2 -', F2c[options[1]],
print '3 -', F2c[options[2]],
answer = input('\nYou  choose number ?:')
if options[answer-1] == wordnum:
    raw_input('\nCorrect! Hit enter...')
    score = score + 1
else:
    raw_input('\nWrong! Hit enter...')
count = count + 1
print '\nYour score is:', score
Suor

Right now you do nothing to ensure that second and third selected option won't clash with first. In order to do so you can remove first chosen option from list before choosing second, and so on.

However, there is function in python standard library that already implements carefully selecting several items from a list:

answers = random.sample(F2c, 3)

Or to select indexes:

options = random.sample(range(len(F2c)), 3)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related