Computer Science, asked by sarmisthasahoo310, 10 months ago


Q.1 Write a single loop to display all the contents of a text file “file.txt” after removing leading and trailing whitespaces.
Q.2 Write function fle_long() that accepts a filename and reports the file;’s longest line.
Q.3 What is the output of the following code in the below image - explain​

Answers

Answered by poojan
6

Language using: Python Programming

A) A single loop to display all the contents of a text file “file.txt” after removing leading and trailing whitespaces.

Program:

f=open('brainly.txt','r')

for i in f:

   x=i.strip()

   if x!='':

       print(x)

B) function fle_long() that accepts a filename and reports the file;’s longest line.

Program:

def file_long(f):

   long=""

   for i in f:

       if len(i)>len(long):

           long=i

   print(long)

file_long(open('brainly.txt','r'))

Learn more:

1) Printing all the palindromes formed by a palindrome word.

brainly.in/question/19151384

2) Indentation is must in python. Know more about it at :

brainly.in/question/17731168

Answered by jinceps99gmailcom
0

Answer:

Q1. Ans    

f=open('file.txt')    

for k in list(f):

       print(k.strip(),end='')

Q2. Ans

def file_long(f):

  long=""

  for i in list(f):

      if len(i)>len(long):

          long=i

  print(long)

file_long(open('brainly.txt','r'))

Explanation:

Object is converted into list  of lines and removing white spaces

Similar questions