Untitled

 avatar
unknown
plain_text
21 days ago
1.4 kB
0
Indexable
import random

# Define the notes and corresponding keys in an octave
notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
key_positions = {
    "C": 0, "C#": 1, "D": 2, "D#": 3, "E": 4, "F": 5,
    "F#": 6, "G": 7, "G#": 8, "A": 9, "A#": 10, "B": 11
}

# Game variables
correct_streak = 0
goal_streak = 100

def play_game():
    global correct_streak
    
    while correct_streak < goal_streak:
        # Pick a random note
        target_note = random.choice(notes)
        print(f"Identify the note: {target_note}")
        
        # Ask the user to select the correct key
        user_input = input("Which key corresponds to this note? (Enter a note like 'C', 'D#', etc.): ").strip()

        if user_input == target_note:
            correct_streak += 1
            print(f"Correct! Streak: {correct_streak}/{goal_streak}")
        else:
            correct_streak = 0
            print(f"Wrong answer! Streak reset. Try again!")
        
        # If the user reaches the goal streak, they win
        if correct_streak == goal_streak:
            print("Congratulations, you've won! You reached 100 correct answers in a row!")
            break

# Start the game
if __name__ == "__main__":
    print("Welcome to the Piano Key Learning Game!")
    print("Your goal is to answer 100 piano key names correctly in a row.")
    print("Good luck!\n")
    
    play_game()
Leave a Comment