In this tutorial we shall learn about Input and Decision Making statements.To get the data from the user we need to use input statements.Input statement in python is variable_name = input(“Text_to_be_displayed”);.The input statement is a predefined function which has String has parameter to display the message to the user.Now the value entered by the user will be stored in the variable.
Let us write a simple program to demonstrate the input statement.In this program we request the user to enter his/her age and display the same age to the user.
age = input("Please enter your Age:"); print("Your entered your age as " + age);
Decision Making Statement: In all programming language Decision Making Statements are nothing but if statements.We all know that there are 4 type of if statements.But the syntax of if statements may vary depending upon the language. Python too have different syntax for if statements.We shall learn.
Simple if Statement:The syntax of simple if statement is
if (condition) : <true statements> <true statements> . . . <true statements>
if…else Statement: The syntax of if else is
if (condition) : <true statements> <true statements> . . else : <false statements> <false statements> . .
Nested if…else Statements: The syntax of nested if-else statements is
if (condition 1): if(condition 2) : <true statements> else : <false statements> else : if (condition 3) : <true statements> else : <false Statements>
else…if: With comparison to other languages in python else if have different syntax
if (condition 1 ) : <true statements> elif (condition 2) : <true statements> elif (condition 3) : <true statements> . . . elif(condition n) <true statements>
These are the decision making statements present in python and their respective syntax.One more thing Python doesn’t support Switch statements