# Initialize an empty list to store the final grades
grade_list = []

# Loop exactly 3 times to collect grades for 3 subjects
for i in range(3):
    # loop runs until valid numerical input is provided
    while True:
        try:
            # Get user input and immediately convert it to an integer
            marks = int(input(f"Enter your marks for subject {i+1}:\n"))
            
            # Validate that the score is realistic (between 0 and 100)
            if 0 <= marks <= 100:
                break
            print("Invalid input. Marks must be between 0 and 100.")
        except ValueError:
            # Prevents program crash if user types letters instead of numbers
            print("Invalid input. Please enter a valid whole number.")

    # Determine the grade based on the verified marks
    if marks < 40:
        grade = 'D'
    elif marks < 60:
        grade = 'C'
    elif marks < 80:
        grade = 'B'
    else:
        grade = 'A'

    # Display the results using an f-string for cleaner formatting
    print(f"Your grade is: {grade}\n")
    
    # Save the determined grade to the list
    grade_list.append(grade)

# Display the complete list of grades after processing all inputs
print("Final Grade List:", grade_list)