results.txt:
Name: Luka Sporcic, Points: 2
Name: Ivan Smilovic, Points: 5
Name: Dominik Tkalcec, Points: 4
expected print:
Name: Ivan Smilovic, Points: 5
Name: Dominik Tkalcec, Points: 4
Name: Luka Sporcic, Points: 2
code:
print ("Welcome to quiz")
name = ""
while(name==""):
name = raw_input("Type your name: ")
filequestions = open("questions.txt")
questions=[]
correctanswers={}
questansw =""
for line in filequestions:
if "Answer" not in line:
questansw+= line
else:
questions.append(questansw)
correctanswers[questansw]=line.strip().replace("Answer","").strip()
questansw= ""
print("\n")
score = 0
for question in questions:
answer= raw_input(question + "\Answer: " )
if(answer== correctanswers[question]):
score+=1
print(name + ", your result is: " + str(score) + ".\nYou want to archive your result? Y/N")
storage = raw_input()
if storage.upper()=="Y":
fileResult = open("results.txt", "a")
fileResult.write("Name: "+ name +", Points: " +str(score) + "\n")
I need help. How to print sorted by the number of the points(Hall of fame) from results.txt? Application is quiz. Questions are in questions.txt in this format:
What color are cherries?
a)red
b)blue
c)green
Answera
Koja životinja živi u moru
a)horse
b)jellyfish
c)elephant
Answerb
Comments
Post a Comment