Use loop, do not repeat code.
answers = [raw_input(q)+'\n' for q in open('questions.txt')]
# save answers to file
with open('answers.txt', 'w') as out:
out.writelines(answers)
if raw_input('Do you want to review your answers? ').lower() in ('yes', 'y'):
with open('answers.txt') as inp:
print inp.read()
questions.txt
What is your name?
What grade are you in?
What is your favorite color?
What is your favorite food?
Who is your favorite band?
pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
still having problems with the program...
Won't go past question three and checking answers section wrong
Dont' know what "Won't go past guestion three" means. On input, on writing, on checking answers? And have you already created the file "few_questions.txt" with the questions in it (that could be the cause of the "won't go past three" problem). You did not say. If not, that is the first thing your program must do. If you know functions, use one function to output the file the first time, a second function to read the file, ask for an answer, and write to the new file, etc. As stated before, use a loop:
print "Please answer these questions."
print
few_Questions = open("few_questions.txt","r")
few_responses = open("few_responses.txt","w")
## Your program does not store the question in the variable to use to write to new file
for rec in few_Questions:
rec = rec.strip()
print rec
response = raw_input ("Enter an answer: ")
response = response.strip()
few_responses.write("%s: %s\n" % (rec, response)) ## delimiter = colon
few_Questions.close()
few_responses.close()
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714