Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

What am I doing wrong?

This program inputs a user score in % and outputs a letter grade.

scale used is

90 or greater is an A

Less than 90 but 80 or greater is a B

Less than 80 but 70 or greater is a C

Less than 70 but 60 or greater is a D

Less than 60 is an F

def convert_grade_to_letter(number_grade): letter_grade = 'F' if number_grade >= 90: letter_grade = 'A' elif number_grade >= 80: letter_grade = 'B' elif number_grade >= 70: letter_grade = 'C' elif number_grade >= 60: letter_grade = 'D'

return letter_grade

def main(): try: number_grade = int(input("Input number grade: ")) number_grade = int(number_grade)

    if number_grade <= 0 or number_grade >= 101:
        raise ValueError("invalid data")
except ValueError as err:
    print("invalid data")

    if number_grade >= 101:
        print("{}".format(err))
    elif number_grade <= -1:
        print("{}".format(err))
    else:
        letter_grade = convert_grade_to_letter(number_grade)
    convert_grade_to_letter(number_grade)
    print("Letter grade: " + letter_grade)

main()

in this program I'm trying to make it so that it only has one output ex. Letter Grade: A invalid data should not pop up when I insert 1000 only invalid data should pop up

boi
boi
14,242 Points

Sean, the details provided here are confusing to understand due to improper formatting, I suggest you repost your question with proper formatting so people can help you out. As for me, repost using proper formatting and I'll make sure you have a solution.

Go Here to learn to format properly