Problem 1a. Write a function named hasFinalLetter that takes two parameters 1. strList, a list of non-empty strings 2. letters, a string of upper and/or lower case letters The function hasFinalLetter should create and return a list of all the strings in strList that end with a letter in letters.

Respuesta :

Answer:

The answer is the programming in Python language has strings and characters that has to be declared in the method.

Explanation:

#method

def hasFinalLetter(strList,letters):

output = #output list

#for every string in the strList

for string in strList:

#findout the length of each string in strList

length = len(string)

#endLetter is last letter in each string

endLetter = string[length-1]

#for each letter in the letters list

for letter in letters:

#compare with endLetter

#if we found any such string

#add it to output list

if(letter == endLetter):

output.append(string)

#return the output list

return output

#TestCase 1 that will lead to return empty list

strList1 = ["user","expert","login","compile","Execute","stock"]

letters1 = ["a","b","y"]

print hasFinalLetter(strList1,letters1)

#TestCse2

strList2 = ["user","expert","login","compile","Execute","stock"]

letters2 = ["g","t","y"]

print hasFinalLetter(strList2,letters2)

#TestCase3

strList3 = ["user","expert","login","compile","Execute","stock"]

letters3 = ["k","e","n","t"]

print hasFinalLetter(strList3,letters3)

The program is an illustration of loops.

Loops are used to perform repetitive operations.

The function in Python, where comments are used to explain each line is as follows:

#This defines the function

def hasFinalLetter(strList,letters):

   #This initializes  the output list

   result = []

   #This iterates through the strings in strList

   for string in strList:

       #This iterates through each letter in letters list

       for letter in letters:

           #If the last character of the current string ends in letter,

           if(letter == string[-1]):

               #The string is appended to the output string

               result.append(string)

   #This returns the output string

   return result

The above function is implemented using two for loops

Read more about similar programs at:

https://brainly.com/question/1855157

ACCESS MORE