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]
2 years 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]2 years 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
jane feels listening to music at night helps her to sleep. should jane listen to music the night before a test ​
Pavel [41]

If it help her sleep than yes! Sleep helps you to stay focused during a test.

7 0
3 years ago
Which are factors that go into a project plan?
BaLLatris [955]

Answer:

The four critical factors to planning a successful project

Explanation:

5 0
3 years ago
Once artwork is inserted into a placeholder, it can be moved around on a slide. True False
inn [45]

Answer:

The answer to this question is true.

Explanation:

The artwork is used on the PowerPoint for making the presentation more effective. The artwork is also known as Clip Art. In the Microsoft PowerPoint, the clip art is a collection of media files like image file, video file, an audio file, and an animation file. If our computer has an Internet connection, then we can add new clip art for free. If we use the artwork or clip art on slide So it can be moved around on the slide.

6 0
3 years ago
Davingould1115...................answer 1​
erma4kov [3.2K]

wt ...

I didn't get u..

is it a I'd

8 0
3 years ago
Read 2 more answers
assume for arithmetic, load/store, and branch instructions, a processor has CPIs of 1, 12, and 5, respectively. Also assume that
KonstantinChe [14]

Answer:

1 PROCESSOR :

(1 × 2.56 × 10^9) + (12 × 1.28 × 10^9) + (5 × 2.56 × 10^8) / 2 GHz = 9.6 s

2 PROCESSORS :

(1×2.56×10^9)+(12×1.28×10^9)/0.7×2 + (5 × 2.56 × 10^8) / 2 GHz = 7.04 s

Speed -up is 1.36

4 PROCESSORS :

(1×2.56×10^9)+(12×1.28×10^9)/0.7×4 + (5 × 2.56 × 10^8) / 2 GHz = 3.84 s

Speed -up is 2.5

5 PROCESSORS :

(1×2.56×10^9)+(12×1.28×10^9)/0.7×8 + (5 × 2.56 × 10^8) / 2 GHz = 2.24 s

Speed -up is 4.29

Explanation:  

The following formula is used in this answer:

EXECUTION TIME = CLOCK CYCLES / CLOCK RATE

Execution Time is equal to the clock cycle per clock rate

7 0
3 years ago
Other questions:
  • An agile team used planning poker to estimate user stories. After all team members read a user story, the facilitator asks every
    7·1 answer
  • The figure below shows a black and white image with a resolution of 720×504. Identify how much memory (in bits) will be occupied
    15·1 answer
  • Write an if-else statement with multiple branches. If givenYear is 2100 or greater, print "Distant future" (without quotes). Els
    5·1 answer
  • What are some effects of the holocaust? She walked along the river until a policeman stopped her. It was one o'clock, he said. N
    8·1 answer
  • How many bytes are there in 256 Kbytes?
    6·1 answer
  • Pascal system . write the program that will calculate the perimeter of a rectangle if its area is A (m²) and one of its sides ha
    6·1 answer
  • Java: Programming Question: Reverse OrderWrite a program that reads ten integers into an array; define another array to save tho
    10·1 answer
  • Cuando se introduce una fórmula en una celda primero que hay que introducir es
    13·1 answer
  • Đánh giá hoạt động thanh toán điện tử của sinh viên
    6·1 answer
  • Madeleine's Instructor praised her for capturing a nearly perfect image. It included dominance, harmony, and proportion among ot
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!