Category: Python
Posts of Category: Python
TOP TAGS :
1. ## Write a NumPy program to compute the x and y coordinates for points on a sine curve and plot the points using matplotlib.

import numpy as np import matplotlib.pyplot as plt # Compute the x and y coordinates for points on a sine curve x = np.arange(0, 3 * np.pi, 0.2) y = np.sin(x) print("Plot the points using matplotlib:") plt.plo...Learn More
2. ## Write a NumPy program to repeat elements of an array.

import numpy as np x = np.repeat(3, 4) print(x) x = np.array([[1,2],[3,4]]) print(np.repeat(x, 2)) ...Learn More
3. ## Program to Print the Double Pyramid Star Pattern

row_size=int(input("Enter the row size:"))for out in range(row_size,-(row_size+1),-1):Â Â for inn in range(0,abs(out)+1):Â Â Â Â print("*",end="")Â Â print("\r") ...Learn More
4. ## Python Program to Print Border of given Tree in Anticlockwise Direction

class BinaryTree: def __init__(self, key=None): self.key = key self.left = None self.right = None Â def set_root(self, key): self.key = key Â def inorder(self): if self.left is not None: self.left.inorder() pr...Learn More
5. ## Program to Sort an array in Descending order

arr=[]size = int(input("Enter the size of the array: "))print("Enter the Element of the array:")for i in range(0,size):Â Â num = int(input())Â Â arr.append(num)print("Before sorting array elements are:")for i ...Learn More
6. ## Python Program to Find Minimum Spanning Tree using Krusalâ€™s Algorithm

class Graph: def __init__(self): # dictionary containing keys that map to the corresponding vertex object self.vertices = {} Â def add_vertex(self, key): """Add a vertex with the given key to the graph.""" ver...Learn More
7. ## Program to print series -1 4 -7 10 -13 16 -19...n

print("Enter the range of number(Limit):") n=int(input()) i=1 se=1 while(i<=n): Â Â if(i%2==0): Â Â Â Â print(se,end=" ") Â Â else: Â Â Â Â print(-1*se, end=" ") Â Â se+=3 Â Â i+=1 ...Learn More
8. ## Find the sum of digits of a number using recursion

def SumOfDigits(num):Â Â if num==0:Â Â Â Â return 0Â Â else:Â Â Â Â return ((num%10) +SumOfDigits(num//10))num=int(input("Enter the Number:"))print("Sum of digits of given Number Using Recursion is:",SumOfDigi...Learn More
9. ## Find the Minimum occurring character in given string

str=input("Enter Your String:")min=999arr=[0]*256for i in range(len(str)):Â Â if str[i]==' ':Â Â Â Â continueÂ Â num=ord(str[i])Â Â arr[num]+=1ch=' 'for i in range(len(str)):Â Â if arr[ord(str[i])] != 0:Â Â Â ...Learn More
10. ## Program to print the Solid Half Diamond Alphabet Pattern

row_size=int(input("Enter the row size:"))for out in range(row_size,-(row_size+1),-1):Â Â for inn in range(row_size,abs(out)-1,-1):Â Â Â Â print((chr)(inn+65),end="")Â Â print("\r") ...Learn More
11. ## Python Program to Exchange the Values of Two Numbers Without Using a Temporary Variable

Â a=int(input("Enter value of first variable: ")) b=int(input("Enter value of second variable: ")) a=a+b b=a-b a=a-b print("a is:",a," b is:",b) ...Learn More
12. ## Program to Find square of a matrix

# Taking input of the matrix print("Enter the Matrix Element:") for i in range(row_size): matrix.append([int(j) for j in input().split()]) # compute square of the matrix for i in range(0,row_size): for j in ra...Learn More