-2
While True:
    n=turtle.textinput(“”,”write your grade”)
    grade = int(n)

    while int(n) != grade :
        n=turtle.textinput(“”,”use only number”)
        grade = int(n)

    If grade <=100 and grade>=95 :
        print(“A+“)
    else :
        print(“F”)

I'm getting value error.

I want to get situation <- if users gives me literal answer, I want to say "only number".

AAA
  • 3,520
  • 1
  • 15
  • 31
남아름
  • 1
  • 1

2 Answers2

0

I think you meant to try this

def enforce_int(x):
    try:
        _ = int(x)
        return True
    except ValueError as _:
        return False

While True: # why is this here though?
    n=turtle.textinput(“”,”write your grade”)

    while not enforce_int(n):
        n=turtle.textinput(“”,”use only number”)

    grade = int(n)
    If grade <=100 and grade>=95 :
        print(“A+“)
    else :
        print(“F”)
Buckeye14Guy
  • 831
  • 6
  • 12
0

Next time please format your code in ASCII.

while True:
    n = input("write your grade: ")
    while True:
        try:
            grade = int(n)
            break
        except:
            n=input("use only number: ")

    if grade <=100 and grade>=95 :
        print("A+")
    else :
        print("F")
roschach
  • 8,390
  • 14
  • 74
  • 124