私は非常にPythonに新しく、このコードを動作させようとしています。私は基本的なプログラムしか作ることができず、私は自分の深みからうまくいっていると感じています!もし私がこれを行うことができる別の方法があると思うなら、私はどんな提案にも開放的です。(基本)questionareのエラー
import time
right = 0
again = 0
name = 0
wrong = 0
questionNumber = 0
questions = [
{'text': 'What is the population of New Zealand?',
'choices': ('6.7m', '3.2m', '5.1m', '4.5m'),
'answer': {'D', '4.5M'},
},
{'text': 'What year did the first european set foot on '
'New Zealand? (Abel Tasman)',
'choices': ('1830', '1543', '1642', '1765'),
'answer': {'C', '1642'},
},
{'text': 'How High is Mt Cook New Zealand?',
'choices': ('3,724m', '4,272m', '3,893m', '2,280m'),
'answer': {'A', '3724'},
},
{'text': 'What is the biggest lake in New Zealand?',
'choices': ('Taupo', 'Te Anau', 'Wanaka', 'Wakatipu'),
'answer': {'A', 'Taupo'},
},
{'text': 'What Percentage of New Zealands population are Maori?',
'choices': ('25%', '45%', '10%', '15%'),
'answer': {'D', '15'},
},
]
print("Please Enter Your Name")
name = input()
def questionAsk(question):
global right, wrong, questions, questionNumber, name
print(question['text'])
for i in questions:
print(chr(i+ord('A')) + ': ', choice)
return input('> ').upper() in question['answer']
for 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 and you 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 and you have completed",questionNumber,"Questions")
print()
print("Well done",name,"! you have completed my Questionare! You have got",right,"Out of a possible 10 questions correct and",wrong,"You have completed",questionNumber,"Questions!")
print()
print()
print("Do you want to play again?")
print("Y: Yes")
print("N: No")
again = input()
そして相続エラー:ここに私のコードがあるあなたの助けのための
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) for +: 'dict' and 'int'
本当にありがとうございました!あなたがこのアンケートを作成するより良い方法を持っているなら、私はどんな提案にもオープンしています!
種類よろしく、 ユーザー関数questionAskでループの
回答の正確さに完全に同意しますが、OPが何が起こっているのかを理解するために、少し詳しく説明してください。 – JohanL