SHOW:
|
|
- or go back to the newest paste.
1 | - | from ex46module import quest |
1 | + | from ex46module import quest # this module is a dictionary (quest) that are questions as keys and answers as values |
2 | from sys import exit | |
3 | import random | |
4 | ||
5 | #random.sample iterates over the keys in dict quest and returns 1 key | |
6 | ||
7 | keys = random.sample(quest.items(),len(quest)) #passing .items method returns a list w/ key:value pairs | |
8 | ||
9 | # keys is now a list of Tuples that can be iterated over | |
10 | #print random.sample(keys[0],1) # this is taking a random selection either key or value in | |
11 | #in random tuple from keys | |
12 | #k1 = keys[0] # k1 is set to the Tuple in the list generated | |
13 | #str(keys[0]) #since tuple is at index position 0, returns the tuple (as a string) | |
14 | #print k1[0] # returns first value in Tuple, index 0, the key | |
15 | #k1[1] # returns second value in Tuple, index 1, the value | |
16 | ||
17 | ||
18 | def q_and_a(quest): | |
19 | ''' | |
20 | This takes as input a dict of questions /answers, | |
21 | global vars, keys, k1, are loopsd and tested to | |
22 | remove a question that has been used and if ans is correct | |
23 | or wrong. | |
24 | ''' | |
25 | k1 = keys[0] | |
26 | #str(keys[0]) | |
27 | print k1[0] | |
28 | k1[1] | |
29 | ans = raw_input("> ") | |
30 | ||
31 | qlist = [] # empty list to hold questions as selected | |
32 | qcount = len(qlist) # starts at Zero | |
33 | correct_ans_count = 0 | |
34 | ||
35 | # Ans at this point is stuck and is not updating, that's why all answers are correct | |
36 | # How do I update the value for ans? | |
37 | ||
38 | while True: # qcount <= 5: | |
39 | if ans == k1[1]: # or new_ans: # if answer is correct /was while/ | |
40 | print ans, k1[1] | |
41 | qcount += 1 # updates # of questions asked | |
42 | correct_ans_count += 1 # updates # of correct answers | |
43 | print 'That\'s Correct!' | |
44 | print 'You have %d questions to go' %(3 - qcount,) | |
45 | print 'Correct Answers: ',correct_ans_count | |
46 | if correct_ans_count == 3: #ans == k1[1] and #Test if ready to advance to new room | |
47 | print 'Congratulations, on to the next room' | |
48 | return | |
49 | #return next_room | |
50 | else: | |
51 | if ans != k1[1]: | |
52 | print 'Wrong Answer' | |
53 | qcount += 1 | |
54 | print qcount | |
55 | if qcount == 5: | |
56 | exit(1) | |
57 | qlist.append(keys[0]) # append the question to do not use list (qlist) | |
58 | print qlist | |
59 | for i in keys: #next 3 line compare used question to keys and if matched | |
60 | if i in qlist: # ...removes tuple from keys | |
61 | keys.remove(i) | |
62 | - | #return banishment |
62 | + | |
63 | print new_question | |
64 | global ans | |
65 | ans = keys[0][1] | |
66 | print ans | |
67 | new_ans = raw_input("> ") | |
68 | ans = new_ans |