IF statements in Python

If statements are used to run lines of code according to a specified condition. For example, Students are allowed to enter school if they have school uniforms otherwise they are not allowed to enter the school. The second example is that if the gender is male then the prefix Mr. should be added to the name while if the gender is female then the prefix Ms. should be added to the name. So how we can write such a program in python; Here we will use IF and ELSE statements.


# EXAMPLE 01

student1 = "Willian"
std_uniform1 = "yes"
student2 = "Avery"
std_uniform2 = "no"
if std_uniform1 == "yes":
    print(student1+" ALLOWED")
else:
    print(student1+" NOT ALLOWED")
if std_uniform2 == "yes":
    print(student2+" ALLOWED")
else:
    print(student2+" NOT ALLOWED")

# EXAMPLE 01

name = "Asad"
gender = "m"
if(gender == "m"):
    prefix = "Mr."
else:
    prefix = "Ms."
print(prefix+" "+name)
name = "Sophia"
gender = "f"
if(gender == "m"):
    prefix = "Mr."
else:
    prefix = "Ms."
print(prefix+" "+name)

Github:
https://github.com/asadraza825/python

Tags: Python, Python Programming,  Python IF ELSE statements, IF statements
Next Post Previous Post
No Comment
Add Comment
comment url