Ticker

6/recent/ticker-posts

Python subjective question for competitive exam (27)

Q1.Program to compute polynomial equation.

import math print("enter the cofficient of the form ax^3+bx^2+cx+d") l=[] for i in range(0,4): a=int(input("enter cofficient")) l.append(a) x=int(input("enter value of x")) sum=0 j=3 for i in range(0,3): while(j>0): sum=sum+(l[i]*math.pow(x,j)) break j=j-1 sum=sum+l[3] print("the value of polynomial is",sum) Output >>> === RESTART: C:/Users/Dell/AppData/Local/Programs/Python/Python37-32/ss.py === enter the cofficient of the form ax^3+bx^2+cx+d enter cofficient1 enter cofficient1 enter cofficient1 enter cofficient1 enter value of x2 the value of polynomial is 15.0



Q2.Program to print identity matrix.

n=int(input("enter size")) for i in range(0,n): for j in range(0,n): if(i==j): print("1",sep=" ",end=" ") else: print("0",sep=" ",end=" ") print() Output >>> === RESTART: C:/Users/Dell/AppData/Local/Programs/Python/Python37-32/ss.py === enter size4 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1



Q3.Program to find entered number is perfect or not.

n=int(input("enter number")) sum=0 for i in range(1,n): if(n%i==0): sum=sum+i if(sum==n): print("number is perfect number") else: print("the number is not perfect number") === RESTART: C:/Users/Dell/AppData/Local/Programs/Python/Python37-32/ss.py === enter number6 number is perfect number === RESTART: C:/Users/Dell/AppData/Local/Programs/Python/Python37-32/ss.py === enter number10 the number is not perfect number


Q4.Program to check key present in dictionary or not.

d={1:"ram",2:"sham",3:"ravi"} key=int(input("enter the key want to search in dictionary")) if key in d.keys(): print("key is present") print(d[key]) else: print("key is not present in dictionary") Output >>> === RESTART: C:/Users/Dell/AppData/Local/Programs/Python/Python37-32/ss.py === enter the key want to search in dictionary2 key is present sham >>> === RESTART: C:/Users/Dell/AppData/Local/Programs/Python/Python37-32/ss.py === enter the key want to search in dictionary4 key is not present in dictionary


Q5.Program of transpose a matrix.

a=[[1,2],[3,4]] for i in range(len(a)): for j in range(len(a[0])): print(a[i][j],sep=" ",end=" ") print() print("matrix after transpose") for i in range(len(a)): for j in range(len(a[0])): print(a[j][i],sep=" ",end=" ") print() Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== 1 2 3 4 matrix after transpose 1 3 2 4



Post a Comment

0 Comments