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

Image of Bright Data

Maintain Seamless Data Collection – No more rotating IPs or server bans.

Avoid detection with our dynamic IP solutions. Perfect for continuous data scraping without interruptions.

Avoid Detection

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay