Friday, February 1, 2019

Captilize each word

  • Problem Description

    Write a python program to create a file and Capitalise each word (Starting letter) in the file

    Hint:

    1. Create a File
    2. Take the input as number of lines to be written into the file
    3. File name to be searched

    Input:
    1. Filename
    2. The number of lines to be written into the file
    3. File name

    Output:
    Display the file content with capitalise of each word (Starting letter)
  • CODING ARENA
  • import os
    fname = input()
    a=int(input())
    with open(fname, 'w') as f:
        for i in range(a):
            x=input()
            l=x.title()
            f.write(l+ os.linesep)
    f.close()
    fnam=input()
    with open(fnam, 'r') as f:
        for line in f:
            print(line)
  • Test Case 1

    Input (stdin)
    sample.txt
    
    4
    
    This is First Line of the file
    
    This is Second Line of the file create in eLab Server
    
    This is Third Line sample line
    
    This is fourth line of the file and eLab is an auto evaluation tool launched in 2017
    
    sample.txt
    
    
    Expected Output
    This Is First Line Of The File
    
    
    
    This Is Second Line Of The File Create In Elab Server
    
    
    
    This Is Third Line Sample Line
    
    
    
    This Is Fourth Line Of The File And Elab Is An Auto Evaluation Tool Launched In 2017
  • Test Case 2

    Input (stdin)
    sample.txt
    
    2
    
    This is First Line of the file
    
    This is Second Line of the file create in eLab Server
    
    sample.txt
    
    
    Expected Output
    This Is First Line Of The File
    
    
    
    This Is Second Line Of The File Create In Elab Server

No comments:

Post a Comment