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
amm1812
3 years ago
14

Write a function called average() that takes a single parameter, a list of numeric values. The function should return the averag

e of the values in the list. If the list is empty, average() should return 0.
>>>lst = [1,3,4]

>>>average(lst)

2.6666666666666665

>>>average([])

0
Computers and Technology
1 answer:
QveST [7]3 years ago
3 0

Answer:

The following code is in python.

import statistics as st #importing statistics which include mean function.

def average(lst): #function average.

   return st.mean(lst)#returning mean.

lst=a = list(map(int,input("\nEnter the list : ").strip().split()))#taking input of the list..

print("The average is "+str(average(lst)))#printing the average.

Output:-

Enter the list :

1 2 3 4 5 6

The average is 3.5

Explanation:

I have used the statistics library which includes the mean function that calculates the mean or average of the list.In the function average having lst as an argument returns the mean of the list lst.

Then taking lst input from the user and printing it's average.

You might be interested in
Which of the following transferable skills are generally the most looked for in the IT field?
san4es73 [151]
The correct option is D.
Transferable skills refers to those set of skills that do not belong to any specific field or industry, they are general skills and can be transferred from one job to another. Option D is the correct choice because all jobs require the employees to have problem solving skill, team building skills and communication skills; all these skills contribute to a successful career. 
3 0
3 years ago
Read 2 more answers
Consider the following two code segments: Segment 1: while (k > 0) { System.out.println(k); k--; } --------------- Segment 2:
zepelin [54]

Answer:

Always same value

Explanation:

These both code segments will always generate identical values given that we provide same value of k to both segments.

You can see attached pictures.

6 0
3 years ago
6.10.1: Modify a C string parameter. Complete the function to replace any period by an exclamation point. Ex: "Hello. I'm Miley.
Andrej [43]

Answer:

#include <iostream>

#include <cstring>

using namespace std;

void replacePeriod(char* phrase) {

int i = 0;

while(*(phrase + i) != '\0')

{

if(*(phrase + i) == '.')

*(phrase + i) = '!';

i++;

}

}

int main() {

const int STRING_SIZE = 50;

char sentence[STRING_SIZE];

strcpy(sentence, "Hello. I'm Miley. Nice to meet you.");

replacePeriod(sentence);

cout << "Updated sentence: " << endl;

cout << sentence << endl;

return 0;

}

Explanation:

  • Create a function called replacePeriod that takes a pointer of type char as a parameter.
  • Loop through the end of phrase, check if phrase has a period and then replace it with a sign of exclamation.
  • Inside the main function, define the sentence and pass it as an argument to the replacePeriod function.
  • Finally display the updated sentence.
6 0
3 years ago
What is a logical reason why you should be able to delete your own posts on social media?
Furkat [3]

People live in the moment and post whatever they want and they just might regret it later on.

3 0
3 years ago
Read 2 more answers
What's a common mistake that young people in relationships make?
allochka39001 [22]
B, i say b because oversharing something personal could result in somebody you thought you loved going back telling someone else, causing rumors to be spread out
3 0
2 years ago
Other questions:
  • Write a program that checks for car mileage. if the mileage is greater than 100000, display "clunker!". if not, display "buy it!
    7·1 answer
  • Explain how inflation flattens the universe
    6·2 answers
  • What is the name of the program file that you can enter in the Windows search or Run box to execute Event Viewer? What process i
    12·1 answer
  • Anyone wanna play roblox?? My user is Tsvetok_luis
    11·2 answers
  • Xavier would like to change the sort options for his contacts. In which tab will he find the Arrangement command group?
    6·1 answer
  • Discuss the difference between a broad internet search and a narrow internet search?
    12·2 answers
  • Designers and graphic artists can print finished publications on a color printer, take them to a professional printer, or post t
    15·1 answer
  • Which of the following is another term for a subfolder​
    14·1 answer
  • What gaming PC should I get
    14·2 answers
  • I need help, who is a great phone pin lock screen cracker?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!