Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Any input passes and an "A"
#1
apparently any str passes as an "A" in my code. how do i fix this

gradeletter = str(input("Enter your Letter Grade: "))
def GPAcalc(grade):
    if (gradeletter == "A" or "a" or "B" or "b" or "C" or "c" or "D" or "d" or "F" or "f"):
        if (gradeletter == "A" or "a"):
            return (4)
        if (grade == "B" or "b"):
            return (3)
        if (gradeletter == "C" or "c"):
            return (2)
        if (gradeletter == "D" or "d"):
            return (1)
        if (gradeletter == "F" or "f"):
            return (0)
    else: print ("Invalid")

print(GPAcalc(gradeletter))
Reply
#2
https://python-forum.io/Thread-Multiple-...or-keyword
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
didnt help me. My program has no error it just doesnt output correctly.
also are you insulting me with that quote?
Reply
#4
(Mar-10-2019, 06:29 PM)JTNA Wrote: didnt help me. My program has no error it just doesnt output correctly.
also are you insulting me with that quote?

Click on the link that buran kindly posted for you,
Read what it says in the linked thread to explain why multiple expressions with "or" keyword give unexpected results,
Thank buran for the link.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020