Advertisement
ALENTL

4.py

Jul 14th, 2022
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. """"
  2. create file
  3. no of sentences
  4. words ending with s
  5. sentences beginning with a
  6. """
  7.  
  8. def createFile():
  9.     with open('lab4.txt', 'w') as file:
  10.         a = input("Enter the content of the text file: ")
  11.         file.write(a)
  12.     print("File Created")
  13.  
  14. def countSentences():
  15.     with open('lab4.txt') as file:
  16.         a = file.read()
  17.         b = a.split('.')
  18.        
  19.         count = 0
  20.  
  21.         for k in b:
  22.             count = count + 1
  23.  
  24. def wordEndA():
  25.     with open('lab4.txt') as file:
  26.         a = file.read()
  27.         b = a.split()
  28.  
  29.         for k in b:
  30.             if k[-1] == "s":
  31.                 print(k)
  32.             elif k[-1] == "." and k[-2] == "s":
  33.                 print(k)
  34.  
  35. def sentenceBeginA():
  36.     with open('lab4.txt') as file:
  37.         a = file.read()
  38.         b = a.split('.')
  39.  
  40.         for k in b:
  41.             if k[0] in "aA":
  42.                 print(k)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement