DEV Community

vishwa v
vishwa v

Posted on

Python-3

Conditional statement
It used to control the flow of the execution of the program based on the specific condition.

if statement
It execute whether the given condition is true.

mark=75
if mark>60:
    print("pass")
Enter fullscreen mode Exit fullscreen mode

output:pass

elif statement
Used when you want to check another condition if the first one is false.

marks = 75

if marks >= 90:
    print("Grade A")
elif marks >= 75:
    print("Grade B")
elif marks >= 50:
    print("Grade C")
Enter fullscreen mode Exit fullscreen mode

output:Grade C

else statement
Runs when none of the above conditions are true.

marks = 30

if marks >= 90:
    print("Grade A")
elif marks >= 75:
    print("Grade B")
elif marks >= 50:
    print("Grade C")
else:
    print("Fail")
Enter fullscreen mode Exit fullscreen mode

output:Fail

Top comments (0)