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: 100

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

Profile IconJames Pollard, Steve Carter, Steven Eaton and 5 more joined Online Safety Community
8 hours ago
Training Doyens posted events
14 hours ago
Training Doyens updated an event
Thumbnail

Live Webinar on Excel as a BI Tool: Pivot Tables Part 1 at 26468 E Walker Dr, Aurora, Colorado 80016

February 4, 2019 from 1pm to 2pm
OVERVIEWMicrosoft Excel Pivot Tables are one of the most powerful tools in Excel’s data analysis and Business Intelligence (BI) armoury.  With just a few clicks of the mouse (and no complicated formulas!) you can quickly and easily build the reports, dashboards and charts that help you to summarize, analyze, interpret and understand your data which in turn helps you to…See More
yesterday
simpliv updated an event
Thumbnail

Machine Learning with Python (40%OFF) at Online live courses,161 Mission Falls Lane, Suite 216, Fremont, CA 94539, USA.

March 2, 2019 at 7am to April 27, 2019 at 9am
Learn to use Python, the ideal programming language for Machine Learning, with this comprehensive course from Simpliv. Gain expertise in core areas of Python and Machine Learning, such as algorithms, model evaluation, supervised vs. unsupervised learning, reinforcement learning, neural networks, k-nearest Neighbor Classifier, Naive Bayes Classifier, and lots more. Become a complete Machine Learning and Python pro. Our experts will show you how to use your knowledge of Python to learn to use it…See More
Monday

Forum

Important of Warning sign 1 Reply

Warning sign is a type of traffic sign that guide a hazard ahead on the road. Having proper warning sign on the road provide a healthy environment.Continue

Tags: Signs, Workplace, Safety, Sign, Warning

Started by healthandsafetysigns. Last reply by Jen McDade on Monday.

Workers paticipation in safety management 2 Replies

Workers paticipation in safety management is the aspect which is required to be implemented in the OHSAS 18001 2007 version. , I invite our experience community members to share their views on the…Continue

Tags: management, safety, in, paticipation, Workers

Started by SafetyRaja. Last reply by Tara safe Dec 27, 2018.

How to improve safety culture of factories 4 Replies

How to improve safety culture of factories having mostly contract and casual ever changing workers for whom training and monitoring both are major issues. Such qorkers are mainly meeting accidents in…Continue

Started by Harkant Dave. Last reply by Jen McDade Dec 24, 2018.

[General Industry] What is your workplace's policy on headphones? Working on one currently. 1 Reply

I have been tasked to create a headphones (and cell phone) policy for my employer. I am relatively new to this company, but so far they've let everyone listen to headphones and mess around with their…Continue

Tags: general, industry, distraction, music, phone

Started by Kyle C. Johnson. Last reply by Jen McDade Dec 19, 2018.

Biggest Challenge? 5 Replies

As a distributor of safety supplies, as a webmaster who is trying to sell safety supplies online, one of my main goals is to try to provide value above and beyond just selling supplies and product.So…Continue

Started by Safetyguy08. Last reply by Jen McDade Dec 18, 2018.

Badge

Loading…

© 2019   Created by Safety Community.   Powered by

Badges  |  Report an Issue  |  Terms of Service