Python- The Decisions

  IF..ELSE

  1. We will start with the simple if..else statement in Python.
  2.  Create a new file ifelse.py and enter the below lines:num = 100
    if (num == 100) : print(“Value of the number is 100”)
    else :
    print (“Value of the number is not equal to 100”)print(“Exit”)                          
  3. Save the file and under Run menu, click on Run module. You should get the output as shown below:

 

All in One

  1. Next, we will see how to use the if, elif and else statements in one program.
  2. Type the code snippet as given below:

          

      3. Save the file and under Run menu, click on Run module. You should get the output as shown below:

          

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s