I am attempting to ask a question, have the user input the answer. The program has to check the user's answer against the correct answer than keep score. I am having difficulties formatting the while and if statements and reading the lines from the text file.
Quiz Game
def main():
print("\t\tWelcome to Bible Champion!\n "
"It can be difficult to remember the characters of the bible.\n "
"Bible Champion makes it fun and easy with trivia "
"style questions!\n")
name =(input("Please enter your first name to get started: "))
print()
name1 = name[1:] + name[0] + "ay" + "7"
print("Here is player one's game name:",name1,"\n")
qf= open("quiz_game.txt", "r")
for i in range(2):
print (qf.readline())
user_ans = str(input())
while user_ans[0] =="a" or user_ans[0] == "a.":
print ("Correct")
break
if user_ans[0] =="b" or user_ans[0] == "b.":
print ("Incorrect")
if user_ans[0] =="c" or user_ans[0] == "c.":
print ("Incorrect")
if user_ans[0] =="d" or user_ans[0] == "d.":
print ("InCorrect")
qf= open("quiz_game.txt", "r")
for i in range(4):
print (qf.readline())
user_ans = str(input())
while user_ans[0] =="a" or user_ans[0] == "a.":
print ("Correct")
break
if user_ans[0] =="b" or user_ans[0] == "b.":
print ("Incorrect")
if user_ans[0] =="c" or user_ans[0] == "c.":
print ("Incorrect")
if user_ans[0] =="d" or user_ans[0] == "d.":
print ("InCorrect")
qf.close()
main()
Here is what I have so far.
Here is the update output. How do i make it score the first answer and continue to the next set of questions and answers?
==========================================================
== Welcome to Bible Champion! ==
== It can be difficult to remember the characters of the bible. ==
== Bible Champion makes it fun and easy with trivia style questions! ==
===========================================================
Please enter your first name to get started: kok
Here is player one's game name: okkay7
(1)Which bible character had strength in his hair?
a. Samuel b. Peter c.Samson d.John
a
Incorrect
(1)Which bible character had strength in his hair?
a. Samuel b. Peter c.Samson d.John
c
(2)King David danced out of his ______?
Updated?
How do I read for instance only line 3 and 4 from the text into python?
I tried using this:
print qf.readline()[0:2]
but it gave me an error.