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

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

kate smith posted a blog post

Pre-Employment Testing is a Good Tool for Assessing Future Hires

If administered properly, pre-employment testing is a good means of ensuring that the organization gets the right candidateIn simple terms, a pre-employment test is an assessment an organization carries out to test the suitability of the candidate for the selected role. It is done to ensure that the candidate has the potential to fulfil the expected role. It is done to get a feel of how a candidate could fare if given the job.What are the Kinds of Pre-Employment Tests?Pre-employment tests…See More
10 hours ago
Traininngdotcom-LLC posted blog posts
10 hours ago
Mark Nilson posted events
11 hours ago
HrishikeshRam posted a blog post

How Would You Benefit From an IOSH Managing Safely Course?

IOSH Managing Safely is a fundamental risk management health and safety certificate course, this offers the manager a comprehensive understanding of essential practical actions required for the health safety and well being of their groups. It empowers the organization to show commitment towards health and safety measures which is imperative for the reputation of all…See More
12 hours ago

Forum

Road Safety

What can be the best measures for Road Safety?Continue

Started by Jen McDade Sep 27.

safety equipments in breweries 4 Replies

safety equipments in breweries -- kindly provide detailsContinue

Started by ajit. Last reply by Jen McDade Sep 24.

Unusual Safety Tips 10 Replies

Please share some unusual but genuine safety precautions.My unusual safety tips - Don't drink sweet fruity juice while driving in the night as it contains sugar and sugar slows down your blood…Continue

Started by Arnold Brame. Last reply by Jen McDade Sep 24.

Safety products 9 Replies

While working or at some work stations, employees are exposed to threats or at times suffer severe injuries. The safety of the employee should be the foremost priority. Safety equipment aids help in…Continue

Tags: equipments, and, products

Started by Enna Henry. Last reply by Jen McDade Sep 24.

Talend Application Integration

APPLICATION INTEGRATION:Talend ESB and Application Integration delivers agile real-time integration of applications and data.Heterogeneous Application and Data IntegrationTalend’s open source ESB…Continue

Tags: york, new, certification, training, talend

Started by nicolewells Sep 21.

Badge

Loading…

© 2018   Created by Safety Community.   Powered by

Badges  |  Report an Issue  |  Terms of Service