1.

A text file “Quotes.Txt” has the following data written in it:Living a life you can be proud ofDoing your bestSpending your time with people and activities that are important to youStanding up for things that are right even when it’s hardBecoming the best version of youWrite a user defined function to display the total number of words present in the file.

Answer»

def countwords():

s= open("Mydata", "r")

f = s.read()

z= f.split()

count = 0

for i in z :

count = count+1

print "Total number of words", count



Discussion

No Comment Found

Related InterviewSolutions