我做了一个Python测验,大约有500行。我想知道如何使其更短并简化代码。这是我在测验中的一个问题的示例
while counter<3:
def question(question,choices):
print(question)
for question in choices:
print(question)
print('\033[0m'"____________________________________________________________\n")
question("Question 1. What is the real name of Batman?", ["A. Bruce Wayne", "B. Peter Parker", "C. Bruce Banner", "D. Bruce Waine"])
answer = input().lower()
if answer == "a":
print('\033[32m'"\nNice job! ✔\n")
score = score +1
counter = 4
elif answer == "bruce wayne":
print('\033[32m'"\nGreat work! ✔\n")
counter = 4
break
else:
score = score - 1
counter = counter +1
if counter ==3:
print('\33[31m'"\nIncorrect! ✘ The correct answer is A. Bruce Wayne\n")
elif counter ==1 or 2:
print('\33[31m'"\nIncorrect! ✘ Try again...\n")
print('\033[0m''\033[04m'"Your score is ",score)
炎炎设计
相关分类