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
________ is the information about a file.
GalinKa [24]
Properties is the information about the file
4 0
2 years ago
In video game development, the person who oversees and directs the entire design team and is the key vision keeper is
Sav [38]

Answer:

The Lead Designer

Explanation:

The Lead designers main role is to oversee how a game looks and is played. They manage a, normally small, design team. They work with them to come up with many aspects of the game itself like; characters, props, and plots to the game. they also, makes sure that the team itself stays on track, is within budget, and meets the designated deadlines.

3 0
2 years ago
Need answer ASAP
Alinara [238K]

both software coding and testing occurs during Engineering phase

6 0
2 years ago
Create a VBScript script (w3_firstname_lastname.vbs) that takes one parameter (folder name) to do the following 1) List all file
leva [86]

Answer:

Set args = Wscript.Arguments

If (WScript.Arguments.Count <> 1) Then

 Wscript.Echo "Specify the folder name as a command line argument."

Else

   objStartFolder = args.Item(0)

   Set objFSO = CreateObject("Scripting.FileSystemObject")

   if (Not objFSO.FolderExists(objStartFolder)) Then

       Wscript.Echo "Folder "&objStartFolder&" does not exist"

   Else

       Set objFolder = objFSO.GetFolder(objStartFolder)

       Set colFiles = objFolder.Files

       For Each objFile in colFiles

           Wscript.Echo objFile.Name, objFile.Size, objFile.DateCreated

       Next

   End If

End If

Explanation:

Here's some code to get you started.

4 0
3 years ago
Suppose within your Web browser you click on a link to obtain a Web page. The IP address for the associated URL is not cached in
pychu [463]
I really truly don’t understand
7 0
3 years ago
Other questions:
  • Describe the general process of creating a DataFlow Diagram (DFD)
    7·1 answer
  • My name Jeff <br><br> what movie is this off of
    6·2 answers
  • Design a hierarchy of classes, where the Media superclass has the artistName and the mediaName as the common attributes. Create
    14·1 answer
  • You recently started working part-time in a retail store, and are learning about the reading devices your store uses. Your store
    6·1 answer
  • How is a website most likely to distinguish its different sections?
    8·1 answer
  • Which communication technology should you use if you need to connect three offices which are all within 3 miles of each other at
    6·1 answer
  • Why 3 phase motors so effective?
    5·1 answer
  • ONlY OnE pErcEnT oF pEOpLe CaN sOlvE tHiS!
    7·2 answers
  • When is mail merge an effective productivity tool<br>​
    5·2 answers
  • How does the dns solve the problem of translating domain names like example.com into ip addresses?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!