Found 26504 Articles for Server Side Programming

Print a Calendar in Python

Hafeezul Kareem
Updated on 12-Feb-2020 12:21:27

13K+ Views

In this tutorial, we are going to learn how to print the calendar of month and year using the calendar module of Python. It's a straightforward thing in Python. We need year and month numbers. That's it.Let's see how to print a year calendar. Follow the below steps to print the year calendar.Import the calendar module.Initialize the year number.Print the calendar using calendar.calendar(year) class.ExampleSee the below code. Live Demo# importing the calendar module import calendar # initializing the year year = 2020 # printing the calendar print(calendar.calendar(year))OutputIf you run the above code, you will get the following output.        ... Read More

Multiplication of two Matrices using Numpy in Python

Hafeezul Kareem
Updated on 12-Feb-2020 11:49:31

862 Views

In this tutorial, we are going to learn how to multiply two matrices using the NumPy library in Python. It's straightforward with the NumPy library.It has a method called dot for the matric multiplication. You can install the NumPy library with the following command.pip install numpyLet's see the steps involved in the program.Import the NumPy library.Initialize the matrices.Multiply the matrices with numpy.dot(matrix_1, matrix_2) method and store the result in a variable.Print the result.See the below code.Example# importing the module import numpy # initializing the matrices matrix_1 = [       [1, 2, 3], [4, 5, 6], [7, 8, 9] ... Read More

Move all zeroes to end of the array using List Comprehension in Python

Hafeezul Kareem
Updated on 12-Feb-2020 11:44:21

2K+ Views

Given a list of numbers, move all the zeroes to the end using list comprehensions. For example, the result of [1, 3, 0, 4, 0, 5, 6, 0, 7] is [1, 3, 4, 5, 6, 7, 0, 0, 0].It's a single line code using the list comprehensions. See the following steps to achieve the result.Initialize the list of numbers.Generate non-zeroes from the list and generate zeroes from the list. Add both. And store the result in a list.Print the new list.Example# initializing a list numbers = [1, 3, 0, 4, 0, 5, 6, 0, 7] # moving all the zeroes ... Read More

Merge, Join and Concatenate DataFrames using Pandas

Hafeezul Kareem
Updated on 12-Feb-2020 11:42:34

1K+ Views

In this tutorial, we are going to learn to merge, join, and concat the DataFrames using pandas library. I think you are already familiar with dataframes and pandas library. Let's see the three operations one by one.MergeWe have a method called pandas.merge() that merges dataframes similar to the database join operations. Follow the below steps to achieve the desired output. Merge method uses the common column for the merge operation.Initialize the Dataframes.Call the method pandas.merge() with three arguments dataframes, how (defines the database join operation), on (common field of the dataframes).ExampleLet's see an example.# importing the pandas library import pandas # creating dataframes   ... Read More

Get a google map image of specified location using Google Static Maps API in Python

Hafeezul Kareem
Updated on 12-Feb-2020 11:29:57

4K+ Views

Google provides a static maps API that returns a map image on our HTTP request. We can directly request for a map image with different parameters based on our need.We have to create a billing account on Google to use this API. You can go to the website for more details.Let's see the steps to get the image of a location.Import the requests module.Initialise your API Key and base URL ("https://maps.googleapis.com/maps/api/staticmap?").Initialize the city and zoom value.Update the URL with API Key, City, and Zoom value.USend an HTTP request. And write the response to a file for saving the image.pdate the ... Read More

Find current weather of any city using OpenWeatherMap API in Python

Hafeezul Kareem
Updated on 12-Feb-2020 11:25:39

9K+ Views

In this tutorial, we are going to get the weather of a city using OpenWeatherMap API. To use the OpenWeatherMap API, we have to get the API key. We will get it by creating an account on their website.Create an account and get your API Key. It's free until 60 calls per minute. You have to pay if you want more than that. For this tutorial, the free version is enough. We need requests module for the HTTP requests and JSON module to work with the response. Follow the below steps to the weather of any city.Import the requests and JSON ... Read More

Count frequencies of all elements in array in Python

Hafeezul Kareem
Updated on 12-Feb-2020 11:16:43

20K+ Views

In this tutorial, we are going to write a program that finds the frequency of all the elements in an array. We can find it in different ways let's explore two of them.Using dictInitialize the array.Initialize an empty dict.Iterate over the list.If the element is not in dict, then set the value to 1.Else increment the value by 1.Print the element and frequencies by iterating over the dict.ExampleLet's see the code.# intializing the list arr = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3] # initializing dict to store frequency of each element elements_count = {} ... Read More

Count all prefixes in given string with greatest frequency using Python

Hafeezul Kareem
Updated on 12-Feb-2020 11:10:44

627 Views

In this tutorial, we are going to write a program that counts and prints the words with a higher frequency of an alphabet than the second one.Take a string and two alphabets. The prefixes with a higher frequency of the first alphabet will be printed. And display the count at the end of the output.Let's see some examples.Inputstring:- apple alphabets:- p, eOutputap app appl apple 4Inputstring:- apple alphabets:- e, pOutput0Let's see the steps to write the code.Define a function and write the code in it.Initialize count to 0 and an empty string.Iterate over the string.Get the prefix using the string ... Read More

Count all possible position that can be reached by Modified Knight in C++

Ayush Gupta
Updated on 10-Feb-2020 12:13:17

117 Views

In this tutorial, we will be discussing a program to find the number of possible positions that can be reached by Modified Knight.For this we will be provided with a 8*8 chessboard. Our task is to find the number of positions Modified Knight can capture with the given number of steps.Example#include using namespace std; //finding the positions void findSteps(int current_row, int current_column, int curr, int board_size, int steps, int* visited){    //bound checking    if (current_row >= board_size || current_row < 0       || current_column >= board_size || current_column < 0       || curr > ... Read More

Count all possible paths from top left to bottom right of a mXn matrix in C++

Ayush Gupta
Updated on 10-Feb-2020 12:08:04

236 Views

In this tutorial, we will be discussing a program to find the number of possible paths from top left to bottom right of a mXn matrix.For this we will be provided with a mXn matrix. Our task is to find all the possible paths from top left to bottom right of the given matrix.Example#include using namespace std; //returning count of possible paths int count_paths(int m, int n){    if (m == 1 || n == 1)       return 1;    return count_paths(m - 1, n) + count_paths(m, n - 1); } int main(){    cout

Advertisements