Sie sind auf Seite 1von 5

1) Conditional statements in python?

Conditional Statements:
Conditional statements are used to perform different types of ACTIONS. It works depending on
whether a condition is TRUE or FALSE.Mostly with conditional statements we use COMPARIONS
and ARITHMETIC expressions with VARIABLES.

DECISION MAKING FLOWCHART DIAGRAM:

Conditional Statements Types:

IF STATEMENTS
IF..ELSE STATEMENTS
IF..ELIF..ELSE STATEMENTS
NESTED IF STATEMENTS

IF STATEMENTS
Rules:

The colon (:) is significant and required. It separates the header of the compound
statement from the body.

The line after the colon must be indented. It is standard in Python to use four spaces for
indenting.

All lines indented the same amount after the colon will be executed whenever the
BOOLEAN_EXPRESSION is true.

In python NON-ZERO value interprets as TRUE. NONE and ZERO interprets as FALSE.
Syntax:

if condition:
True Statement Block

Flow chart for IF statement:

Program:

Mark = input(Enter your mark)


if(Mark>=50)
print(you are pass) # indentation here 4 space

If.else Statements:
The ifelse statement checks the condition, If the condition is TRUE it executes the TRUE
STATEMENT BLOCK otherwise it executes the FALSE statement block.

In the If.else we use INDENTATION to separate the block.

Syntax:

if condition:
True Statement Block
else:
False Statement Block
Flowchar for if.else:

Program:
Mark = input(Enter your mark)
if(Mark>=50)
print(you are pass) # indentation here 4 space
else:

print(you are fail)

if.elif.else statement:

The elif statement is used to check multiple conditions.

The elif can have multiple elif blocks but only one else block.

In the elif if the condition1 is false, it check condition2 and so on


Syntax:
If condition1:
True statement
elif condition2:
True statement
elif condition3:
True statement
else
False statement

If.else Flowchart:

Con False
1

True

Execute true Execute false


condition1 stat condition stat

Con
2 False

True
Execute true Execute false
condition2 stat condition2 stat
Program:

Mark = input(Enter your mark)


if(Mark>90&&Mark<100)
print(you are A grade)

if(Mark>80&&Mark<90)

print(you are B grade)

if(Mark>70&&Mark<80)

print(you are C grade)

else:

print(you are low grade)

Nested if statements:

The ifelifelse statement can be used inside another ifelifelse statement. This is called
nesting in computer programming

Program:

Mark=input(enter your mark)

if Mark>=0:

if Mark==0:

print(your mark is zero)

else:

print(your mark is positive mark)

else:

print(your mark is negative mark)

Das könnte Ihnen auch gefallen