CBSE Class 11 Computer Science
Question 18 of 19
Strings in Python — Question 18
Back to all questions 18
Question Write a program that reads a line, then counts how many times the word 'is' appears in the line and displays the count.
line = input("Enter a line: ")
line = line.lower()
words = line.split()
count = words.count('is')
print("The word 'is' appears", count, "times.")Enter a line: The project is ambitious, and its success is dependent on how well it is managed and executed.
The word 'is' appears 3 times.
line
=
input
(
"Enter a line: "
)
line
=
line
.
lower
()
words
=
line
.
split
()
count
=
words
.
count
(
'is'
)
print
(
"The word 'is' appears"
,
count
,
"times."
)
Output
Enter a line: The project is ambitious, and its success is dependent on how well it is managed and executed.
The word 'is' appears 3 times.