Ticker

6/recent/ticker-posts

Python subjective question for competitive exam (26)

Q1.Program to print even length word in string.

s=input("enter string") word=s.split() for i in word: if len(i)%2==0: print(i) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter string my name is xyz and i am yy standard my name is am yy standard



Q2.Program to search substring in string.

str=input("enter string") sub=input("enter substring want to search in string") if sub in str: print("substring",sub,"present in",str) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter string my name is hello enter substring want to search in stringhello substring hello present in my name is hello



Q3.Program to find number of uppercase and lowercase in string.

str=input("enter string") u=0 l=0 for i in str: if i>='A' and i<='Z': u=u+1 if i>='a' and i<='z': l=l+1 print("string is ",str) print("uppercase letter in string",u) print("lowercase letter in string",l) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter string my name is XYZ string is my name is XYZ uppercase letter in string 3 lowercase letter in string 8


Q4.Program to swap first element of list with last element of list.

l=[1,2,3,4,5,6,7,8,9,10] print(l) le=len(l) temp=l[0] l[0]=l[le-1] l[le-1]=temp print("after swapping first or last element of list then list is",l) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] after swapping first or last element of list then list is [10, 2, 3, 4, 5, 6, 7, 8, 9, 1]


Q5.Program to print number of vowel present in string.

l=['a','e','i','o','u','A','E','I','O','U'] str=input("enter string") count=0 for i in str: if i in l: count=count+1 print(count) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter string python program and data 6



Post a Comment

0 Comments