Page 10 - PYTHON-12
P. 10

(b)  SELECT COUNT(*) FROM Hospital
                     WHERE Age>35;
                  (c)  SELECT Name,HOD.Department,HOD_name
                     FROM Hospital,HOD
                     WHERE Hospital.Department = HOD.Department;
              28.  Write a function convert() in Python that copies contents of S.txt to NS.txt after converting first letter
                 of every line to capital.                                                                  (3)
                  Example, If the file "S.txt"contents are as follows:
                      this is a File
                      this is a new File
                      python can create files
                      this is a text file
                  then file "NS.txt" should have:
                      This is a File.
                      This is a new File
                      Python can create files
                      This is a text file
                                                            OR
                  Write a function AMCount()in Python which should read each character of a text file "PLAY.TXT"and
                 count lines ending with a vowel and display the count.
                  Example:
                  If the file content "PLAY.TXT" are:
                  We are on first line.
                  Second line is in C++
                  Third line is in Python
                  Fourth line is in Java
                  Fifth line is in Go
                  Then it should display
                  Number of lines ending with a vowel: 2
             Ans.  def convert():
                     F1=open("S.txt","r”")
                     F2=open("SN.txt""w")
                     while True:
                      s=F1.readline()
                      if s=="":
                        break
                      n=S[0].upper()+S[1:]
                      F2.write(n+"\n")
                     F1.close()
                     F2.close()
                                                            OR
                 def AMCount():
                     F=open("PLAY.txt","w")
                     count=0
                     while True:
                      s=F.readline()
                      if s=="":
                        break
                      if s[-1] in "aeiouAEIOU":
                        count+=1
                     print("Number of lines:",count)
                     F.close()


            Appendices                                                                                     A.35
   5   6   7   8   9   10   11   12   13   14   15