my name is ali and I was making a quiz and I wanted to make it so when a question was answered it deletes all previous outputs this is my code
import questions
import sys
import time
import os
#clear console for next question
def cls():
os.system('cls' if os.name=='nt' else 'clear')
# Initialize score
score = 0
print("Quiz started! You get 1 point for each correct answer.\n")
# Question 1
print(questions.q1)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a1.lower():
print("CORRECT!")
score += 1 #add 1 point
print(f"your current score is: {score} point")
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a1)#correct answer
time.sleep(1)
print(f"your current score is: {score} points")
cls()
time.sleep(2)
# Question 2
print(questions.q2)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a2.lower():
print("CORRECT!")
score += 1 #add 1 point
print(f"your current score is: {score} points")
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a2)#correct answer
time.sleep(1)
print(f"your current score is: {score} points")
cls()
time.sleep(2)
# Question 3
print(questions.q3)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a3.lower():
print("CORRECT!")
score += 1 #add 1 point
print(f"your current score is: {score} points")
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a3)#correct answer
time.sleep(1)
print(f"your current score is: {score} points")
cls()
time.sleep(2)
# Question 4
print(questions.q4)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a4.lower():
print("CORRECT!")
score += 1 #add 1 point
print(f"your current score is: {score} points")
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a4)#correct answer
time.sleep(1)
print(f"your current score is: {score} points")
cls()
time.sleep(2)
# Question 5
print(questions.q5)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a5.lower():
print("CORRECT!")
score += 1 #add 1 point
print(f"your current score is: {score} points")
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a5)#correct answer
time.sleep(1)
print(f"your current score is: {score} points")
cls()
time.sleep(2)
# Question 6
print(questions.q6)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a6.lower():
print("CORRECT!")
score += 1 #add 1 point
print(f"your current score is: {score} points")
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a6)#correct answer
time.sleep(1)
print(f"your current score is: {score} points")
cls()
time.sleep(2)
# Question 7
print(questions.q7)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a7.lower():
print("CORRECT!")
score += 1 #add 1 point
print(f"your current score is: {score} points")
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a7)#correct answer
time.sleep(1)
print(f"your current score is: {score} points")
cls()
time.sleep(2)
# Question 8
print(questions.q8)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a8.lower():
print("CORRECT!")
score += 1 #add 1 point
print(f"your current score is: {score} points")
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a8)#correct answer
time.sleep(1)
print(f"your current score is: {score} points")
cls()
time.sleep(2)
# Question 9
print(questions.q9)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a9.lower():
print("CORRECT!")
score += 1 #add 1 point
print(f"your current score is: {score} points")
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a9)#correct answer
time.sleep(1)
print(f"your current score is: {score} points")
cls()
time.sleep(2)
# Question 10
print(questions.q10)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a10.lower():
print("CORRECT!")
score += 1 #add 1 point
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a10)# correct answer
cls()
time.sleep(2)
# Display final score
print("\nQuiz completed!")
print(f"Your final score: {score} points")
sys.exit()
import questions
import sys
import time
import os
#clear console for next question
def cls():
os.system('cls' if os.name=='nt' else 'clear')
# Initialize score
score = 0
print("Quiz started! You get 1 point for each correct answer.\n")
# Question 1
print(questions.q1)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a1.lower():
print("CORRECT!")
score += 1 #add 1 point
print(f"your current score is: {score} point")
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a1)#correct answer
time.sleep(1)
print(f"your current score is: {score} points")
cls()
time.sleep(2)
# Question 2
print(questions.q2)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a2.lower():
print("CORRECT!")
score += 1 #add 1 point
print(f"your current score is: {score} points")
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a2)#correct answer
time.sleep(1)
print(f"your current score is: {score} points")
cls()
time.sleep(2)
# Question 3
print(questions.q3)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a3.lower():
print("CORRECT!")
score += 1 #add 1 point
print(f"your current score is: {score} points")
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a3)#correct answer
time.sleep(1)
print(f"your current score is: {score} points")
cls()
time.sleep(2)
# Question 4
print(questions.q4)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a4.lower():
print("CORRECT!")
score += 1 #add 1 point
print(f"your current score is: {score} points")
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a4)#correct answer
time.sleep(1)
print(f"your current score is: {score} points")
cls()
time.sleep(2)
# Question 5
print(questions.q5)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a5.lower():
print("CORRECT!")
score += 1 #add 1 point
print(f"your current score is: {score} points")
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a5)#correct answer
time.sleep(1)
print(f"your current score is: {score} points")
cls()
time.sleep(2)
# Question 6
print(questions.q6)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a6.lower():
print("CORRECT!")
score += 1 #add 1 point
print(f"your current score is: {score} points")
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a6)#correct answer
time.sleep(1)
print(f"your current score is: {score} points")
cls()
time.sleep(2)
# Question 7
print(questions.q7)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a7.lower():
print("CORRECT!")
score += 1 #add 1 point
print(f"your current score is: {score} points")
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a7)#correct answer
time.sleep(1)
print(f"your current score is: {score} points")
cls()
time.sleep(2)
# Question 8
print(questions.q8)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a8.lower():
print("CORRECT!")
score += 1 #add 1 point
print(f"your current score is: {score} points")
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a8)#correct answer
time.sleep(1)
print(f"your current score is: {score} points")
cls()
time.sleep(2)
# Question 9
print(questions.q9)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a9.lower():
print("CORRECT!")
score += 1 #add 1 point
print(f"your current score is: {score} points")
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a9)#correct answer
time.sleep(1)
print(f"your current score is: {score} points")
cls()
time.sleep(2)
# Question 10
print(questions.q10)
user_answer = input("your answer: ")
if user_answer.lower() == questions.a10.lower():
print("CORRECT!")
score += 1 #add 1 point
time.sleep(2.5)
cls()
time.sleep(1)
else:
print("INCORRECT! The correct answer was:", questions.a10)# correct answer
cls()
time.sleep(2)
# Display final score
print("\nQuiz completed!")
print(f"Your final score: {score} points")
sys.exit()
Statistics: Posted by ali.b — Wed Feb 26, 2025 8:44 pm