Pretty much just a programming hobbyist. Recently been trying to up my programming game by shortening my code. Arrays would really help with that for this example, but I still haven't gotten them locked in yet.
Below I made homemade quiz. If you run the script you'll see it will prompt the question for you to answer. Then, tell you if it is correct or incorrect upon answering. The problem I can't solve is my variable "correct" outputs zero regardless of my if statements in the functions. I defined it as zero to start somewhere but don't understand why it isn't adding to the final statement.
Any help would be appreciated. Code below:
correct = 0
def answerA():
if answer == 'a':
correct = 0
correct += 1
print("Correct
")
else:
print("Incorrect
")
def answerB():
if answer == 'b':
correct = 0
correct += 1
print("Correct
")
else:
print("Incorrect
")
def answerC():
if answer == 'c':
correct = 0
correct += 1
print("Correct
")
else:
print("Incorrect
")
def answerD():
if answer == 'd':
correct = 0
correct += 1
print("Correct
")
else:
print("Incorrect
")
answer = input("How many stars are in the sky?
A. 100
B. 1000
C.10000
D.Nobody knows.
Answer: ")
answerD()
answer = input("People who chew with their mouth open are what?
A. Nice
B. Detestable
C. Considerate
D. Mannerly
Answer: ")
answerB()
answer = input("which Star wars movie is a movie?
A. Rise of the Sith
B. Skywalker Strikes Back
C. Revenge of the Sith
D. Return of the Emperor
Answer: ")
answerC()
answer = input("Question 3: Which word below is spelled INCORRECTLY?
A. Acommodate
B. Pharaoh
C. Separate
D. Occurrence
Answer: ")
answerA()
print("Answers correct: " + str(correct))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…