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]
2 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]2 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
(a) Convert to hexadecimal: 1457.1110. Round to two digits past the hexadecimal point.
zaharov [31]

Answer:

Following is attached solution to each part. I hope it will help you!

Explanation:

4 0
3 years ago
Why are free web based providers so popular?
kipiarov [429]
The first one, Accessing is so important .
6 0
3 years ago
A __________ is the column of data in a database that is used as the basis for arranging data.
Llana [10]
The answer is sort key.  A Sort Key is the column of data in a database that is used as the basis for arranging data. Iy is also used for rearranging data in the column.  An Operational Database is used to collect, modify, and maintain data on a daily basis.
8 0
3 years ago
Read 2 more answers
Design a program that asks the user to enter a store’s sales for each day of the week. The amounts should be stored in an array.
sdas [7]

Answer:

Program given below

Explanation:

Total Sales

Assign the values of the variable as “Enter the store sales for Sunday” in Sun

Assign the values of the variable as “Enter the store sales for Monday” in Mon

Assign the values of the variable as “Enter the store sales for Tuesday” in Tue

Assign the values of the variable as “Enter the store sales for Wednesday” in Wed

Assign the values of the variable as “Enter the store sales for Thursday” in Thu

Assign the values of the variable as “Enter the store sales for Friday” in Fri

Assign the values of the variable as “Enter the store sales for Saturday” in Sat

Assign the values for the variable in array as [Sun, Mon, Tue, Wed, Thu, Fri, Sat]

Initialize tot = 0

Use the loop for calculating the total sales for the week,

for total_sales in store_sales:

    tot += total_sales

then display the result as,    

print "\n Total week sales = %2.f " %tot

sun = int(input("\n Enter the store sales for Sunday: "))

mon = int(input("\n Enter the store sales for Monday: "))

tue = int(input("\n Enter the store sales for Tuesday: "))

wed = int(input("\n Enter the store sales for Wednesday: "))

thu = int(input("\n Enter the store sales for Thursday: "))

fri = int(input("\n Enter the store sales for Friday: "))

sat = int(input("\n Enter the store sales for Saturday: "))

store_sales = [sun, mon, tue, wed, thu, fri, sat]

tot = 0

for store_sale in store_sales:

tot += store_sale

print "\n Total Week Sales: %2.f" %tot

We will have the following output:

<u>OUTPUT </u>

<u> </u>Enter the store sales for Sunday: 45

Enter the store sales for Monday: 56

Enter the store sales for Tuesday: 89

Enter the store sales for Wednesday:78

Enter the store sales for Thursday: 45

Enter the store sales for Friday: 12

Enter the store sales for Saturday: 23

Total Week Sales: 348

8 0
3 years ago
                                                       HELP PLEASE 
Marina CMI [18]
Your answer should be mode







5 0
3 years ago
Read 2 more answers
Other questions:
  • What is the IEEE standard for the Wi-Fi Protected Access 2 (WPA2) security protocol?
    6·1 answer
  • Fill the validateForm function to check that the phone number contains a number (use the isNaN function) and that the user name
    10·1 answer
  • Write a function getPigLatin(pigStr) that accepts pigStr as a parameter (a sentence as input) and converts each word to "Pig Lat
    8·1 answer
  • How to build an arch bridge​
    5·1 answer
  • You run the ipconfig command on your computer, and it reports an IP address of 169.254.75.10 on the Ethernet interface. Which de
    8·1 answer
  • Enterprise Resource Planning (ERP) is an example of a single user database.
    7·1 answer
  • 27. If X and Y are int type variables,
    14·1 answer
  • How does this happen on brianly???
    5·2 answers
  • If the disaster requires actions offsite from the primary infrastructure, it is under the jurisdiction of__________.
    7·1 answer
  • The new software analyzes sales conversion per sales in a way intended to increase sales success. what is the first thing you mu
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!