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

Why Python is fail to calculate basic math problems?

When i was trying this:

a = input("Enter your math calculations :")

if "45*3" or "45 * 3" in a:
    print("555")
elif "56+9" or "56 + 9" in a:
    print("77")
elif "56/6" or "56 / 6" in a:
    print("4")
else:
    print(eval(a))

Instead of expected answer it is outputting unexpected output

Expected : Enter your math calculations :10+1 =
11

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

Result : Enter your math calculations :10+1 =
555

What am i doing wrong???.

>Solution :

Why did you write if "45*3" or "45 * 3" in a:

Instead write if a=="45*3" or a=="45 * 3":

and all like this.

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