##Question 1

def find_median(grades):
    sorted_grades = sorted(grades)
    n = len(sorted_grades)
    
    if n % 2 == 0:
        # If the number of grades is even, take the average of the two middle values
        middle1 = sorted_grades[n // 2 - 1]
        middle2 = sorted_grades[n // 2]
        median = (middle1 + middle2) / 2
    else:
        # If the number of grades is odd, the median is the middle value
        median = sorted_grades[n // 2]
    
    return median

# Example grades
test_grades = [74, 93, 36, 95, 87, 94, 92, 81]
median_grade = find_median(test_grades)
print(f"The median test grade is: {median_grade}")


##Question 2
import random

def higher_or_lower_game():
    current_number = random.randint(1, 100)
    score = 0

    while True:
        print(f"Current number: {current_number}")
        guess = input("Higher (h) or Lower (l) or Quit (q): ").lower()

        if guess not in ['h', 'l', 'q']:
            print("Please enter 'h' for higher, 'l' for lower, or 'q' to quit.")
            continue

        next_number = random.randint(1, 100)

        if (next_number > current_number and guess == 'h') or (next_number < current_number and guess == 'l'):
            score += 1
            current_number = next_number
        else:
            print(f"Game over! Your final score is {score}")
            break

# Play the game
print("Welcome to the Higher or Lower Game!")
higher_or_lower_game()

The median test grade is: 89.5
Welcome to the Higher or Lower Game!
Current number: 32
Game over! Your final score is 0