1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
erma4kov [3.2K]
3 years ago
14

Write the function longest that, given a nonempty list of strings, finds the longest even-length string that ends with ing. It t

akes a list of strings L as input and returns a string. If there are many longest strings, return the first. If there are no such strings, return the empty string (which clearly indicates that no string was found, since a valid string would need to be at least length 3).
Computers and Technology
1 answer:
lorasvet [3.4K]3 years ago
8 0

Answer:

  1. def longest(L):
  2.    for x in L:
  3.        if(len(x) % 2 == 0):
  4.            if(x.endswith("ing")):
  5.                return x  
  6.    return ""
  7. print(longest(["Playing", "Gaming", "Studying"]))

Explanation:

The solution is written in Python 3.

Firstly, create a function longest that takes one parameter L as required by question (Line 1).

In the function, create a for loop to traverse through each string in L and check if the current string length is even (Line 2 - 3). If so, use string endwiths method to check is the current string ended with "ing". If so return the string (Line 4-5).

At last, test the function by passing a list of string and we shall get the output "Gaming".

You might be interested in
What does the program print out as a result of the given snippet of code?
dexar [7]

Answer:

5

Explanation:

well the function len gives the length of the list

so the length of supplies is

5

7 0
3 years ago
Read 2 more answers
Assume you have the following array: int[] values = new int[15]; What will happen if the following code is executed? int[15] = 2
andrey2020 [161]

Answer:

You are creating an array "values" which stores 15 integers. And if we will write int[15]=20, we are not following correct syntax. Hence, nothing will happen, and it might however, throw an error that the syntax is wrong.

Explanation:

int[15]=20 is a wrong syntax, and hence nothing will happen or computer might throw an error like that not correct syntax is being used. And if we write values[15]=20,  It will certainly throw ArrayIndexOutOfBoundsException as the maximum length is fixed to 15 and values[14] and not more than that.  

3 0
4 years ago
Code the function definition for aNonclassFunction, picking up co. aNonclassFunction has no return value.
enot [183]

Answer:

b)void aNonclassFunction (Banana co);

Explanation:

In the function definition you have to pass the tell the function which type of argument it is taking.In our case we are taking a variable co of Banana type passing it to the function named aNonclassFunction having no return type.

So the definition will be like this.

void aNonclassFunction (Banana co);

6 0
3 years ago
Explain how for loops can be used to work effectively with elements in an array?
tresset_1 [31]

Explanation:

There are three types of loops in programming languages which are as following:-

  1. for.
  2. while.
  3. do while.

The syntax for all the three loops is different.You will see mostly for loop used with the arrays because they are easy to implement.

the syntax of for loop is :-

for(int i=initial value;condition;i++)

{

body

}

In for loops you only have to write the conditions in only line else is the body of the loop.

for example:-

for array of size 50 printing the each element

for(int i=0;i<50;i++)

{

   cout<<arr[i]<<" ";

}

You have to initialize i with 0 and the condition should be i<size of the array and then increase the counter.

7 0
3 years ago
What do the Sikh people wear on their head?
Mama L [17]

Answer:

Explanation:

It is called "Turban"

Sikhs wear the turban, to take care of the hair, promote equality, and preserve the Sikh identity

4 0
3 years ago
Read 2 more answers
Other questions:
  • Where can audiovisual technology and materials be found? (Select all that apply.)
    14·1 answer
  • The ability to anticipate and determine upcoming driving hazards and conditions are adversely affected by stress.
    10·1 answer
  • Assuming x and y are variables of type float, the expression:
    6·1 answer
  • Which statement does not describe the guidelines for the use of text in presentation programs?
    7·1 answer
  • PLEASE HELP ME ASAP!!! THIS IS DUE SOON!!
    9·1 answer
  • The file format that an application can always open a named collection of data on a storage medium such as a hard disk or usb fl
    13·1 answer
  • What is the inflation rate if the price of a soda was $10 last year, but only $5 this year?
    5·1 answer
  • The base 10 number 18 is equal to which base 16 number?<br><br> 10<br><br> 12<br><br> 14<br><br> 16
    11·1 answer
  • Dash transfers several bits of data together at one time<br>​
    6·1 answer
  • JQuery uses CSS selectors to select elements?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!