Decision Making Statement.
Conditional Statement
Decision making of an anticipation of condition occuring by execution of program and dpecific action is taken according to condtion.
Following is a general form of typical decision making structure found in most programming language.Python programming language uses any non-zero or non-null value as true and if it is either zero or null then it is assume false value.
if Condition:
In python the block of statement is executed if the condition is true.
SyntaxQuestion: Write a program that prompt user to enter two integer values, print the message "equal" if both entered value are equal
if-else Condition:
The particular block of statement is executed if the if-condtion is true , else it will execute other block of statement.
SyntaxQuestion: Write a program that prompt user to enter two integer values, print the message if one value is greater than other else vece-versa.
if-elif Condition:
The particular block of statement is executed if the if-condtion is true , else it will execute other block of statement.
SyntaxCore python does not provide SWITCH statement as in other languages but we can use if-elif statement to simulate switch-case as follow:
Question: Write a program to prompt a user to read the subject of 5, claculate total marks and % of the marks and display the grade based on given in table.
Nested if Statement:
When a programmar write one if statement inside another then it is called as Nested if statement.
Syntax
Comments
Post a Comment