나는 농업에 대한 기본적인 3 가지 퀴즈를 만들어야합니다. 3 가지 질문을하고, 답이 맞는지 틀린지를 출력하고, 틀린 경우 다시 시도 할 수 있습니다. 또한 점수 기능이 있어야합니다. 내가 질문을 완료하고 사양의 부정확 한/올바른 부분을하지만 내가 뭘하려고해도 나는 점수 기능을 작동시키지 못한다. 나는 시도했다 : 다음퀴즈 득점 기능이 필요합니다.
score = 0
def counter(score)
score = score + 1
def counter(score)
score = 0
score = score + 1
def counter(score)
global score
score = 0
score = score + 1
와 다음 대답은 정확했다 일단 라인이 읽어 :
counter(score)
가 나는 또한
score = 0
다음
score = score + 1
을
을 시도 하지만 아무것도 작동하지 않으며 나는 어떤 일이 잘못되고 있는지 알아 봅니다. 또한 사용자가 마지막에 얼마나 많은 사용자를 확보했는지 인쇄해야합니다.CODE :
는score = 0
def quiz():
print("Here is a quiz to test your knowledge of farming...")
print()
print()
print("Question 1")
print("What percentage of the land is used for farming?")
print()
print("a. 25%")
print("b. 50%")
print("c. 75%")
answer = input("Make your choice: ")
if answer == "c":
print("Correct!")
score = score + 1
else:
print("Incorrect.")
answer = input("Try again! ")
if answer == "c":
print("Correct")
score = score + 1
else:
print("Incorrect! Sorry the answer was C.")
print()
print()
print("Question 2")
print("Roughly how much did farming contribute to the UK economy in 2014.")
print()
print("a. £8 Billion.")
print("b. £10 Billion.")
print("c. £12 Billion.")
answer = input("Make your choice: ")
if answer == "b":
print("Correct!")
score = score + 1
else:
print("Incorrect.")
answer = input("Try again! ")
if answer == "b":
print("Ccrrect!")
score = score + 1
else:
print("Incorrect! Sorry the answer was B.")
print()
print()
print("Question 3.")
print("This device, which was invented in 1882 has revolutionised farming. What is it called?")
print()
print("a. Tractor")
print("b. Wagon.")
print("c. Combine.")
answer == input("Make your choice. ")
if answer == "a":
print("Correct!")
score = score + 1
else:
print("Incorrect.")
answer == input("Try again! ")
if answer == "a":
print("Correct!")
score = score + 1
else:
print("Incorrect! Sorry the answer was A.")
print("You got {0}/3 right!".format(score))
'def'아래의 모든 것이 들여 쓰기되어야합니다. – elethan
힌트 : [함수는 무언가를 반환 할 수 있습니다.] (https://learnpythonthehardway.org/book/ex21.html). – LaundroMat
파이썬 코드를 게시하는 경우 들여 쓰기를 정확하게 재현해야합니다. 심하게 들여 쓰여진 파이썬 코드는 난센스 다. – khelwood