Python If Else | If Else in Python


#--------------------------if-else method-----------------------
marks = int(input("Enter your marks: "))
if marks > 80:
print("A+")
elif marks > 60:
print("A")
elif marks > 45:
print("B+")
elif marks > 30:
print("B")
else:
print("Fail")

#OUTPUT:
# Enter your marks: 82
# A+

#----------------AND-OR Method----------

name = 'Alex'
age = 24
if name == 'Alex' and age > 18: #You can use or in the place of and
                                    operator
print("You can watch this movie")
else:
print("You can't watch this movie.")

#OUTPUT:
# You can watch this movie

#---------------In keyword-------------
name = 'reverse shell'
if 'e' in name:
print("Then ok!")
else:
print("Not Ok!")
#OUTPUT:
#Then ok!

#---------------Check Empty or Not-------
name = 'Python'
if name:
print("There is no problem")
else:
print("There is no name to print")
#OUTPUT:
# There is no problem

Comments