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
Liono4ka [1.6K]
3 years ago
13

Write a function that takes a list value as an argument and returns a string with all the items separated by a comma and a space

, with and inserted before the last item. For example, passing the previous spam list to the function would return 'apples, bananas, tofu, and cats'. But your function should be able to work with any list value passed to it.
Computers and Technology
1 answer:
Vsevolod [243]3 years ago
4 0

Answer:

The function in Python is as follows:

def myfunction(mylist):

    listitems = ""

    for i in range(len(mylist)):

         if (i < len(mylist)-1):

              listitems = listitems + mylist[i] + ", "

         else:

              listitems = listitems + "and "+mylist[i]

   

    return listitems

Explanation:

This defines the function

def myfunction(mylist):

This initializes an empty string which in the long run, will be used to hold all strings in the list

    listitems = ""

This iterates through the list

    for i in range(len(mylist)):

For list items other than the last item, this separates them with comma (,)

         if (i < len(mylist)-1):

              listitems = listitems + mylist[i] + ", "

For the last item, this separates with and

         else:

              listitems = listitems + "and "+mylist[i]

   

This returns the required string

    return listitems

You might be interested in
Jennifer has written a short story for children. What should be her last step before she submits the story for publication?
SSSSS [86.1K]

Answer:

What is the choice of being answer c?

6 0
3 years ago
Assume that a file contains students' ids, full names, and their scores (Assignments grade, quizzes grade,
elixir [45]

Answer:

اope its heمحبعم

Explanation:

3 0
3 years ago
Do all light bulbs server a practical purpose?
Greeley [361]

Answer:

A light bulb produces light from electricity

6 0
3 years ago
Differences between mechanical and optical mouse <br>Plz help me
lutik1710 [3]
Mechanical mouse has a ball that turns rollers inside. If friction is lost between the ball and the mousing surface, or between the ball and the rollers, the mouse fails to work. In order to assure good contact with the mousing surface, the ball must be fairly heavy. When you change directions with the mouse, you must make the ball change rolling directions--an action that inertia likes to prevent.

An optical mouse makes use of an LED and some optics to detect surface texture and the changes in it as the mouse is moved. There are no moving parts
7 0
3 years ago
Isabel received a message on her computer that appeared to be from the FBI. It informed her that her computer has been locked an
Strike441 [17]

Answer:

Option C is the correct option.

Explanation:

When any email or message is received from the FBI in the user's computer system and the following message is about the user's computer system has been locked and they demand some amount to unlock their data or information.

So, the following scenario is about the ransomware because they ransom money to retrieve their data and information from the system.

5 0
3 years ago
Other questions:
  • What item on a business card is generally the most prominent?
    13·2 answers
  • Discuss anomaly detection.
    5·1 answer
  • Justin Blake and Raegan Beast anyone?? I miss Jaegan a ton and I need a fangirl to talk to.
    13·1 answer
  • Suppose you have an int variable called number. What Java expression produces the second-to-last digit of the number (the 10s pl
    15·1 answer
  • Question 2 of 10
    12·1 answer
  • A typical day in programming and software development would involve
    7·1 answer
  • MULTI SELECTION
    9·1 answer
  • Anyone want to play mine mincraft w/ me?
    9·1 answer
  • How do you initiate a sprite’s actions in a scene?
    8·1 answer
  • scheduling is approximated by predicting the next CPU burst with an exponential average of the measured lengths of previous CPU
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!