Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

if-else statement print does not match after checking through statement

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading