Found 26504 Articles for Server Side Programming

ASCII art using Python pyfiglet module

Pradeep Elance
Updated on 18-Feb-2020 11:51:29

2K+ Views

The ASCII text can be used to display many stylish texts by using the module pyfiglet. After installing this module we can use it to control the font that can be used to display the result. In the below program we see various results by choosing various font types.Example# import pyfiglet module import pyfiglet #Text in default font out = pyfiglet.figlet_format("Point") print(out)OutputRunning the above code gives us the following result −Example# import pyfiglet module import pyfiglet #Text in slant font out = pyfiglet.figlet_format("Point", font="slant") print(out)OutputRunning the above code gives us the following result −Example# import pyfiglet module import pyfiglet #Text ... Read More

Adding K to each element in a Python list of integers

Disha Verma
Updated on 18-Feb-2020 11:31:07

1K+ Views

In this article, we will learn how to add a constant K value to each element in a Python list of integers. A list is a data type in Python that stores a sequence of items separated by commas, like this − List = [item1, item2, item3…] Suppose we have a list of integers called "a" and a constant value "k." We need to add this "k" to each item in the "a" list. For example − Input: a = [5, 10, 15, 20] k = 5 Output: #On adding 5 to each element of the ... Read More

Add one Python string to another

Pradeep Elance
Updated on 18-Feb-2020 11:28:35

390 Views

By adding strings in python we just concatenate them to get a new string. This is useful in many scenarios like text analytics etc. Below are the two approaches we consider for this task.Using += OperatorThe + operator can be used for strings in a similar was as it is for numbers. The only difference being, in case of strings the concatenation happens and not a numeric addition.Example Live Demos1 = "What a beautiful " s2 = "flower " print("Given string s1 : " + str(s1)) print("Given string s2 : " + str(s2)) #Using += operator res1 = s1+s2 print("result ... Read More

Add leading Zeros to Python Program string

Pradeep Elance
Updated on 18-Feb-2020 10:29:31

279 Views

We may sometimes need to append zeros as string to various data elements in python. There may the reason for formatting and nice representation or there may be the reason for some calculations where these values will act as input. Below are the methods which we will use for this purpose.Using format()Here we take a DataFrame and apply the format function to the column wher we need to append the zeros as strings. The lambda method is used to apply the function repeatedly.Exampleimport pandas as pd string = {'Column' : ['HOPE', 'FOR', 'THE', 'BEST']} dataframe=pd.DataFrame(string) print("given column is ") print(dataframe) ... Read More

Add list elements with a multi-list based on index in Python

Pradeep Elance
Updated on 18-Feb-2020 11:24:15

605 Views

Lists can be nested. Which means we have smaller lists as elements inside a bigger list. In this article we solve the challenge of adding the elements of a simple list to the elements of a nested list. If the length of the lists are different then the length of the smaller list becomes the maximum length of the resulting list.Below are the various methods to accomplish this.Using for LoopIn this method, we take the length of the smaller list and loop through the elements of this list adding it to the elements of the bigger list. Here we use ... Read More

Add image on a Python Tkinter button

Pradeep Elance
Updated on 18-Feb-2020 10:23:22

2K+ Views

Tkinter, which is the GUI library for python programming has a feature to add images to the GUI buttons. This is useful for users to remember the symbols in the GUI rather than the text in the GUI. In the below Tkinter program we show how we can add an image to a GUI button. The photoimage method from the imageKT module is used. We mention the local path to the image file.Examplefrom tkinter import * from PIL import ImageTk ,Image base = Tk() base.title('Start Button') img=ImageTk.PhotoImage(Image.open ("D:\button.jpg")) lab=Label(image=img) lab.pack() button=Button(base, text='exit', command=base.quit) button.pack() base.mainloop()OutputRunning the above ... Read More

Count all sub-sequences having product <= K – Recursive approach in C++

Ayush Gupta
Updated on 17-Feb-2020 10:49:05

225 Views

In this tutorial, we will be discussing a program to find the number of sub-sequences having product k) {       discard_count += power(2, n - i);       return;    }    if (i == n)       return;       float rem = prefix[n - 1] - prefix[i];    if (sum + a[i] + rem > k)       solve(i + 1, n, sum + a[i], k, a, prefix);    if (sum + rem > k)       solve(i + 1, n, sum, k, a, prefix); } int countSubsequences(const int* arr, ... Read More

Count all possible walks from a source to a destination with exactly k edges in C++

Ayush Gupta
Updated on 17-Feb-2020 10:45:04

149 Views

In this tutorial, we will be discussing a program to find the number of walks from a source to a destination with exactly k edges.For this we will be provided with a graph and the values of source and destination. Our task is to find all the possible paths starting from the source to the destination having exactly k edges.Example Live Demo#include using namespace std; #define V 4 //counting walks using recursion int countwalks(int graph[][V], int u, int v, int k){    if (k == 0 && u == v)       return 1;    if (k == 1 && graph[u][v])       return 1;    if (k

Count all prefixes of the given binary array which are divisible by x in C++

Ayush Gupta
Updated on 17-Feb-2020 10:40:52

117 Views

In this tutorial, we will be discussing a program to find the number of prefixes of the binary array which are divisible by x.For this we will be provided with binary array and a value x. Our task is to find the number of elements whose prefixes are divisible by given value x.Example Live Demo#include using namespace std; //counting the elements with prefixes //divisible by x int count_divx(int arr[], int n, int x){    int number = 0;    int count = 0;    for (int i = 0; i < n; i++) {       number = number ... Read More

Count all Quadruples from four arrays such that their XOR equals to ‘x’ in C++

Ayush Gupta
Updated on 17-Feb-2020 10:39:07

231 Views

In this tutorial, we will be discussing a program to find the number of quadruples from four arrays such that their XOR equals to x.For this we will be provided with four arrays and a value x. Our task is to count all the quadruples whose XOR is equal to the given value x.Example Live Demo#include using namespace std; //counting quadruples with XOR equal to x int count_quad(int a[], int b[], int c[], int d[], int x, int n){    int count = 0;    for (int i = 0 ; i < n ; i++)       for (int ... Read More

Advertisements