Ticker

6/recent/ticker-posts

Python subjective question for competitive exam (25)

Q1.Operator overloading in python.

print(1+2) print("ram"+"kumar") print(3*4) print("ram"*4) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== 3 ramkumar 12 ramramramram



Q2.Evaluate postfix expression using stack.

op=set(['+','-','*','/','**']) def evalexpre(exp): stack=[] for i in exp: if i not in op: stack.append(i) else: a=stack.pop() b=stack.pop() if i=='+': res=int(a)+int(b) elif i=='-': res=int(a)-int(b) elif i=='*': res=int(a)*int(b) elif i=='/': res=int(a)/int(b) elif i=='**': res=int(a)**int(b) stack.append(res) return(''.join(map(str,stack))) exp=input("enter postfix expression") print() print(evalexpre(exp)) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter postfix expression23+5* 25



Q3.Program to find lcm of two number.

def lcmcal(x,y): if x>y: greater=x else: greater=y while(True): if((greater % x==0)and(greater % y==0)): lcm=greater break greater+=1 return(lcm) print(lcmcal(23,2)) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== 46


Q4.Program to find hcf of two number.

def hcfcal(x,y): if x>y: small=y else: small=x for i in range(1,small+1): if((x%i==0)and(y%i==0)): hcf=i return(hcf) print(hcfcal(28,21)) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== 7


Q5.Program to remove duplicate element from list.

l=[1,2,3,4,5,1,2,3] tl=[] for i in l: if i not in tl: tl.append(i) l=tl print(l) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== [1, 2, 3, 4, 5]



Post a Comment

0 Comments