So i have a recent python project and i'm struggling a little, if anyone could be of any assistance that would be great :). The project is to make a 'Flash Cards' type quiz within which i am required to make a random generator to import one randomly chosen keyword with three randomly selected definitions containing one correct answer. If they select the correct answer then a success message is displayed, after every keyword is done twice the program will end. I thaught i could make a tickoff for each time a keyword is presented but the whole random generator has got me confuzed. Would be awesome if anyone could help me or at least point me in the right direction.:D

So far this is something i've thaught of :s

import random

name = input("What is your name? ")
in_file = open("keywords.txt", "rt")

Q1_tickoff = 2
Q2_tickoff = 2
Q3_tickoff = 2
Q4_tickoff = 2
Q5_tickoff = 2
Q6_tickoff = 2
Q7_tickoff = 2
Q8_tickoff = 2
Q9_tickoff = 2
Q10_tickoff = 2


print("Hey there, this is a 'Flash Cards' quiz. So, Ready " + name + "? Here comes the first question :)")
T = True
while T == True:
    randomQ = random.randint(0,15)

Recommended Answers

All 2 Replies

You could use a dictionary like ...

d = {
'kw1' : [def1, def2, def3, ix],
'kw2' : [def1, def2, def3, ix],
'kw2' : [def1, def2, def3, ix],
...
}

Where keys kw1, kw2, ... are the keywords and values are a list of definitions for each keyword, and the index number ix being the correct definition in each list.

You can create a list of the dictionary keys (keywords) with d.keys() and random.shuffle the keyword list.

Learn about lists, do not use unique variables.

You are not generating the random number yourself like you said, but using the random.randint.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.