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?
2 odpowiedzi
+ 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 😀
- 1
It should work...check what you input again :)