Ticker

6/recent/ticker-posts

Python subjective question for competitive exam (20)

Q1.Program to implementation of stack using list.

s=[] ch='y' while(ch=='y'): op=input("enter the operation name you want to perform push or pop") if(op=="push"): item=input("enter item") s.append(item) elif(op=="pop"): s.pop() elif(op=="display"): for i in s: print(i) else: ch=input("enter no for not operation") Output >>> ==================== RESTART: C:\Users\Dell\Desktop\ss.py ==================== enter the operation name you want to perform push or poppush enter item1 enter the operation name you want to perform push or poppush enter item2 enter the operation name you want to perform push or poppush enter item3 enter the operation name you want to perform push or popdisplay 1 2 3 enter the operation name you want to perform push or poppop enter the operation name you want to perform push or popdisplay 1 2 enter the operation name you want to perform push or poppop enter the operation name you want to perform push or popdisplay 1 enter the operation name you want to perform push or pop enter no for not operationno >>>



Q2.Program to implement of queue using list

s=[] ch='y' while(ch=='y'): op=input("enter the operation name you want to perform add or remove") if(op=="add"): item=input("enter item") s.append(item) elif(op=="remove"): s.pop(0) elif(op=="display"): for i in s: print(i) else: ch=input("enter no for not operation") Output >>> ==================== RESTART: C:\Users\Dell\Desktop\ss.py ==================== enter the operation name you want to perform add or removeadd enter item1 enter the operation name you want to perform add or removeadd enter item2 enter the operation name you want to perform add or removeadd enter item3 enter the operation name you want to perform add or removeremove enter the operation name you want to perform add or removedisplay 2 3 enter the operation name you want to perform add or removeremove enter the operation name you want to perform add or removedisplay 3 enter the operation name you want to perform add or remove enter no for not operationno



Q3.Program to find sum of n number.

sum=0 n=int(input("enter the value of n ")) for i in range(n): sum=sum+i print(sum) Output >>> ==================== RESTART: C:\Users\Dell\Desktop\ss.py ==================== enter the value of n 10 45


Q4.Program to print number divisible by 5 from range 0 to 100.

n=int(input("enter the value of n ")) for i in range(n): if i%5==0: print(i) Output >>> ==================== RESTART: C:\Users\Dell\Desktop\ss.py ==================== enter the value of n 100 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95


Q5.Program to find area using function using default argument and positional argument.

def area(l,b=12): r=l*b print(r) area(2,3) area(1) Output >>> ==================== RESTART: C:\Users\Dell\Desktop\ss.py ==================== 6 12



Post a Comment

0 Comments