2. Complete the function avg5 to return the average of five numbers. Use the accumulator pattern. Don't change anything outside of avg5. Save & Run 10/4/2020, 1:04:36 PM - 13 of 13 3 def avg5(num1, num2, num3, num4, num5): ' 'Returns the average of its parameters''' pass #This statement does nothing #Your code here to calculate the average - use the accumulator pattern 4 you can remove it 6 7 avgstart=num1 8 avg5=(avgstart+num2+num3+num4+num5)/5 return avg5 10 11 12 13 14 15 print(avg5(10, 13, 15, 18, 25))
2. Complete the function avg5 to return the average of five numbers. Use the accumulator pattern. Don't change anything outside of avg5. Save & Run 10/4/2020, 1:04:36 PM - 13 of 13 3 def avg5(num1, num2, num3, num4, num5): ' 'Returns the average of its parameters''' pass #This statement does nothing #Your code here to calculate the average - use the accumulator pattern 4 you can remove it 6 7 avgstart=num1 8 avg5=(avgstart+num2+num3+num4+num5)/5 return avg5 10 11 12 13 14 15 print(avg5(10, 13, 15, 18, 25))
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question

Transcribed Image Text:### Task 2: Complete the Function `avg5` to Calculate the Average of Five Numbers
**Objective**: Modify the function `avg5` to return the average of five given numbers. Use the accumulator pattern and ensure no changes are made outside of the function `avg5`.
#### Code Explanation:
```python
def avg5(num1, num2, num3, num4, num5):
'''Returns the average of its parameters'''
pass # This statement does nothing = you can remove it
# Your code here to calculate the average - use the accumulator pattern
avgstart = num1
avg5 = (avgstart + num2 + num3 + num4 + num5) / 5
return avg5
print(avg5(10, 13, 15, 18, 25))
```
- **Function Definition**:
- `avg5` is defined to take five parameters: `num1`, `num2`, `num3`, `num4`, and `num5`.
- **Documentation String**:
- A docstring is included to describe the purpose of the function, which is to return the average of its parameters.
- **Initial Statements**:
- A `pass` statement is initially present and can be removed since it does not execute any operation.
- **Accumulator Pattern**:
- Two variables are utilized:
- `avgstart`: Initially set to `num1`.
- `avg5`: Calculates the average by summing `avgstart`, `num2`, `num3`, `num4`, and `num5`, and then dividing by 5.
- **Return Statement**:
- The function returns the calculated average.
- **Output**:
- The function call `print(avg5(10, 13, 15, 18, 25))` demonstrates the function output with sample input values.
This example demonstrates basic arithmetic operations in Python and emphasizes the use of the accumulator pattern to compute averages.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education