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

using and vs or in statments

while gender.capitalize() != "M" and gender.capitalize() != "F" and gender.capitalize() != "Male" and gender.capitalize() != "Female":
    print("Not a valid entry: ")
    gender = (input("Gender: "))
if gender.capitalize() == "M" or gender.capitalize()== "Male":
    print("Hello " + name + " you are " + age + " years old and are a boy")
elif gender.capitalize() == "F" or gender.capitalize()== "Female":
    print("Hello " + name + " you are " + age + " years old and are a girl")

this is working code I would just like to know why and works above and or works below im sure it’s the != but I’m not sure

I just want a better understanding of when and why to use and vs or

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 :

and should be used when all the conditions requirement shoule be met [i.e all conditions must be True]

or should be used when any one condition satisfy the condition [i.e. any one condition should met True]

Ex let’s say you wanted a number which should be divisible by 2 and should be greater than 10

Condition you should apply -: if num%2==0 and num>10: as you see and is used because you wanted both criteria to be satisfied

Ex let’s say you wanted a number which is greater than 10 or if it is not greater than 10 the number should divisible by 2

Condition you should apply :- if num>10 or num%2==0 as you see or used because any one criteria if satisfied you wanted that number..

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