Ticker

6/recent/ticker-posts

Python subjective question for competitive exam (18)

Q1.Program to find big element from tuple.

def max(a): big=a[0] for i in range(len(a)): if a[i]>big: big=a[i] return big a=(1,2,3,4,5,6) print(max(a)) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/bb.py ==================== 6



Q2.Program to find minimum number from tuple.

def min(a): small=a[0] for i in range(len(a)): if a[i] < small: small=a[i] return small a=(1,2,3,4,5,6) print(min(a)) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/bb.py ==================== 1



Q3.Program to find mean of tuple numbers.

def mean(a): small=a[0] sum=0 for i in range(len(a)): sum=sum+a[i] avg=sum/len(a) return avg a=(1,1,1,1,1,1) print(mean(a)) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/bb.py ==================== 1.0


Q4.Program to search a element from tuple.

def search(a,x): for i in range(len(a)): if x==a[i]: return i return -1 a=(1,1,1,1,1,1) x=1 r=search(a,x) if(r==-1): print("element not found") else: print("element found at", r) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/bb.py ==================== element found at 0


Q5.Program to find entered number is armstrong or not.

n=int(input("enter a number")) sum=0 temp=n while temp>0: digit=temp%10 sum+=digit**3 temp//=10 if n==sum: print("number is armstrong") else: print("number is not armstrong") Output >>> ==================== RESTART: C:/Users/Dell/Desktop/bb.py ==================== enter a number3 number is not armstrong >>> ==================== RESTART: C:/Users/Dell/Desktop/bb.py ==================== enter a number153 number is armstrong



Post a Comment

0 Comments