Server Side Programming Articles - Page 1963 of 2650

Fractal Trees in Python

Pradeep Elance
Updated on 02-Jan-2020 10:07:38

989 Views

Fractal patterns are all around us in nature. Like a small branch taken out of the leaf of a fern leaf resembles the leaf itself. Or a pebble often resembles the shape of a mountain! So this idea of a repetition of small pattern to generate a large pattern is known as a fractal tree. In python programming we can also generate fractal trees by using various modules available.Using pygame ModuleThis module provides us with the required functions to generate the fractal trees. Here we first defines the screen layout size and then define the deepness up to which the ... Read More

Decision tree implementation using Python

Pradeep Elance
Updated on 02-Jan-2020 10:01:51

2K+ Views

Decision tree is an algorithm which is mainly applied to data classification scenarios. It is a tree structure where each node represents the features and each edge represents the decision taken. Starting from the root node we go on evaluating the features for classification and take a decision to follow a specific edge. Whenever a new data point comes in , this same method is applied again and again and then the final conclusion is taken when all the required features are studied or applied to the classification scenario. So Decision tree algorithm is a supervised learning model used in ... Read More

assert keyword in Python

Pradeep Elance
Updated on 02-Jan-2020 09:51:34

379 Views

Every programming language has feature to handle the exception that is raised during program execution. In python the keyword assert is used to catch an error and prompt a user defined error message rather than a system generated error message. This makes it easy for the programmer to locate and fix the error when it occurs.With AssertIn the below example we use the assert key word to catch the division by zero error. The message is written as per the wish of the programmer.Example Live Demox = 4 y = 0 assert y != 0, "if you divide by 0 it ... Read More

Append Odd element twice in Python

Pradeep Elance
Updated on 02-Jan-2020 09:46:46

234 Views

In this article we will see how to take a list which contains some odd numbers as its elements and then add those odd elements repeatedly into the same list. Which means if odd number is present twice in a list then after processing the odd number will be present four times in that same list.For this requirement we will have many approaches where we use the for loop and the in condition or we take help of of itertools module. We also check for the odd condition by dividing each element with two.Example Live Demofrom itertools import chain import numpy ... Read More

Append at front and remove from rear in Python

Pradeep Elance
Updated on 02-Jan-2020 09:44:40

243 Views

When using Python for data manipulation we frequently and remove elements from list. There are methods which can do this effectively and python provides those function as part of standard library as well as part of external library. We import the external library and use it for this addition and removal of elements. Below we will see two such approaches.Using + operatorExample Live Demovalues = ['Tue', 'wed', 'Thu', 'Fri', 'Sat', 'Sun'] print("The given list : " ,values) #here the appending value will be added in the front and popping the element from the end. result = ['Mon'] + values[:-1] print("The values ... Read More

Alternate range slicing in list (Python)

Yaswanth Varma
Updated on 14-Jul-2025 14:22:54

882 Views

Slicing is used to extract a portion of a sequence (such as a list, a tuple, string) or other iterable objects. Python provides a flexible way to perform slicing using the following syntax. list[start:stop:step] Alternate Range Slicing The alternate range slicing is used to retrieve the elements from a list by skipping the elements at a fixed interval, using the step parameter. For example, if we want every second element from a list, we set step=2. Let’s observe some examples to understand how alternate range slicing works. Example 1 Consider the following ... Read More

Adding a Chartsheet in an excel sheet using Python XlsxWriter module

Pradeep Elance
Updated on 02-Jan-2020 09:34:40

483 Views

In addition to python’s own libraries, there are many external libraries created by individual authors which do a great job of creating additional features in python. Xlsx library is one such library which not only creates excel files containing data from python programs but also creates charts.Creating Pie ChartIn the below example we will create a pie chart using the xlsxwriter writer. Here we first define a workbook then add a worksheet to it in the next step we define the data and decide on the columns where the data will be stored in an excel file based on those ... Read More

Add the element in a Python list with help of indexing

Pradeep Elance
Updated on 02-Jan-2020 09:32:17

211 Views

A python list is a collection data type that is ordered and changeable. Also, it allows duplicate members. It is the most frequently used collection data type used in Python programs. We will see how we can add an element to a list using the index feature.But before adding the element in an existing link, let's access the elements in a list using the index feature.Accessing List using Indexevery element in the list is associated with an index and that is how the elements remain ordered. We can access the elements by looping through the indexes. The below program prints ... Read More

Add similar value multiple times in a Python list

Pradeep Elance
Updated on 02-Jan-2020 09:29:58

7K+ Views

There are occasions when we need to show the same number or string multiple times in a list. We may also generate these numbers or strings for the purpose of some calculations. Python provides some inbuilt functions which can help us achieve this.Using *This is the most used method. Here we use the * operator which will create a repetition of the characters which are mentioned before the operator.Example Live Demogiven_value ='Hello! ' repeated_value = 5*given_value print(repeated_value)Running the above code gives us the following result:Hello! Hello! Hello! Hello! Hello!Using repeatThe itertools module provides repeat function. This function takes the repeatable string ... Read More

Calculate n + nn + nnn + u + n(m times) in Python Program

Hafeezul Kareem
Updated on 02-Jan-2020 07:07:04

410 Views

In this tutorial, we are going to write code to find the sum of the series n + nn + nnn + ... + n (m times). We can do it very easily in Python. Let's see some examples.Input: n = 1 m = 5 Series: 1 + 11 + 111 + 1111 + 11111 Output: 12345AlgorithmFollow the below steps to solve the problem.1. Initialise the n and m. 2. Initialise total to 0. 3. Make the copy of n to generate next number in the series. 4. Iterate the loop m times.    4.1. Add n to the total. ... Read More

Advertisements