Input and Decision Making Statements in Python

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); 

Output:
input_demo

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

Advertisements

About Anuroop D

Very enthusiastic about technology and likes to share my knowledge through blogging. Has Bachelor's in Information Technology and currently pursuing my Master's in Computer Science.
This entry was posted in Python and tagged , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s