What you have so far looks OK. The files that you are reading must be in the same directory as this module. You must read the gray writing on the background of the post window or the "Posting Guidelines" on the right or at the top of this forum to learn how to use CODE TAGS so that your post looks like this:
-
-
# Read number and question from a file into a dict
-
questionFile = open('questions.txt')
-
numberQuestionDictionary = {}
-
for line in questionFile.readlines():
-
if not line:
-
continue
-
line = line.strip()
-
if len(line) == 0:
-
continue
-
numberAndQuestion = line.split('.')
-
number = numberAndQuestion[0]
-
question = numberAndQuestion[1].strip()
-
numberQuestionDictionary[number] = question
-
questionFile.close()
-
# Read number and answer from a file into a dict
-
answerFile = open('answers.txt')
-
numberAnswerDictionary = {}
-
for line in answerFile.readlines():
-
if not line:
-
continue
-
line = line.strip()
-
if len(line) == 0:
-
continue
-
numberAndAnswer = line.split('.')
-
number = numberAndAnswer[0]
-
answer = numberAndAnswer[1].strip()
-
numberAnswerDictionary[number] = answer
-
answerFile.close()
-
-
for number in numberQuestionDictionary.keys():
-
print 'Q: ',
-
print numberQuestionDictionary[number]
-
print 'A: ',
-
print numberAnswerDictionary[number]
-
print
-
We'll also need a copy of the text files that you are trying to read. Thanks for posting,
Barton