Category: Python
Posts of Category: Python
  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
    Python
  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
    Python
  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
    Python
  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
    Python
  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
    Python
  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
    Python
  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
    Python
  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
    Python
  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
    Python
  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
    Python
  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
    Python
  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
    Python