Create a function that returns the fifth character in every line.?

In this exercise, your function will receive 1 parameter,

the name of a text file. The function will return a string

created by concatenating the fifth character from each line

into one string. If the line has fewer than 5 characters,

then the line should be skipped. All lines should have

leading and trailing whitespace removed before looking for

the fifth character.

### Function Name

fifthchar

### Parameters

* `filename` : a string value (the name of a file to open)

### Return Value

A string made from the fifth character of each line that has at least 5 characters.

This is what I came up with, and this is the error im getting:

"AssertionError: False is not true : fifthchar(otqlsjtm.txt) returned p

mkte

p

nppg

w. It should have returned pmktepnppgw. Check your logic and try again."

Does anyone know how to remove those spaces?

Attachment image

2 Answers

Relevance
  • EddieJ
    Lv 7
    2 months ago
    Favorite Answer

    line.strip ()

    does NOT alter line.  You need:

    line = line.strip ()

    You could have:

    if len (line) >= 5: output += line [4]

    I'm assuming that this is Python.  That should have been the first word in your headline.

    I suggest that you include the actual text of your code so that we can run it.

  • Anonymous
    2 months ago

     Ça me fout.                            

Still have questions? Get your answers by asking now.