mardi 31 mars 2015

How can i compare the arrays userResponse and correctAnswers in the gradeAnswers function. It is the only pary not functioning properly


def main():

correctAnswers = ['B','D','A','A','C',
'A','B','A','C','D',
'B','C','D','A','D',
'C','C','B','D','A']

userResponse = userAnswers()
correct = gradeAnswers(correctAnswers, userResponse)
passFail(correct)


#function to obtain the users input for answers and put in an array
def userAnswers():

answers = 1

userResponse = ['','','','','','','','','','',
'','','','','','','','','','',]

for answers in range (20):
print('What is the answer to number ',\
answers + 1, '? ',sep='',end='')
userResponse[answers] = str(input())


print(userResponse)
return userResponse




#function to calculates the amount of correct answers and displays such
def gradeAnswers(correctAnswers, userResponse):
correct = 1
incorrect = 0
index = 1
for correct in range (20):

if userResponse[correct] == correctAnswers[index]:
index += 1
correct += 1**




print('You answered',correct, 'out of 20 questions correctly')

return correct***


#function to determine and display wether the user passed or failed
def passFail(correct):

if correct >= 15:
print('You passed. Good Job')
else:
print('You failed. Do Better')



main()

Aucun commentaire:

Enregistrer un commentaire