Online Safety Community

If you have knowledge of other programming languages, then you would know the importance of conditional statements. Conditional statements are required for taking decisions. Whenever we operate the software, our choice of action decides the next step. A simple example is booking an air ticket. If you want to travel in economy class, you will be presented a different package, whereas if you opt for business class you will be given a different package. So, let’s take a look at the conditional statements available in python.

-An else statement can be combined with an if statement. An else statement contains the block of code that executes if the conditional expression in the if statement resolves to 0 or a FALSE value.

Format:

if (expression): code1  else:  code2

EXAMPLE:

a= 7 b=8 if(a>b): print ‘I am greater than b’ else: print ‘I am greater than a’

Output :I am greater than a

-To check multiple conditions and run the block of code for the condition that returns ‘true’

Format:

if expression1: code1  elif expression2: code2  elif expression3: code3  else:  code4

EXAMPLE:

a=7 b=7 if(a>b): print ‘I am greater than b’ elif (b>a): print ‘I am greater than a’ elif (a==b): print ‘Hey!! we both are equal’

Output: Hey!! we both are equal

- A simple if statement can be used without any else or else if. Usage of simple if statement means that the lines of code should be executed only if the condition is true.

Format:

if condition : execute the code

EXAMPLE:

a=7 b=7 if(a>b): print ‘I am greater than b’ print ‘Good Bye’

Output: Good Bye

HTTPS://DOCS.PYTHON.ORG/2/LIBRARY/THREADING.HTML#CONDITION-OBJECTS

Views: 20

Reply to This

Replies to This Discussion

Head scratching - I signed up here thinking I may gain knowledge of safety issues

RSS

Take our poll!

Take our poll!

Latest Activity

Timber Warriors posted a blog post

Preparing Your Home for Storm Season

Natural disasters happen ever year. Being able to protect your family and your home inside your house is critical to surviving storm season. Use this guide below to help create a safer environment in your home for you and your family.How To Prepare Your Home for Storm Season from Timber Warriors.See More
13 hours ago
Stevenson Crane posted a blog post

Rigging Safety Guidelines

Everyone knows there are certain best practices when lifting a heavy object. For example, you should always lift with your legs, not your back. The same principle applies to situations in which heavy hauling necessitates the use of rigging to lift especially heavy objects. There are numerous guidelines and best practices that OSHA recommends to help ensure that all heavy lifting takes place under the safest conditions. Failing to follow these guidelines and rules can create unsafe conditions…See More
15 hours ago
Training Doyens posted events
15 hours ago
Profile IconMildred Parham, mrs juliet williams, jothi kamesh v and 2 more joined Online Safety Community
16 hours ago

Forum

Python Condition Objects Tutorial in 2018 1 Reply

If you have knowledge of other programming languages, then you would know the importance of conditional statements. Conditional statements are required for taking decisions. Whenever we operate the…Continue

Tags: course, certification, training, languages, programming

Started by Elena Lauren. Last reply by Jim Chesters May 15.

Power BI Visualization Types

Visualizations in Power BI displays the visual insights from a data. In power bi service a visual can be pinned from reports to create dashboards. Visuals are used in reports.List of visualizations…Continue

Tags: COURSE, TRAINING, BI, POWER

Started by Azharuddin May 15.

Automation Anywhere. How do I pick a value from dropdown 1 Reply

Automation Anywhere. How do I pick a value from dropdown. I tried 'set text' from a copied variable. Its very slow, and also doesnt…Continue

Tags: anywhere, automation

Started by emmablisa. Last reply by venkatesh Mar 29.

Agile overcome common software security challenges

Paradoxically, security is a negative goal. To secure something, you must understand how insecure it is. Start by trying to break it or by figuring out how other people might break it. The same is…Continue

Tags: agile, scrum, security

Started by nicolewells Mar 23.

Badge

Loading…

© 2018   Created by Safety Community.   Powered by

Badges  |  Report an Issue  |  Terms of Service