CBSE CS and IP

CBSE Class 11 & 12 Computer Science and Informatics Practices Python Materials, Video Lecture

File Handling (3 Marks Questions)

  1. Write a program that copies a text file “Source.txt” onto “target.txt” barring the lines starting with a “@” sign.
    Click Here for Solution
  2. Write a user-defined function in Python that displays the number of lines starting with the letter ‘H’ in the file Para.txt, if the file contains.
    Click Here for Solution

1 comment:

  1. from os import path

    if path.isfile("source.txt") and path.isfile("target.txt"):

    with open("source.txt", 'r') as source:

    with open("target.txt", 'w') as target:

    for sentence in source.readlines():

    if not sentence.startswith('U'):

    target.write(sentence)

    print("Task executed successfully!")

    else: print("Some files seem to be missing...")

    ReplyDelete