python - (Basic) Errors with questionare -
i'm new python , i'm trying code work. can make basic programs , feel i'm out of depth! if think there way can open suggestions. here code:
import time right = 0 again = 0 name = 0 wrong = 0 questionnumber = 0 questions = [ {'text': 'what population of new zealand?', 'choices': ('6.7m', '3.2m', '5.1m', '4.5m'), 'answer': {'d', '4.5m'}, }, {'text': 'what year did first european set foot on ' 'new zealand? (abel tasman)', 'choices': ('1830', '1543', '1642', '1765'), 'answer': {'c', '1642'}, }, {'text': 'how high mt cook new zealand?', 'choices': ('3,724m', '4,272m', '3,893m', '2,280m'), 'answer': {'a', '3724'}, }, {'text': 'what biggest lake in new zealand?', 'choices': ('taupo', 'te anau', 'wanaka', 'wakatipu'), 'answer': {'a', 'taupo'}, }, {'text': 'what percentage of new zealands population maori?', 'choices': ('25%', '45%', '10%', '15%'), 'answer': {'d', '15'}, }, ] print("please enter name") name = input() def questionask(question): global right, wrong, questions, questionnumber, name print(question['text']) in questions: print(chr(i+ord('a')) + ': ', choice) return input('> ').upper() in question['answer'] question in questions: if questionask(question): print ("right") right = right + 1 questionnumber = questionnumber + 1 print() print("so far",name,"you have got",right,"answers right,",wrong,"answers wrong , have completed",questionnumber,"questions") print() else: print ("wrong") wrong = wrong + 1 questionnumber = questionnumber + 1 print() print("so far",name,"you have got",right,"answers right,",wrong,"answers wrong , have completed",questionnumber,"questions") print() print("well done",name,"! have completed questionare! have got",right,"out of possible 10 questions correct and",wrong,"you have completed",questionnumber,"questions!") print() print() print("do want play again?") print("y: yes") print("n: no") again = input()
and heres error:
traceback (most recent call last): file "c:/users/jason/downloads/python.py", line 44, in <module> if questionask(question): file "c:/users/jason/downloads/python.py", line 39, in questionask print(chr(i+ord('a')) + ': ', choice) typeerror: unsupported operand type(s) +: 'dict' , 'int'
thanks help! if have better way of creating questionnaire open suggestions!
kind regards, user
change loop in function questionask way:
for i,choice in enumerate(question['choices']): print(chr(i+ord('a')) + ': ', choice)
Comments
Post a Comment