answer.
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
Likurg_2
2 months ago
11

Define a function below called average_strings. The function takes one argument: a list of strings. Complete the function so tha

t it returns the average length of the strings in the list. An empty list should have an average of zero. Hint: don't forget that in order to get a string's length, you need the len function.
Computers and Technology
1 answer:
Natasha_Volkova [1K]2 months ago
6 0

Answer:

def average_strings(lst):

   total_length = 0

   avg = 0

   for s in lst:

       total_length += len(s)

   avg = total_length/len(lst)

   return avg

Explanation:

Define a function named average_strings that takes a single argument, lst

Initialize both total length and avg variables

Utilize a for loop to iterate through lst, accumulating the length of each string into total length

Once the loop ends, compute the average by dividing the total length by the number of elements in lst

Return the computed average.

You might be interested in
You would like the user of a program to enter a customer’s last name. Write a statement thaUse the variables k, d, and s so that
Rzqust [1037]

Answer:

1st question:

Utilize k, d, and s as variables to read three distinct inputs: an integer, a float, and a string, respectively. Print these variables in reverse order on one line, ensuring exactly one space separates each. On a second line, print them in their original sequence, with one space in between.

Solution:

In Python:

k = input()  # prompts user to enter k, an integer value

d = input()  # prompts user to provide d, a float value

s = input()  # prompts user to input s, a string

print (s, d, k)  # displays the variable values in reverse order

print (k, d, s)# displays the variable values in the original order

In C++:

#include <iostream>    // for input-output functions

using namespace std;   // to identify objects like cin and cout

int main() {    // start of main function

  int k;   // declare an int variable for the integer value

  float d; //  declare a float variable for the float value

  string s;   //  declare a string variable for string input

  cin >> k >> d >> s;    // reads the values for k, d, and s

  cout << s << " " << d << " " << k << endl;     // displays the variables in reverse order

  cout << k << " " << d << " " << s << endl;   } // displays the variables in their original order

Explanation:

2nd question:

You would want users of your program to enter a customer's last name. Formulate a statement that prompts the user with "Last Name:" and assigns the input to a string variable named last_name.

Solution:

In Python:

last_name = input("Last Name:")

# The input function captures input from the user and assigns it to last_name variable

In C++:

string last_name;  // declare a string variable called last_name

cout<<"Last Name: ";  // prompts user to input last name through this message Last Name:

cin>>last_name; // gathers and assigns the provided value to the last_name variable

The provided programs along with their outputs are included.

6 0
2 months ago
Your company is developing a new marketing campaign and wants to know which customers have never placed an order. You will need
maria [1035]

Answer:

Refer to the explanation

Explanation:

By utilizing the left outer join:

select custid,companyname,contactname,country,phone from sales.customers left outer join sales.orders on sales.customers=sales.order;

4 0
2 months ago
Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print
Harlamova29_29 [1022]

Answer:

Below is a detailed explanation along with the C++ code.

C++ Code:

#include <iostream>

using namespace std;

int main()

{

int numRows;

int numCols;

int r = 1;

cout <<"Please input the number of rows:"<<endl;

cin>>numRows;

cout <<"Please input the number of columns:"<<endl;

cin>>numCols;

cout<<"The theater's seating arrangement:"<<endl;

for(int i = 0; i < numRows; i++)

{

  char c = 'A';  

 for(int j = 0; j < numCols; j++)

 {

  cout <<r << c << " ";

  c= c + 1;

 }

 r= r + 1;

}

  return 0;

}

Explanation:

// The outer loop is responsible for row printing.

// The increment r = r + 1 effectively updates the row count.

// The inner loop handles column printing.

// The increment c = c + 1 updates the column characters.

//  Setting int r = 1 starts row numbering from 1.

Output:

This program has been tested several times and functions correctly for any quantity of rows and columns.

Please input the number of rows

2

Please input the number of columns

3

Theater seating arrangement:

1A 1B 1C 2A 2B 2C

5 0
2 months ago
Other questions:
  • Allan needs to ensure that an object is in a very precise location on a slide. He decides to use the Ruler option to achieve thi
    5·2 answers
  • Assume a machine during its initial testing phase produces 10 widgets a day. After 10 days of testing (starting on day 11), it b
    9·1 answer
  • Widget Corp. wants to shift its list of inventory to a cloud so that its different branches can access it easily. The company ne
    7·1 answer
  • A company moves a popular website to a new web host. Which of the following will change as a result?
    15·1 answer
  • A 2-dimensional 3x3 array of ints, has been created and assigned to tictactoe. Write an expression whose value is true if the el
    10·1 answer
  • Explain what might happen if two stations are accidentally assigned the same hardware address?
    15·1 answer
  • An extranet is like an intranet except that it allows company employees access to corporate Web sites from the ______
    13·1 answer
  • Write a complete Java program that: Prompts an employee to enter the number of hours that they have worked in a given week and s
    14·1 answer
  • For a list of numbers entered by the user and terminated by 0. Write a program to find the sum of the positive numbers and the s
    10·1 answer
  • What is printed by the following program provided all necessary standard header files are included? Explain each line of the out
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!