import random, os # Import random for generating numbers, os for clearing the screen
# Function to clear the terminal screen (Windows or Unix-based systems)
def clear_screen():
os.system("cls" if os.name == "nt" else "clear")
# Main function to handle flashcards logic
def add_flashcards(right=0, wrong=0):
clear_screen() # Clear screen at the beginning of each round
# Generate two random numbers between 0 and 10
card_one = random.randint(0, 10)
card_two = random.randint(0, 10)
correct = card_one + card_two # Calculate the correct answer
# Ask the user to solve the addition problem
answer = input(f"{card_one} + {card_two} = ")
# Check if the user's answer is correct
if int(answer) == correct:
print(f"Correct! You're right. This is {correct}")
right += 1 # Increment correct counter
else:
print(f"Wrong! Addition should return a result {correct}")
wrong += 1 # Increment incorrect counter
# Display the current score
score = f"\nRight: {right}. Wrong: {wrong}"
print(score)
# Ask if the user wants to continue
play = input("Would you like another card? (yes|no|restart): ")
if play.lower() in ["y", "yes"]:
# Continue with current score
add_flashcards(right, wrong) # <-- Fix here
elif play.lower() in ["r", "res", "restart"]:
# Restart score from zero
add_flashcards(right=0, wrong=0)
else:
# End game
clear_screen()
print(f"\nYour final score: {score}", "\nThanks for playing!")
return
# Run the game only if this script is executed directly
if __name__ == "__main__":
add_flashcards()