You are on page 1of 2

STRING QUESTIONS:

6.What will be the output of the following programming code?


x = 'AmaZing'
print(x[3:],'and',x[:2])
print(x[-7:],'and',x[-4:-2])
print(x[2:7],'and',x[-4:-1])

17.Write a program to count the number of vowels in the string ‘pineapple’.


word = 'pineapple'
count = 0
for letter in word:
if letter in ('i', 'u', 'a', 'e', 'o'):
count = count+ 1
print(count)
18. What will be the output of the following program snippet?
str = 'aNDarIeL'
nstr = ''
for i in range(len(str)):
if str[i].isupper():
nstr = nstr + str[i].lower()
else:
nstr = nstr + str[i].upper()
print(nstr)
26. Write a program to remove vowels from a string.
Ans:
str1=input("enter string")
str2=""
for i in range(len(str1)):
if str1[i] not in "ieouaAEIOU":
str2 = str2+str1[i]
print("original string:", str1)
print("new string is:",str2)
27.What will be the output of the following program?
mes1=["SKy"]
mes2=["ThE"]
mes3=["LiMIT"]
l1 = len(mes1)
l2 = len(mes2)
l3 = len(mes3)
n = l1+l2+l3
for C in range(1,n):
if (C%4 == 0):
print(mes2)
l2 = l2 -1
else:
if (C%3 == 0):
print(mes1)
l1 = l1 - 1
else:
print(mes3)
l3 = l3 - 1

You might also like