Python help needed in a problem of string

You are given an array strarr of strings and an integer k . Your task is to return the first longest string consisting of k consecutive strings taken in the array.


longest_consec([“zone”, “abigail”, “theta”, “form”, “libe”, “zas”, “theta”, “abigail”], 2) --> “abigailtheta”

n being the length of the string array, if n = 0 or k > n or k <= 0 return “”.



`> def longest_consec(strarr, k):
      string_s=str(input("enter some comma separated value"))
      for a in range(0,k):
      if(n>k or k<=0):
        return longest_consec[a]


the code of mine is above.i have to check the longest string and return it.but
the error shows
Traceback (most recent call last):
File “”, line 8, in
testing(longest_consec([“zone”, “abigail”, “theta”, “form”, “libe”, “zas”], 2), “abigailtheta”)
File “/home/codewarrior/”, line 4, in longest_consec
string_s=str(input(“enter some comma separated value”))
EOFError: EOF when reading a line

please help me.

There’s a lot going on here that needs to be fixed first

longest_consec is the name of the function, so what is longest_consec[a] supposed to mean? Right now that’s just a straight up error

the indentation is wild, I hope that’s just a formatting error from copy pasting the code, but it’ll probably fail to run otherwise? not sure how strict python is with this

Why is there a strarr argument that’s not used? Alternatively, why do you get user input when you have a strarr argument to the function?

did you really mean while k > 0: ? k will pretty much always be greater than 0 right? especially with that k = k + 1 line you have

is that for and if meant to be inside the while loop? I think perhaps not…

there’s a lot that needs to be cleaned up here first