Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instructions Annotate every line of code. You may want to google line 7 which is a common convention in Python code but sort of odd.

Instructions
Annotate every line of code.
You may want to google line 7 which is a common convention in Python code but sort of odd.
Make it so that average (values) only averages the non-negative values. For example, average ([-2,9,7,-2,8,0,-7]) should
return 6. Hint: If you feel stuck, look at the "Conditionals" information near the bottom of this week's "Repetition" Notebook.
def average(values):
sum =0;
for i in range(len(values)):
sum = sum + values i
return sum/len(values)
if =="": # I recommend researching online what this line of code is doing _ it has a unique purpose
but is commonly used.
values =[-2,9,7,-2,8,0,-7]
# values =[1,2,3,4,5,6,7,8,-9,-10]
# values =[1,1,1,2,2,2,3,3,4,4,32]
# values =[30,32,21,11,12,92,46,54,7,-250]
# values =[5,5,5,5,5,-6,-6,-6,-6,-6]
print("The average is ", average(values))
# Annotate code.
# Make it so that average(values) only averages the non-negative values
# average ([-2,9,7,-2,8,0,-7]) should return 6
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago