Question

# Fill in the missing parts in the following code. # It should compute the same...

# Fill in the missing parts in the following code. # It should compute the same result as map(lambda x: n*x, L).

def multAll(n, L):
'''Assuming n is a number and L is a list of numbers,
make a list by multiplying each element of L by n.
For example, multAll(3,[3,5,7,9]) is [9,15,21,27].'''
if L==[]:

return None # TO-DO replace None


else:

return None # TO-DO replace None

Homework Answers

Answer #1

Python code pasted below.

#Function definition
def multAll(n,L):
if L==[]:
#returns list if list is empty
return L
else:
#list comprehension
return [x*n for x in L]
#main progarm
#function calling - Test case 1
print(multAll(3,[3,5,7,9]))
#function calling - Test case 2
print(multAll(3,[]))
Python code in IDLE pasted below for better understanding of the indent.

Output Screen

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Q1: Given the following code, what is returned by tq(4)? int tq(int num){ if (num ==...
Q1: Given the following code, what is returned by tq(4)? int tq(int num){ if (num == 0) return 0; else if (num > 100) return -1; else     return num + tq( num – 1 ); } Group of answer choices: 0 4 -1 10 Q2: Given that values is of type LLNode<Integer> and references a linked list (non-empty) of Integer objects, what does the following code do if invoked as mystery(values)? int mystery(LLNode<Integer> list) {    if (list.getLink() ==...
# Parts to be completed are marked with '<<<<< COMPLETE' import random N = 8 MAXSTEPS...
# Parts to be completed are marked with '<<<<< COMPLETE' import random N = 8 MAXSTEPS = 5000 # generates a random n-queens board # representation: a list of length n the value at index i is # row that contains the ith queen; # exampe for 4-queens: [0,2,0,3] means that the queen in column 0 is # sitting in row 0, the queen in colum 1 is in row, the queen in column 2 # is in row 0,...
## We will be simulating the ideal solution to Hanoi's tower problem. ## The discs will...
## We will be simulating the ideal solution to Hanoi's tower problem. ## The discs will be numers from 0 to n-1, with the larger number being the smaller disc. ## each rod with discs will be encoded by a list, from bottom to top. For example, a rod with discs 0, 3, 5 will be encoded as [0,3,5] ## current configuration of rods will be encoded as a list of 3 lists. For example, starting state with 3 discs...
Re-write following if-else-if statements as Switch statement. Your final code should result in the same output...
Re-write following if-else-if statements as Switch statement. Your final code should result in the same output as the original code below. if (selection == 10) System.out.println("You selected 10."); else if (selection == 20) System.out.println("You selected 20."); else if (selection == 30) System.out.println("You selected 30."); else if (selection == 40) System.out.println("You selected 40."); else System.out.println("Not good with numbers, eh?"); Second question Re-write following while loop into Java statements that use a Do-while loop. Your final code should result in the same...
Q1: Re-write following if-else-if statements as Switch statement. Your final code should result in the same...
Q1: Re-write following if-else-if statements as Switch statement. Your final code should result in the same output as the original code below. if (selection == 10) System.out.println("You selected 10."); else if (selection == 20) System.out.println("You selected 20."); else if (selection == 30) System.out.println("You selected 30."); else if (selection == 40) System.out.println("You selected 40."); else System.out.println("Not good with numbers, eh?"); Q2: Re-write following while loop into Java statements that use a Do-while loop. Your final code should result in the same...
Implement the following functions in the given code: def random_suit_number(): def get_card_suit_string_from_number(n): def random_value_number(): def get_card_value_string_from_number(n):...
Implement the following functions in the given code: def random_suit_number(): def get_card_suit_string_from_number(n): def random_value_number(): def get_card_value_string_from_number(n): def is_leap_year(year): def get_letter_grade_version_1(x): def get_letter_grade_version_2(x): def get_letter_grade_version_3(x): Pay careful attention to the three different versions of the number-grade-to-letter-grade functions. Their behaviors are subtly different. Use the function descriptions provided in the code to replace the pass keyword with the necessary code. Remember: Parameters contain values that are passed in by the caller. You will need to make use of the parameters that each...
Re-write following if-else-if statements as Switch statement. Your final code should result in the same output...
Re-write following if-else-if statements as Switch statement. Your final code should result in the same output as the original code below. if (selection == 10) System.out.println("You selected 10."); else if (selection == 20) System.out.println("You selected 20.") ; else if (selection == 30) System.out.println("You selected 30."); else if (selection == 40) System.out.println("You selected 40."); else System.out.println("Not good with numbers, eh?");
e-write following if-else-if statements as Switch statement. Your final code should result in the same output...
e-write following if-else-if statements as Switch statement. Your final code should result in the same output as the original code below. if (selection == 10) System.out.println("You selected 10."); else if (selection == 20) System.out.println("You selected 20."); else if (selection == 30) System.out.println("You selected 30."); else if (selection == 40) System.out.println("You selected 40."); else System.out.println("Not good with numbers, eh?"); (Java programming)
convert code from python to cpp L = [2,7,4,19,45,16,9,13,8,69,55,11,23,98,14,5,1,3]   #Merging function def merge(M,N): merging_list = []...
convert code from python to cpp L = [2,7,4,19,45,16,9,13,8,69,55,11,23,98,14,5,1,3]   #Merging function def merge(M,N): merging_list = []        //create empty list to merge the lists M and N if not M:                //if M is empty list, m = 0                //set m = 0 else: m = len(M)             //otherwise, set m = len(M) if not N:                //if N is empty list, n = 0       ...
In this problem your task is to find a missing number. The input will always consist...
In this problem your task is to find a missing number. The input will always consist of an array of n positive integers such that the difference between every two consecutive numbers is a fixed constant but one integer is missing. See below for two example inputs/outputs: Input sequence: [0, 2, 4, 6, 10] Output: missing number is 8 Input sequence: [1, 4, 7, 13, 16] Output: missing number is 10 Note that in the first example the constant c...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT