DEV Community

Cover image for Python Conditional statement
EzeanaMichael
EzeanaMichael

Posted on • Edited on

3 1

Python Conditional statement

Most of us are familiar with making real-life condition statements like "if I have enough money, I will buy a ball" which gives the condition that if you have enough money you will purchase the item but if not you won't.
Python, like all programming languages, also has a way of writing conditional statements like this, with the use of "if….." Statement
An example is a code
image description
When run

Image description
The program won't do anything when it's less than the amount but if it's greater:

Image description

If the condition is fulfilled the operation is carried out, but if not it would be carried out.
In addition, in the if statement it's possible you want the program to run when the condition is not fulfilled here you use the "else" statement.
The else is designed so if the condition under the if statement isn't fulfilled it will be
Example
Image description
When run

Image description
Or

Image description

So if the money is greater than 500 it will send a message saying bought ball but if not it will send a message saying not enough funds.

Hope you enjoyed this short lesson, more on this will be uploaded next week, read, like, comment

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay