Home > front end >  if-else statement print does not match after checking through statement
if-else statement print does not match after checking through statement

Time:07-14

I'm working on a simple if-else statement, however after running through the if-else check, it returns only the else value, despite inputs that matches the if and elif statement:

testing = input("Input: ")

a = ""
b = ""

if testing == a:
    print_value = "a"

elif testing == b:
    print_value = "b"

else:
    print_value = "N/A"

print(print_value)

Example Result after inputting "a":

Expected Result: a
Final Result: N/A

How may I resolve this to ensure it matches the if-elif statement above?

CodePudding user response:

You are assigning the a and b an empty string and then checking if '' is equal to 'a', which you can see are not equal.

Try assigning alphabets to the variables and then perform equality check.

a = 'a'
b = 'b'
  • Related