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
Len [333]
1 year ago
11

Write the function definition for a function called list_total that accepts a list of integers

Computers and Technology
1 answer:
uranmaximum [27]1 year ago
7 0

Answer:

def list_total(numbers):

   sum_of_numbers = 0

   for number in numbers:

       sum_of_numbers += number

   return sum_of_numbers

Explanation:

So, to define a function, the syntax is simply:

def functionName(arguments here):

   # code

So to define a function called "list_total" which accepts a list of integers, you write:

"

def list_total(numbers):
   # code

"

any the "numbers" is a parameter, and it's just like any variable, so you can name it anything besides keywords. I just named it "numbers" since it makes sense in this context, you could also write "integers" instead and it would be just as valid, and may be a bit more specific in this case.

Anyways from here, the initial sum should be equal to 0, and from there we add each number in the list to that initial sum. This can be done by initializing a variable to the value "0" and then traversing the list using a for loop. This can be done as such:

"

def list_total(numbers):

   sum_of_numbers = 0

   for number in numbers:

       # code

"

So for each element or integer in the list "numbers" the for lop will run, and the variable "number" will contain the value of the current element it's on.

So we can add the "number" to the sum_of_numbers as such:

sum_of_numbers = sum_of_numbers + number

but there is a shorter way to do this, and it's represented as:

sum_of_numbers += sum_of_numbers

which will do the same exact thing. In fact this works for any mathematical operation for example:

a *= 3

is the same thing as

a = a * 3

and

a /= 3

is the same thing as

a = a / 3

It's the same thing, but it's a much shorter and more readable notation.

Anyways, this code will go in the for loop to almost finish the code

"

def list_total(numbers):

   sum_of_numbers = 0

   for number in numbers:

       sum_of_numbers += number

"

The last thing is to return this value, and this is simply done by using the syntax:

"return {value here}"

and since the sum_of_numbers has the value, we write

"return sum_of_numbers"

at the end of the function, which is very very important, because when you use the return keyword, you end the function, and return whatever value is next to the return to the function call

So to finish the code we just add this last piece to get:

"

def list_total(numbers):

   sum_of_numbers = 0

   for number in numbers:

       sum_of_numbers += number

   return sum_of_numbers

"

You might be interested in
How could TWC continue to leverage mobile apps to further monetize its significant investment in its weather data? What addition
Ann [662]

<u>Explanation</u>:

To effectively Monetise mobile apps the latest trend usually involves focusing on user downloads and active user subscriptions.

Since TWC is a weather data analyst company, providing premium services via it's app not available on TV can increase user signups.

Their app could offer this use cases;

  • A platform were users share live weather data of their location that are factual.
  • Provide paid weather educational courses
8 0
3 years ago
Based on the condition.
e-lub [12.9K]

Answer:

A subroutine is a block of statements that carries out one or more tasks. ... they share all variables with the rest of the main program. ... Once you have defined a function in your program, you may use it in any appropriate expression, such as: ... Thus, functions can- not change the values of the arguments passed to them.

Explanation:

5 0
3 years ago
A person interested in a career in digital media should have which qualities? Select all that apply.
emmainna [20.7K]
1.Creativity
2.Leadership
3.Attention to detail
5.Enjoyment to learning new things!
6.Vision
No Problem!
5 0
2 years ago
1. The Percentage of T9 and T10 also have the wrong number format. Change them to the Correct number format(to match the rest of
pentagon [3]

Answer:

60%

Explanation:

After changing the number format of the percentages of T9 and T10, the value that now shows in T10 due to the change from the wrong format to the Right format is 60%

This is because when a value is entered into a column in a wrong format the value would be different from other values entered rightly but when the format is changed to the right format, the correct value would show up.

5 0
3 years ago
Software that organizes, manages, and processes business data, such as data concerned with inventory, customers, and vendors, is
adoni [48]

Answer:

c) data management software

Explanation:

Software that organizes, manages, and processes business data, such as data concerned with inventory, customers, and vendors, is called data management software.

5 0
3 years ago
Other questions:
  • Which of the following would likely be covered under homeowners insurance but NOT by renter's insurance?
    9·2 answers
  • The view side by side command is used to view and ________ two workbooks at one time
    10·1 answer
  • 6. Which of the following is malware? (1 point)
    10·2 answers
  • Match each vocabulary word to its definition.
    11·2 answers
  • What needs to be increased in order to increase image size and clarity?
    10·1 answer
  • Peripeteia is also referred to as __________.
    5·2 answers
  • All of the following are used to fund private schools except ______
    14·2 answers
  • Allows a user to control the<br>volume of the computer​
    8·1 answer
  • I have a very quick question. So im applying for Early college and i need some future educational goals and maybe im just thinki
    6·1 answer
  • Read the scenario below, and then choose the right type of computer for each person from the drop-down menus. Three of your frie
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!