Advertisement
Guest User

Untitled

a guest
May 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. from random import randint
  2.  
  3. def get_cards(filename):
  4.     """
  5.    Return two lists, questions and answers
  6.    read from a file specified by filename.
  7.    """
  8.     #this assumes the question and answer key are in the same file
  9.     cards = []
  10.     answers= []
  11.     with open(filename, mode='r', encoding='utf-8') as card_file:
  12.         for a_card in card_file:
  13.             cards.append(card_file.split()[0])
  14.             answers.append(card_file.split()[1])
  15.     return cards, answers
  16. cards, answers =get_cards("CARD_FILE_HERE")
  17. used = []
  18. score = 0
  19. stop = False
  20. while stop == False:
  21.     #get card
  22.     draw =  randint(0, len(cards-1))
  23.     used.append(draw)
  24.     print(cards[draw])
  25.     guess = input("What is the answer? ")
  26.     if guess == answers[draw]:
  27.         score += 10
  28.         print("good job your score is now: " + str(score)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement