-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassign47.py
More file actions
15 lines (15 loc) · 845 Bytes
/
assign47.py
File metadata and controls
15 lines (15 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
my_string="""Strings are amongst the most popular data types in Python. We can create the strings by enclosing characters in quotes. Python treats single quotes the same as double quotes."""
print("The number of occurences of word string are:",my_string.lower().count("string"))
def count_words(str1):
list1=str1.split()
for k in range(0,len(list1)):
if list1[k].endswith("on")==True:
print("Occurences of word",list1[k],"with on at end are:",str1.count(list1[k]))
else:
continue
for k in range(0,len(list1)):
if (list1[k].startswith("on")!=True) and (list1[k].endswith("on")!=True) and (list1[k].find("on")!=(-1)):
print("Occurences of word",list1[k],"with on in between are:",str1.count(list1[k]))
else:
continue
count_words(my_string)