Found 34494 Articles for Programming

Python program to print a checkboard pattern of n*n using numpy.

Samual Sam
Updated on 30-Jul-2019 22:30:23

458 Views

Given the value of n, our task is to display the check board pattern for a n x n matrix. Different types of functions to create arrays with initial value are available in numpy . NumPy is the fundamental package for scientific computing in Python. Algorithm Step 1: input order of the matrix. Step 2: create n*n matrix using zeros((n, n), dtype=int). Step 3: fill with 1 the alternate rows and columns using a slicing technique. Step 4: print the matrix. Example Code import numpy as np def checkboardpattern(n): print("Checkerboard pattern:") ... Read More

Python program to cyclically rotate an array by one

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

1K+ Views

Given a user input array. Our task is to rotate cyclically means clockwise rotate the value. Example Input: A=[1, 2, 3, 4, 5] Output=[5, 1, 2, 3, 4] Algorithm Step 1: input array element. Step 2: Store the last element in a variable say x. Step 3: Shift all elements one position ahead. Step 4: Replace first element of array with x. Example Code # Python program to cyclically rotate #an array by one # Method for rotation def rotate(A, n): x = A[n - 1] for i in ... Read More

Python program to find common elements in three sorted arrays?

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

574 Views

Here first we create 3 array which are user input unsorted array, then we sort all 3 unsorted arrays. The size of the arrays are n1, n2, n3.starting address of every array is 0.i=0, j=0, k=0, then traverse all the elements of three array and check the element of three arrays are same or not ,if same then print the element otherwise go the next element. Example A = {1, 2, 3, 4, 5} B = {2, 5, 12, 22, 7} C = {1, 9, 2, 89, 80} Output 2 Algorithm commonele(A1, A2, A3, ... Read More

Python program to reverse an array in groups of given size?

Chandu yadav
Updated on 30-Jul-2019 22:30:23

508 Views

Here we use one user input array and the size of the group. And we create sub array on the size of the group and we just reverse it. If the size of the groups(p) is not multiple of the size of the array(n) then the last group will less than k elements left and reverse all remaining elements. If p=1 then array is unchanged, if p>=1 then we reverse all elements in the array. Algorithm Revarray(A, n, p) /* A is an integer Array, n is the size of an array and every sub-array of size p starting ... Read More

Python program to communicate between parent and child process using the pipe.

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

818 Views

Using fork is the easiest way to create child process.fork () is part of the os standard Python library. Here, we solve this task by using of pipe(). For passing information from one process to another pipe() is used. For two way communication two pipes can be use, one for each direction because pipe() is unidirectional. Algorithm Step 1: file descriptors r, w for reading and writing. Step 2: Create a process using the fork. Step 3: if process id is 0 then create a child process. Step 4: else create parent process. Example Code import os ... Read More

Python program to check the validity of a Password?

Samual Sam
Updated on 30-Jul-2019 22:30:23

2K+ Views

Here given a password, our task is to check that this Password is valid or not. Here we use re module that provide regular expression and re.search() is used for checking the validation of alphabets, digits or special characters. Algorithm Step 1: first we take an alphanumeric string as a password. Step 2: first check that this string should minimum 8 characters. Step 3: the alphabets must be between a-z. Step 4: At least one alphabet should be in Uppercase A-Z. Step 5: At least 1 number or digit between 0-9. Step 6: At least 1 character from [_ ... Read More

Python program to iterate over multiple lists simultaneously?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

237 Views

Here we use .zip() for iterative over multiple lists simultaneously.zip() takes n number of iterables and returns list of tuples. i-th element of the tuple is created using the ith element from each of the iterables. Example L1=[1, 2, 3, 4] L2=[‘aa’, ’bb’, ’cc’, ’dd’] L=zip(L1, L2) Output [(1, ’aa’), (2, ’bb’), (3, ’cc’), (4, ’dd’)] Algorithm Step 1: first create 3 user input list. Step 2 : use .zip() function. Step 3: print tuples. Example code # To iterate over 3 lists using zip function importitertools A=list() B=list() C=list() n = int(input("How many you ... Read More

Get emotions of images using Microsoft emotion API in Python?

Samual Sam
Updated on 23-Jun-2020 15:44:05

109 Views

Every human being have emotions just like happy, sad, neutral, surprise, sorrow etc., if we create the emotions of images like happy, sad, neutral, surprise, etc. in Python. We can use Microsoft emotion API for any development purpose.We can easily elaborate all these emotions using Microsoft emotion API's.Example Codeimport http.client, urllib.request import urllib.parse, urllib.error import base64, sys import simplejson as json # replace with subscription_key # you obtained after registration subscription_key = '23d39244dbe55173214b56ab45d56cla' headers = {    # Request for headers. And also replace the placeholder key with    # our subscription key.    'Content-Type': 'application/json',    'Ocp-Apim-Subscription-Key': ... Read More

Segregate 0’s and 1’s in an array list using Python?

Sarika Singh
Updated on 19-Dec-2022 12:06:22

1K+ Views

The elements in the contiguous memory address are contained in the linear data structure known as an array. At these places, it primarily groups components of the same data type. Given an array of integers. The array is to be divided into two halves, 0s and 1s, according to the article "Segregate 0s and 1s in an array." The array should have all the 0’s on the left and all the 1’s on the right. Input-Output Scenario Let’s consider an input and its output scenarios to segregate 0’s and 1’s in an array list - Input: [0, 1, ... Read More

Python program to check if there are K consecutive 1’s in a binary number?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

274 Views

First we take a user input string with the combination of 1’s and 0’s.then create a new string with 1’s, then check if there is any p number of consecutive 1’s is present or not. If present then display FOUND otherwise NOTFOUND. Example Binary number ::1111001111 Enter consecutive 1’s :3 Consecutive 1's is Found Algorithm Step 1: input a string with the combination of 1’s, it’s stored in the variable X and 0’s and p is the consecutive 1’s in a binary number. Step 2: form a new string of p 1’s. newstring=”1”*p Step ... Read More

Advertisements