Home » Exercises » Page 2
Category:

# Exercises

Exercises

## Get a Random element from a List in Python

In this example we show how to get a random element from a list using python We will use 3 different methods to do this random.randint(start, stop) – start and…

• Exercises

## Check If a List is Empty in python

In this example we show 3 ways of checking if a list is empty in python Example If my_list1 is empty then not returns True len of my_list2 – If…

• Exercises

## Check is a number is a Perfect Number in python

In this example we check if a number is a perfect number using python In number theory, a perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the…

• Exercises

## Find Factorial of a Number in Python

In this example we will show you how to work out the factorial of a number in python The factorial of a non negative number is the product of all…

• Exercises

## Count total number of alphabets, digits and special characters using python

In this article we count the occurrences of letters, digits and special characters in a string using python Example We use isalpha() to check if all the characters in the…

• Exercises

## How to Remove Punctuation marks from a String

In this article we show how to remove punctuation marks from a string in python There are 14 punctuation marks that are used in the English language. They are: the…

• Exercises

## Sort a List in Descending Order in Python

In this article we show a way of sorting a list in descending order in python Example We use a for loop to add numbers to the Python list using…

• Exercises

## Sort a List in Ascending Order in Python

In this article we show how to sort a list in ascending order in python Example We use a for loop to add numbers to the Python list using the…

• Exercises

## Check if a string is a palindrome in python

In this example we check if a string is a palindrome in python A palindrome is a string that is the same read forward or backward. Example // check if…

• Exercises

## How to Get the Line Count of a File using python

In this example we will show how to get the line count of a file Example The test file contains the following, notice the blank lines this is line 1…

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More