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

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

Nakul Pratap shared their blog post on Twitter
yesterday
HrishikeshRam posted blog posts
yesterday
Kyle C. Johnson posted a discussion

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

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 phones at any time, anywhere. Even the PIT drivers. It's insane. My initial reaction is to say NO HEADPHONES WHATSOEVER, but my ops manager is concerned it will drastically reduce morale. I suggested that each department should have their own radio and they can play music for everyone to hear, at a…See More
yesterday
John Robinson posted a blog post

Nutrition Facts labels of pure maple syrup and honey

FDA Commissioner, Scott Gottlieb, has announced a major overhaul of the FDA’s update to the Nutrition Facts label on products. This overhaul, the first in nearly twenty years, is aimed at empowering consumers by furnishing information on Nutrition Facts labels pure maple syrup and honey that ensures greater accuracy and is more science-based. With this, the FDA wants to help consumers make more informed and healthier choices.This update to the Nutrition Facts label has incorporated the latest…See More
Friday

Forum

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

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 yesterday.

AI Machine Learning In Businesses How wоuld уоu define a small buѕinеѕѕ, thе number оf реrѕоnеl, thе size оf the budget, оr ѕаlеѕ?

How wоuld уоu define a small buѕinеѕѕ, thе number оf реrѕоnеl, thе size оf the budget, оr ѕаlеѕ?However you define уоur оwn ѕmаll business, it tоо can tаkе advantage оf thе AI/ …Continue

Tags: elite, crest, technologies, intelligence, Artificial

Started by emmablisa Dec 10.

Distracted Driving 1 Reply

****WARNING**** Despite the fact that this is a life event portrayed by actors, it's graphic. This video should be part of…Continue

Tags: texting, fatality, safety, car, driving

Started by Wendy. Last reply by Jen McDade Dec 5.

Safety update: OSHA announces fit-test procedures 1 Reply

Fabricators as well as other workers may be required to use respirators to protect themselves from inhaling fumes, particles, or dust when performing cutting, grinding, welding, coating, or painting,…Continue

Tags: online, training, Safety, workplace, PPE

Started by Safety Training International. Last reply by Jen McDade Dec 4.

Badge

Loading…

© 2018   Created by Safety Community.   Powered by

Badges  |  Report an Issue  |  Terms of Service