Task:
• Create a text file with 5 questions in it.
• Read each question in from the file.
• Ask the user for their response.
• Create a new text file.
• Write the user’s answers to the text file.
• Ask the user if they’d like to review their answers. If yes, read in their answers from the text file. If no, end the program.
Here is my code...
# November 9, 2011
# A Few Questions
print "Please answer these questions."
print
few_Questions = open("few_questions.txt","r")
print few_Questions.readline()
Ques1 = raw_input ("")
print few_Questions.readline()
Ques2 = raw_input ("")
print few_Questions.readline()
Ques3 = raw_input ("")
print few_Questions.readline()
Ques4 = raw_input ("")
print few_Questions.readline()
Ques5 = raw_input ("")
few_Questions.close()
few_Questions = open("question_answers","w")
few_Questions.write(Ques1+"\t")
few_Questions.write(Ques2+"\t")
few_Questions.write(Ques3+"\t")
few_Questions.write(Ques4+"\t")
few_Questions.write(Ques5+"\t")
few_Questions.close()
answer = raw_input("Would you like to review your answers? Y or N.")
while answer == "Y":
print few_Questions.readline()
My problems are as follows
1st the program doesn't run past my third question in my text file?
2nd I have to press enter twice to get my next question?
3rd cant figure out how to set up Y or N section. How do you set it up with a while loop?
Here are my questions...
What is your name?
What grade are you in?
What is your favorite color?
What is your favorite food?
Who is your favorite band?
Thanks in advance