198k views
3 votes
Make an algorithm that calculates the arithmetic average of a student's three grades and shows, in addition to the value of the student's average, the message "Approved" if the average is equal to or greater than 6, or the message "Failed" otherwise.

User Simanas
by
7.0k points

1 Answer

4 votes

Here's a simple algorithm in Python that calculates the arithmetic average of a student's three grades and outputs the corresponding message "Approved" or "Failed" based on the average:

# Input the student's three grades

grade1 = float(input("Enter grade 1: "))

grade2 = float(input("Enter grade 2: "))

grade3 = float(input("Enter grade 3: "))

# Calculate the average

average = (grade1 + grade2 + grade3) / 3

# Output the average and the result

if average >= 6:

print("Average: %.1f - Approved" % average)

else:

print("Average: %.1f - Failed" % average)


Here's how the algorithm works:

The user is prompted to input the student's three grades, which are stored as floating-point numbers in the variables grade1, grade2, and grade3.

The average is calculated by adding the three grades together and dividing by 3, and stored in the variable average.

An if statement checks whether the average is greater than or equal to 6. If it is, the message "Average: %.1f - Approved" is printed with the value of the average substituted in place of the %f format specifier. The %.1f format specifier specifies that the average should be printed with one decimal place. If the average is less than 6, the message "Average: %.1f - Failed" is printed in the same format.

User UpTheCreek
by
8.2k points

No related questions found