Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Python Code not working

+13 votes
asked Jul 27 by Yoong Tsun Chuen (360 points)
retagged Jul 27 by Yoong Tsun Chuen
I'm trying to make a code which can tell you what grade you have, but it isn't working. Please help me if you can. This is the code: https://onlinegdb.com/_erzAZd8I

1 Answer

+4 votes
answered Jul 27 by Peter Minarik (32,880 points)
selected Jul 27 by Yoong Tsun Chuen
 
Best answer

Please, find the syntax error fixes below:

print ("Type in your IGCSE mark")
MARK=int(input(''))
if MARK >= 89 and MARK <= 100:
    print ("PARTY HARD! You have gotten A*")
elif MARK >= 79 and MARK <=90:
    print ("AMAZING! You have gotten an A")
elif MARK >= 69 and MARK <=80:
    print ("Not bad! You have gotten a B")
elif MARK >= 59 and MARK <=70:
    print ("Could be better. You have gotten a C")
elif MARK >= 49 and MARK <=60:
    print ("Try harder! You have gotten a D")
elif MARK >= 39 and MARK <=50:
    print ("Pay more attention in class. You have gotten an E")
elif MARK >= 90 and MARK <=100:
    print ("I suggest you go to a tuition. You have gotten an F")
else:
    while (MARK >= 100 or MARK <= 0):
        print ("Invalid Input")

And here are the compilation errors:

  1. missing colon from the end of line
  2. missing MARK from the left side of the <= operator; also missing colon from the end of line
  3. line needs to be indented

After this, your code compiles, but it has many issues.

  1. There are overlapping regions (e.g. first if [89, 100] and last if [90, 100]) overlap. This is a logic error, although the code runs OK. -- there are many overlaps, not just this)
  2. The last condition (despite the high scores suggests a failure) -- another logic error
  3. the while in the last lines will print "Invalid Input" 'till eternity. You should have your whole input and mark checking logic inside the body of your loop. But they you should tell the user what input allows them to leave the loop. Or just don't make any loop at all. ;)

Everything fixed would produce a code like this:

mark = int(input("Type in your IGCSE mark: "))
if mark > 100 or mark < 0:
    print ("Invalid Input")
elif mark >= 90:
    print ("PARTY HARD! You have gotten A*.")
elif mark >= 80:
    print ("AMAZING! You have gotten an A.")
elif mark >= 70:
    print ("Not bad! You have gotten a B.")
elif mark >= 60:
    print ("Could be better. You have gotten a C.")
elif mark >= 50:
    print ("Try harder! You have gotten a D.")
elif mark >= 40:
    print ("Pay more attention in class. You have gotten an E.")
else:    
    print ("I suggest you go to a tuition. You have gotten an F.")
commented Jul 27 by Yoong Tsun Chuen (360 points)
Thanks for the help. And thanks for pointing out the overlapping and that last F line.
commented Jul 27 by Peter Minarik (32,880 points)
My pleasure.
commented Aug 18 by Dulshan (100 points)
print ("Type in your IGCSE mark")
MARK=int(input(''))
if MARK >= 89 and MARK <= 100:
    print ("PARTY HARD! You have gotten A*")
elif MARK >= 79 and MARK <=90:
    print ("AMAZING! You have gotten an A")
elif MARK >= 69 and MARK <=80:
    print ("Not bad! You have gotten a B")
elif MARK >= 59 and MARK <=70:
    print ("Could be better. You have gotten a C")
elif MARK >= 49 and MARK <=60:
    print ("Try harder! You have gotten a D")
elif MARK >= 39 and MARK <=50:
    print ("Pay more attention in class. You have gotten an E")
elif MARK >= 90 and MARK <=100:
    print ("I suggest you go to a tuition. You have gotten an F")
else:
    while (MARK >= 100 or <= 0):
    print ("Invalid Input")
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...