Ticker

6/recent/ticker-posts

Python subjective question for competitive exam (13)

Q1.Program to find area using default argument.

def area(x,y=3): print(x*y) area(2) area(2,4) output >>> ==================== RESTART: C:/Users/Dell/Desktop/aa.py ==================== 6 8

Q2.Program to print pyramid

for i in range(0,5): for j in range(0,i+1): print("*", end=" ") print("\r") Output * * * * * * * * * * * * * * *



Q3.Program to find fibonacci series

n=10 num1=0 num2=1 nextnumber=num2 count=1 while count<=10: print(nextnumber, end=" ") count=count+1 num1,num2=num2,nextnumber nextnumber=num1+num2 Output ==================== RESTART: C:/Users/Dell/Desktop/aa.py ==================== 1 2 3 5 8 13 21 34 55 89

Q4.Program to find factorial using recursion.

def fact(n): if(n==1): return(1) else: f=n*fact(n-1) return(f) n=int(input("enter a number")) print(fact(n)) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/aa.py ==================== enter a number5 120

Q5. Program to find factorial using iterative method.


fact=1 n=int(input("enter a number")) for i in range(2,n+1): fact=fact*i print(fact) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/aa.py ==================== enter a number6 720



Post a Comment

0 Comments