Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from ex46module import quest # this module is a dictionary (quest) that are questions as keys and answers as values
- from sys import exit
- import random
- #random.sample iterates over the keys in dict quest and returns 1 key
- keys = random.sample(quest.items(),len(quest)) #passing .items method returns a list w/ key:value pairs
- # keys is now a list of Tuples that can be iterated over
- #print random.sample(keys[0],1) # this is taking a random selection either key or value in
- #in random tuple from keys
- #k1 = keys[0] # k1 is set to the Tuple in the list generated
- #str(keys[0]) #since tuple is at index position 0, returns the tuple (as a string)
- #print k1[0] # returns first value in Tuple, index 0, the key
- #k1[1] # returns second value in Tuple, index 1, the value
- def q_and_a(quest):
- '''
- This takes as input a dict of questions /answers,
- global vars, keys, k1, are loopsd and tested to
- remove a question that has been used and if ans is correct
- or wrong.
- '''
- k1 = keys[0]
- #str(keys[0])
- print k1[0]
- k1[1]
- ans = raw_input("> ")
- qlist = [] # empty list to hold questions as selected
- qcount = len(qlist) # starts at Zero
- correct_ans_count = 0
- # Ans at this point is stuck and is not updating, that's why all answers are correct
- # How do I update the value for ans?
- while True: # qcount <= 5:
- if ans == k1[1]: # or new_ans: # if answer is correct /was while/
- print ans, k1[1]
- qcount += 1 # updates # of questions asked
- correct_ans_count += 1 # updates # of correct answers
- print 'That\'s Correct!'
- print 'You have %d questions to go' %(3 - qcount,)
- print 'Correct Answers: ',correct_ans_count
- if correct_ans_count == 3: #ans == k1[1] and #Test if ready to advance to new room
- print 'Congratulations, on to the next room'
- return
- #return next_room
- else:
- if ans != k1[1]:
- print 'Wrong Answer'
- qcount += 1
- print qcount
- if qcount == 5:
- exit(1)
- qlist.append(keys[0]) # append the question to do not use list (qlist)
- print qlist
- for i in keys: #next 3 line compare used question to keys and if matched
- if i in qlist: # ...removes tuple from keys
- keys.remove(i)
- new_question = keys[0][0] # selects new question
- print new_question
- global ans
- ans = keys[0][1]
- print ans
- new_ans = raw_input("> ")
- ans = new_ans
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement