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
Veseljchak [2.6K]
3 years ago
10

def list_length(shrinking_list): ''' A recursive way to count the number of items in a list. ''' if shrinking_list

Computers and Technology
1 answer:
AnnZ [28]3 years ago
8 0

Answer:

Written in Python:

def list_length(shrinking_list):

    if not shrinking_list:

         return 0

    else:

         return list_length(shrinking_list[1:]) + len(shrinking_list[0])

Explanation:

This defines the list

def list_length(shrinking_list):

This checks if list is empty, if yes it returns 0

<em>     if not shrinking_list:</em>

<em>          return 0</em>

If list is not empty,

    else:

This calculates the length of the list, recursively

         return list_length(shrinking_list[1:]) + len(shrinking_list[0])

To call the function from the main, use:

<em>print(list_length(listname))</em>

You might be interested in
What is the dark, sticky substance that forms when tobacco is burned?
sashaice [31]

Answer: Tar.

Explanation:

A chemical substance made when tobacco is burned. Tar contains most of the cancer-causing and other harmful chemicals found in tobacco smoke. When tobacco smoke is inhaled, the tar can form a sticky layer on the inside of the lungs.

7 0
3 years ago
A 'array palindrome' is an array which, when its elements are reversed, remains the same (i.e., the elements of the array are sa
stiv31 [10]

Answer:

This code is written in MATLAB.

function [result] = isPalindrome(array,length)

if length == 0 || length == 1 %if the array is empty or contains only one element, the array is a palindrome

result = 1;

else

for i = 1:length/2 %check all the elements forward and backward until the middle is reached

if array(i) ~= array(end+1-i)

result = 0;

return

end

end

result = 1;

end

Explanation: Please read the comments in the code. In MATLAB, Boolean values are 1 or 0 instead of True or False.

6 0
3 years ago
What data type can be used to hold any single character, including numbers and non-printing characters?
SVEN [57.7K]

Answer:

char

Explanation:

The character data type written as char holds any single character, numbers and non-printing characters. In java and most programming languages, the value of the character must be placed within single quotes. for example

char c = 'd'

char c = '9'

char c = '\t'

Are all valid declarations of a variable c as char and assigned d, then 9 and then used with a non-printing character (tab ) with the escape sequence.

8 0
3 years ago
Read 2 more answers
What is the smallest unit of measure on the computer
Sauron [17]
The smallest unit of measure is a “Bit” or a Binary Digit. Glad to help!
4 0
4 years ago
1. The goals of the Safety Office of the Department of Transportation include______.
Lesechka [4]
The correct answer is D
5 0
3 years ago
Other questions:
  • Hello I'm new to coding and in my class, we have jumped straight into coding with zero experience and or lessons, this is my fir
    14·1 answer
  • A variable of the data type arrays is storing 10 quantities. What is true about these quantities?
    10·1 answer
  • Given the network 192.168.100.0/24, we are going to segment this network into two subnets, Subnet A and Subnet B. The hosts requ
    10·1 answer
  • By including ______
    15·2 answers
  • Describe practices that enable software designers to think about using patterns?
    10·1 answer
  • What role do computer play in law and order​
    6·1 answer
  • Point out the wrong statement:
    7·1 answer
  • To create a cell reference in another spreadsheet you must need to start with _______ sign.
    14·1 answer
  • How to tell if your cell phone is being tracked tapped or monitored by spy software?
    12·1 answer
  • Wml script is used in? ​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!