-1

If I try running this code it will only give me the answer for the 'if' part and not the 'else':

yes = "Answer is correct"
no = "Answer is incorrect"
score = 0

print("Hello and welcome to my quiz!")


q1 = input("What is my name?\n")
if q1 != "Robert" or "robert":
    print(no)

else:
    print(yes)
    score += 1

print("Your score is: " + str(score))
Fidogod
  • 11
  • 3
  • if q1 != "Robert" or q1 != "Robert" -- You have misunderstood how *or* works – Albert Winestein May 26 '22 at 10:20
  • `q1 != "Robert" or "robert"` is the same as `(q1 != "Robert") or ("robert")`, and `"robert"` will evaluate to `True` since it's not an empty string – byxor May 26 '22 at 10:20
  • 1
    Duplicate of [Why does "a == x or y or z" always evaluate to True?](https://stackoverflow.com/questions/20002503/why-does-a-x-or-y-or-z-always-evaluate-to-true) – mkrieger1 May 26 '22 at 10:20

0 Answers0