Hafeezul Kareem

Hafeezul Kareem

259 Articles Published

Articles by Hafeezul Kareem

Page 26 of 26

Barnsley Fern in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 01-Nov-2019 505 Views

In this tutorial, we are going to learn about the Barnsley Fern, which is created by Michael Barnsley. The features of Barnsley Fern is similar to the fern shape. It is created by iterating over the four mathematical equations known as Iterated Function System(IFS). The transformation has the following formula.f(x, y)=$$\begin{bmatrix}a & b \c & d \end{bmatrix}\begin{bmatrix}x \y \end{bmatrix}+\begin{bmatrix}e \f \end{bmatrix}$$Source − WikipediaThe values of the variables are −Source − WikipediaThe four equation that Barnsley Fern proposed are −Source − WikipediaNow, we will see code to create the fern shape in Python.Example# importing matplotlib module for the plot import matplotlib.pyplot ...

Read More

Basic Python Programming Challenges

Hafeezul Kareem
Hafeezul Kareem
Updated on 01-Nov-2019 592 Views

In this tutorial, we are going to write a solution for a challenge.ChallengeWe have to generate a random set of basic arithmetic operations. The user will give the number of questions, and we have to generate questions. After every question, the user will answer it. At the end of the program, we have to give the score. Let's try it.Example# importing random and operator modules import random import operator # main function # taking number of questions that we have to generate def main(n):    print("Welcome to the quizYou should answer floats upto 2 decimals")    # initialising score to ...

Read More

Data analysis and Visualization with Python program

Hafeezul Kareem
Hafeezul Kareem
Updated on 01-Nov-2019 437 Views

In this tutorial, we are going to learn about data analysis and visualization using modules like pandas and matplotlib in Python. Python is an excellent fit for the data analysis things. Install the modules pandas and matplotlib using the following commands.pip install pandaspip install matplotlibYou will get a success message after the completion of the installation process. We will first learn about the pandas and then will see matplotlib.pandasPandas is an open-source library of Python which provides data analysis tools. We are going to see some useful methods from the pandas for data analysis.Creating DataFramesWe need multiple rows to create ...

Read More

Program to reverse an array up to a given position in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 27-Aug-2019 898 Views

In this tutorial, we will learn how to reverse an array upto a given position. Let's see the problem statement.We have an array of integers and a number n. Our goal is to reverse the elements of the array from the 0th index to (n-1)th index. For example, Input array = [1, 2, 3, 4, 5, 6, 7, 8, 9] n = 5 Output [5, 4, 3, 2, 1, 6, 7, 8, 9]Procedure to achieve the goal. Initialize an array and a number Loop until n / 2. Swap the (i)th index and (n-i-1)th elements.Print the array you will get the result.Example## initializing array and ...

Read More

Python program to remove leading zeros from an IP address

Hafeezul Kareem
Hafeezul Kareem
Updated on 27-Aug-2019 615 Views

In this tutorial, we are going to write a program which removes leading zeros from the Ip address. Let's see what is exactly is. Let's say we have an IP address 255.001.040.001, then we have to convert it into 255.1.40.1. Follow the below procedure to write the program.Initialize the IP address.Split the IP address with. using the split functionConvert each part of the IP address to int which removes the leading zeros.Join all the parts by converting each piece to str.The result is our final output.Example## initializing IP address ip_address = "255.001.040.001" ## spliting using the split() functions parts = ip_address.split(".") ## ...

Read More

Python program to merge two Dictionaries

Hafeezul Kareem
Hafeezul Kareem
Updated on 27-Aug-2019 727 Views

In this tutorial, we are going to learn how to combine two dictionaries in Python. Let's see some ways to merge two dictionaries.update() methodFirst, we will see the inbuilt method of dictionary update() to merge. The update() method returns None object and combines two dictionaries into one. Let's see the program.Example## initializing the dictionaries fruits = {"apple": 2, "orange" : 3, "tangerine": 5} dry_fruits = {"cashew": 3, "almond": 4, "pistachio": 6} ## updating the fruits dictionary fruits.update(dry_fruits) ## printing the fruits dictionary ## it contains both the key: value pairs print(fruits)If you run the above program, Output{'apple': 2, 'orange': 3, ...

Read More

Python program to find all close matches of input string from a list

Hafeezul Kareem
Hafeezul Kareem
Updated on 27-Aug-2019 695 Views

In this tutorial, we are going to find a solution to a problem. Let's see what the problem is. We have a list of strings and an element. We have to find strings from a list in which they must closely match to the given element. See the example.Inputs strings = ["Lion", "Li", "Tiger", "Tig"] element = "Lion" Ouput Lion LiWe can achieve this by using the startswith built-in method. See the steps to find the strings.Initialize string list and a string.Loop through the list.If string from list startswith element or element startswith the string from the listPrint the stringExample## initializing ...

Read More

Program to check if all the values in a list that are greater than a given value in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 27-Aug-2019 1K+ Views

In this tutorial, we will check whether all the elements in a list are greater than a number or not. For example, we have a list [1, 2, 3, 4, 5] and a number 0. If every value in the list is greater than the given value then, we return True else False.It's a simple program. We write it in less than 3 minutes. Try it yourself first. If you are not able to find the solution, then, follow the below steps to write the program.Initialise a list and any numberLoop through the list.If yes, return **False**Return True.Example## initializing the list    values ...

Read More

Custom len() Function In Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 30-Jul-2019 844 Views

Let's see how can we implement custom len() function in Python. Try it by yourself first using the following steps.StepsGet the iterator from the user string/list/tuple.Define a function with a custom name as you like and invoke it by passing the iterator.Initialize the count to 0.Run a loop until it reaches the end.Increment the count by 1Return the count.Example Live Demo## function to calculate lenght of the iterator def length(iterator):    ## initializing the count to 0    count = 0    ## iterating through the iterator    for item in iterator:       ## incrementing count       ...

Read More
Showing 251–259 of 259 articles
« Prev 1 22 23 24 25 26 Next »
Advertisements