Condition list Python

Condition list Python
Credit: Unsplash

Note: I’ve written the Quick Code-Python series in a linear fashion so that even a newbie can follow along the series to get a grasp of what python can actually do. For folks that are good with the fundamentals, you can follow along with the series to refresh your concepts or choose any of the chapters in the series that you want to know more about.

Comparison Operators

Condition list Python
Credit: engineering big data

Logical Operators

Conditional Statements

Code to block sam inside the college campus

Sam may trick us by using his friend's name to enter the campus, let’s make sure that doesn’t happen

Code to return only elements from the dictionary that are greater than 25. Note that there are more efficient ways to do this, but for now let’s do this with if condition.

Code to check if a randomly generated number and the user inputted number are the same

Code to indicate the number of digits in an integer

Code to find if a number is even or odd

Append marks to a list from a dictionary only if they are greater than 75

Using the break statement in the loop to break out of the loop

Using the Continue statement in the loop to print the odd numbers in a list

Condition list Python
credit meme overflow

Calculate the sum of the numbers in a list

Let’s give our student’s list an index using enumerate()

List Comprehension

Without using list comprehension

Using list comprehension

Condition list Python
Credit: meme generator

Without using list comprehension,

Using list comprehension,

Nested Loops

Printing the 4th and 5th multiplication table

Condition list Python
Credit: ah see it

Creating a simple while loop to print numbers

We’ll see how to run a loop keeping it Trueduring inital stage, while specifying the condition in the end.

Condition list Python
Credit: Meme generator

Some Practical examples using the above concepts

Printing the numbers from an input string using list comprehension

Printing every name in the list except ‘Kate’

Code to generate the following table

Print the numbers between a given range that are only even

Code to generate a password for a user using random letters, punctuations, numbers depending on the length that the user provides

Sorting the words in a sentence from the reply given by the user

Note: If you are reading the blog in a smartphone, the codes may not be very presentable to you. If you can’t understand the code properly, read the blog in a PC/MAC

Check out the previous chapter of the Quick Code-Python series.