Python Foundation with Data Structures & Algorithms - Part 04

Python Decision Making

Python supports the usual logical conditions from mathematics:

Equals: a == b
Not Equals: a != b
Less than: a < b
Less than or equal to: a <= b
Greater than: a > b
Greater than or equal to: a >= b

These conditions can be used in several ways, most commonly in "if statements" and loops.
An "if statement" is written by using the if keyword.

Python relies on indentation (whitespace at the beginning of a line) to define scope in the code. Other programming languages often use curly-brackets for this purpose.

Using if Statement

using if-else Statement

Multiple if Statement

Here all the true conditions will be executed.

if-elif Statement

Even if all the conditions are true, only first True condition will be executed rest all will not be executed.

Nested if-else Statement

Short Hand If

If you have only one statement to execute, one for if, and one for else, you can put it all on the same line:

if-else using Logical AND Operator

if-else using Logical OR Operator

The pass Statement

if statements cannot be empty, but if you for some reason have an if statement with no content, put in the pass statement to avoid getting an error.

Find No is +ve/-ve

Find the No is Even/Odd

Find the No is Even/Odd ( Without using any Arithmetic Operator )

Find the Greatest Between 2 No's

Find the Greatest Between 3 No's

Calculate Ticket Price:

32