100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Computer Science – Text Files $2.99   Add to cart

Exam (elaborations)

Computer Science – Text Files

 1 view  0 purchase
  • Course
  • Institution

Computer Science – Text Files – 25 Exam based Questions with Answers – 4 Pages - Very Helpful for Students and Teachers

Preview 1 out of 4  pages

  • September 9, 2024
  • 4
  • 2024/2025
  • Exam (elaborations)
  • Questions & answers
  • Secondary school
  • 5
avatar-seller
Text File – Exam based questions

Write a function in python to count the number Write a user defined function countwords() to
lines in a text file ‘Country.txt’ which is starting display the total number of words present in the
with an alphabet ‘W’ or ‘H’. file from a text file “Quotes.Txt”.
def count_W_H():
f = open (“Country.txt”, “r”) def countwords():
W,H = 0,0 s = open("Quotes.txt","r")
r = f.read() f = s.read()
for x in r: z = f.split ()
if x[0] == “W” or x[0] == “w”: count = 0
W=W+1 for i in z:
elif x[0] == “H” or x[0] == “h”: count = count + 1
H=H+1 print ("Total number of words:", count)
f.close()
print (“W or w :”, W)
print (“H or h :”, H)

Write a user defined function countwords() to Write a function COUNT_AND( ) in Python to read
display the total number of words present in the the text file “STORY.TXT” and count the number
file from a text file “Quotes.Txt”. of times “AND” occurs in the file. (include
def countwords(): AND/and/And in the counting)
s = open("Quotes.txt","r") def COUNT_AND( ):
f = s.read() count=0
z = f.split () file=open(‘STORY.TXT','r')
count = 0 line = file.read()
for i in z: word = line.split()
count = count + 1 for w in word:
print ("Total number of words:", count) if w ==’AND’:
count=count+1
print(count)
file.close()

Write a function DISPLAYWORDS( ) in python to Write a function that counts and display the
display the count of words starting with “t” or “T” number of 5 letter words in a text file “Sample.txt
in a text file ‘STORY.TXT’. def count_words( ):
def COUNT_AND( ): c=0
count=0 f = open("Sample.txt")
file=open(‘STORY.TXT','r') line = f.read()
line = file.read() word = line.split()
word = line.split() for w in word:
for w in word: if len(w) == 5:
if w[0] ==’t’ or w[0]==’T’: c += 1
count=count+1 print(c)
print(count)
file.close()

Write a function that counts and display the Write a function that counts and display the
number of 5 letter words in a text file “Sample.txt number of 5 letter words in a text file “Sample.txt
def count_words( ): def count_words( ):
c=0 c=0
f = open("Sample.txt") f = open("Sample.txt")

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller kbzone. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $2.99. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

79271 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$2.99
  • (0)
  Add to cart