Block B


def letter(n):
    """prec: n is an integer 
    postc:  returns A if 90 or higher, B if 80 or higher, usw"""
    if n >= 90:
        return "A"
    if n >= 80:
        return "B"
    if n >= 70:
        return "C"
    if n >= 60:
        return "D"
    return "F"
def modifier(n):
    """prec: n is an integer
    postc:  if n < 60:  returns ""
    if last digit is 0, 1, 2, returns a -
    if last digit is 7 8 or 9, returns a +"""
    if n < 60:
        return ""
    if n  >= 100:
        return "+"
    last_digit = n%10
    if last_digit <= 2:
        return "-"
    if last_digit >= 7:
        return "+"
    return ""
def grade(n):
    return letter(n) + modifier(n)

def main():
    n = 58
    print(f"Case n = {n}" + "PASS" if grade(n) == "F" else "FAIL")
    n = 61
    print(f"Case n = {n}" + "PASS" if grade(n) == "D-" else "FAIL")
    n = 65
    print(f"Case n = {n}" + "PASS" if grade(n) == "D" else "FAIL")
    n = 69
    print(f"Case n = {n}" + "PASS" if grade(n) == "D+" else "FAIL")
    n = 71
    print(f"Case n = {n}" + "PASS" if grade(n) == "C-" else "FAIL")
    n = 75
    print(f"Case n = {n}" + "PASS" if grade(n) == "C" else "FAIL")
    n = 79
    print(f"Case n = {n}" + "PASS" if grade(n) == "C+" else "FAIL")
    n = 81
    print(f"Case n = {n}" + "PASS" if grade(n) == "B-" else "FAIL")
    n = 85
    print(f"Case n = {n}" + "PASS" if grade(n) == "B" else "FAIL")
    n = 89
    print(f"Case n = {n}" + "PASS" if grade(n) == "B+" else "FAIL")
    n = 91
    print(f"Case n = {n}" + "PASS" if grade(n) == "A-" else "FAIL")
    n = 95
    print(f"Case n = {n}" + "PASS" if grade(n) == "A" else "FAIL")
    n = 99
    print(f"Case n = {n}" + "PASS" if grade(n) == "A+" else "FAIL")
    n = 100
    print(f"Case n = {n}" + "PASS" if grade(n) == "A+" else "FAIL")
    n = 102
    print(f"Case n = {n}" + "PASS" if grade(n) == "A+" else "FAIL")
if __name__ == "__main__":
    main()

Here is our app that uses our grade-assigning function.


import skinner
def my_round(n):
    """prec:  n is a floating-point string
post:  returns an integer that is the result of parsing and rounding the string"""
    n = float(n)
    frac = n - int(n)
    if frac < .5:
        return int(n)   #round down
    return 1 + int(n)   #round up

grade = input("Enter a percentage:  ")
print(f"The grade for {grade} is {skinner.grade(my_round(grade))}.")