0% found this document useful (0 votes)
2 views3 pages

Ch-Strings 5Q

The document contains a series of programming questions related to string manipulation in Python. Each question provides a specific task, such as displaying characters, counting vowels, and identifying substrings, along with sample code and expected outputs. The questions aim to test and enhance the reader's understanding of string operations.

Uploaded by

anubhavjha315
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Ch-Strings 5Q

The document contains a series of programming questions related to string manipulation in Python. Each question provides a specific task, such as displaying characters, counting vowels, and identifying substrings, along with sample code and expected outputs. The questions aim to test and enhance the reader's understanding of string operations.

Uploaded by

anubhavjha315
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Ch-Strings Solved/Unsolved Questions

Q1: Consider the string, str1=”Green Revolution”. Implement the following:


A. To display the last 4 characters.
B. To check whether the string contains ‘vol’ or not.
C. To repeat the string 3 times.
Program:
str1=”Green Revolution”
#A
print(str1[-4:])
#B
‘vol’ in str1
#C
print(str1*3)
Output:

Q2: Write a program to count the number of vowels in a word.


Program:
word=input("enter a word: ")
count=0
for letter in word:
if letter in ('a','e','i','o','u'):
count+=1
print("the no of vowels are=",count)
Output:
Q3: Write a program that reads a line, then counts words and displays how
many words are there in the line.
Program:
line=input("enter line")
x=line.split()
count=0
for word in x:
count+=1
print("no of words=",count)
Output:

Q4: Write a program that reads a line, then counts how many times a substring
“is” appears in the line and displays the count.
Program:
str1=input("enter a line ")
str2="is"
x=str1.split()
count=0
for i in x:
if i==str2:
count+=1
print("substring is appearing",count,"times")
Output:

Q5: Write a program that reads a string and displays the occurrence of words
starting with a vowel in the given string.
Program:
str1=input("enter line ")
x=str1.split()
count=0
for z in x:
if z[0] in "aeiou" or z[0] in "AEIOU":
count+=1
print(z)
print("no. words starting with vowels are ", count)
Output:

You might also like