나는 퀴즈를 만들고 있는데 ... 사람들이 얼마나 많은 질문을 대답 할 지 선택할 수 있는지 확인하고 싶습니다. 사용자가 퀴즈 게임을 호스트 할 수있게 해주는 프로그램을 작성하십시오. 신청서에는 짧은 답을 가진 질문 모음이 있습니다. 프로그램은 사용자에게 그들이 게임에 대해 얼마나 많은 질문을하는지 묻습니다. 그런 다음 많은 질문을 무작위로 묻습니다. 사용자가 답변을 입력하면 정답과 맞는지 확인하고 올바른 질문의 수를 추적합니다. 그것은 같은 질문을 두 번 반복하지 않을 것입니다. 모든 질문이 요청을받은, 또는 사용자가 (대답으로 "종료"를 입력하여) 종료되면, 프로그램은 점수를 인쇄 할 질문의 총 수는 주요 문제에나는 T.T 부분 중 하나에 갇혀 누구 도와 줄 수 있습니까?
from random import * #random is a library. we need the randint function from it
def Main() :
Questions = [] # list of all the questions
Answers = [] # list of all the answers
setup(Questions, Answers)
while True :
target = int(input("How many questions do you want to answer? more than 1 and less than 11 "))
if target <= len(Questions) :
break
print("Sorry, I only have ", len(Questions), " in my databank")
# alternate version:
# target = int(input("How many questions do you want to answer? "))
# while target > len(Questions) :
# print("Sorry, I only have ", len(Questions), " in my databank")
# target = int(input("How many questions do you want to answer? "))
#
score = 0
numberAsked = 0
while len(Questions) > 0 :
qnNum = randint(0, len(Questions)-1)
correct = askQuestion(Questions[qnNum], Answers[qnNum])
numberAsked = numberAsked + 1
if correct == "quit" :
break
elif correct :
score=score+1
del Questions[qnNum]
del Answers[qnNum]
reportScore(score, numberAsked)
def reportScore(sc, numAsked) :
print("Thanks for trying my quiz, Goodbye", sc, " questions right out of ", numAsked)
#asks the user a question, and returns True or False depending on whether they answered correctly.
# If the user answered with 'q', then it should return "quit"
def askQuestion (question, correctAnswer):
print(question)
answer = input("your answer: ").lower()
if answer == "quit" :
return "quit"
elif answer == correctAnswer.lower() :
print("Well done, you got it right!")
return True
else :
print("You got it wrong this time!. The correct answer is ", correctAnswer)
return False
# Sets up the lists of questions
def setup(Questions, Answers) :
Questions.append("The treaty of Waitangi was signed in 1901")
Answers.append("FALSE")
Questions.append("Aotearoa commonly means Land of the Long White Cloud")
Answers.append("TRUE")
Questions.append("The Treaty of Waitangi was signed at Parliament")
Answers.append("FALSE")
Questions.append("The All Blacks are New Zealands top rugby team")
Answers.append("TRUE")
Questions.append("Queen Victoria was the reigning monarch of England at the time of the Treaty")
Answers.append("TRUE")
Questions.append("Phar Lap was a New Zealand born horse who won the Melbourne Cup")
Answers.append("TRUE")
Questions.append("God Save the King was New Zealand’s national anthem up to and including during WWII")
Answers.append("TRUE")
Questions.append("Denis Glover wrote the poem The Magpies")
Answers.append("TRUE")
Questions.append("Te Rauparaha is credited with intellectual property rights of Kamate!")
Answers.append("FALSE")
Questions.append("Kiri Te Kanawa is a Wellington-born opera singer")
Answers.append("FALSE")
Main()
무엇이 당신의 질문입니까? – BrenBarn
나는 퀴즈를 만들고 있는데 ... 사람들이 얼마나 많은 질문을하고 싶은지를 선택할 수 있는지 확인하고 싶다. 이것은 파이톤 껍질에서 얻은 결과이다. –
얼마나 많은 질문에 답변 하시겠습니까? 1 초과 11 미만 1 Phar Lap은 뉴질랜드 태생의 말이었습니다. 대답 : 이번에는 잘못되었습니다. 정답은 TRUE입니다. Aotearoa는 일반적으로 긴 흰 구름의 땅을 의미합니다. 답변 : 이번에는 잘못되었습니다. 정답은 TRUE Waitangi 조약은 의회에서 귀하의 답변에 서명했습니다 : 이번에는 잘못 됐어!. 정답은 거짓입니다 키리 테 카나와는 웰링턴에서 태어난 오페라 가수 입니다. 답변 : 이번에는 잘못되었습니다!. 정답은 FALSE입니다. –