DEV Community

Cover image for Letter Grade Converter Function
Scott Gordon
Scott Gordon

Posted on

2 1

Letter Grade Converter Function

# letter_grade_converter_function.py
#   This program accepts an exam score as input and prints out
#   the corresponding grade using a function.
# by: Scott Gordon

def main():
    # Write welcome message.
    print("***** Welcome to The Letter Grade Calculator *****")

    # Get input from user and assign it to score variable.

    score = int(input("Enter your exam score: "))

    def letter_grade_converter(score):

        # Use branching control statements to associate the score
        #       with the letter grade.
        letter_grade = ""
        if score < 60:
            letter_grade = "F"
        elif score < 70:
            letter_grade = "D"
        elif score < 80:
            letter_grade = "C"
        elif score < 90:
            letter_grade = "B"
        elif score < 100:
            letter_grade = "A"

        # Print out the corresponding grade.
        return f"Your letter grade is {letter_grade}."

    print(letter_grade_converter(score))


main()
Enter fullscreen mode Exit fullscreen mode

Photo by Kimberly Farmer on Unsplash

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay