In
this page you learn the if statement in python is the same as other languages like a c programming language. It is used contains a logical expression to test a
condition. And the decision based on the result of the comparison.
Here,
the decisions are made on the validity of the particular conditions. Condition
checking is the backbone of decision making.
In
python, decision making is performed by the following statements.
Statement
|
Description
|
If Statement
|
The if the statement is used to test a
specific condition. If the condition is true, a block of code (if-block) will
be executed.
|
If - else Statement
|
The if-else statement is similar to
if statement except for the fact that, it also provides the block of the code for the false case of the condition to be checked. If the condition provided in the if the statement is false, then the else statement will be executed.
|
Nested if Statement
|
Nested if statements enable us to use
if ? else statement inside an outer if statement.
|
Syntax
if expression:
statement(s)
Example
of if statement
a=20
if a==20:
print "Hello World cup T20"
Output
Hello World cup T20
Example: Program to print the
largest of the three numbers.
b = int(input("Enter b? "));
c = int(input("Enter c? "));
if a>b and a>c:
print("a is largest");
if b>a and b>c:
print("b is largest");
if c>a and c>b:
print("c is largest");
Output:
Enter a? 100
Enter b? 120
Enter c? 130
c is largest
if age>=18:
print("You are eligible to vote !!");
else:
print("Sorry! you have to wait !!");
Output:
Enter your age? 90
You are eligible to vote !!
Example: Program to
check whether a number is even or not.
num = int(input("enter the number?"))
if num%2 == 0:
print("Number is even...")
else:
print("Number is odd...")
Output:
enter the number?10
Number is even
Angular is a platform that makes it easy to build applications with the web. Angular combines declarative templates, dependency injection, end to end tooling, and integrated best practices to solve development challenges. Angular empowers developers to build applications that live on the web, mobile, or the desktop.
0 comments:
Post a Comment