0

About if statement

President1="George Washington" President2="george washington" Ans=input() if Ans==President1 or President2: print("correct") else: print("incorrect") I know there is a problem with the code.It works well if I dont use "or" and give second condition with "elif". But I want to know whats the reason?Which logical error is happening?

18th Nov 2020, 5:49 PM
Tanvir
Tanvir - avatar
2 Antworten
+ 2
The error is in the comparison. In your code python will do if Ans==True: because President1 or President2 == True This way as long as the input is not None, "correct" will print. It should be: if Ans==President1 or Ans==President2 Or: If Ans in (President1, President2): #do something Or: If Ans.lower() == President2: #do something Happy Coding 😀
18th Nov 2020, 5:56 PM
Tomiwa Joseph
Tomiwa Joseph - avatar
- 1
It should work...check what you input again :)
18th Nov 2020, 5:53 PM
Momen Abdelwadoud Abdalla Elkhalifa
Momen Abdelwadoud Abdalla Elkhalifa - avatar