Question

python multiply 2 list and return the sum,[ ] *[ ]return 0 example [1,2] [2,3]return 8...

python
multiply 2 list and return the sum,[ ] *[ ]return 0
example [1,2] [2,3]return 8
do not use sum or any built in func
0 0
Add a comment Improve this question Transcribed image text
Answer #1

def mulsumfunc(list1,list2):
sum1=0;
sum2=0;
for i in list1:
sum1=sum1+i;
  
for j in list2:
sum2=sum2+j;
  
return sum1+sum2;
  
  
print(mulsumfunc([],[]));
print(mulsumfunc([1,2],[2,3]));

Expected output:

0

8

Add a comment
Know the answer?
Add Answer to:
python multiply 2 list and return the sum,[ ] *[ ]return 0 example [1,2] [2,3]return 8...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The language is python Write the function largest_edge_group(vertices) that consumes vertices, a list of list of...

    The language is python Write the function largest_edge_group(vertices) that consumes vertices, a list of list of integer containing the coordinates of the consecutive vertices of a polygon. The function largest_edge_group returns the size of the largest group of same length edges. Your function must run in O(n), where n is the length of vertices. Example largest_edge_group([[0,0],[1,1],[0,2],[-2,3],[-1,2]]) => 3 Hint Remember, it is not possible to compare Floats for strict equality, but since the coordinates are integers, the squared distance is...

  • Use the FDR to design and write a function, maxValTimes, that takes a list of integers...

    Use the FDR to design and write a function, maxValTimes, that takes a list of integers and returns a set containing the value(s) that occur the same number of times as the maximum value in the list. If the list is empty, return an empty set.   For example if the list was [2,1,1,2,3,3,1] the function would return {2,3} as the maximum value is 3 which occurs twice, and 2 also occurs twice (but 1 occurs 3 times). For full marks,...

  • 0% of final (S1 2019) Write a function called sum_of_products(x), where x is a list of lists of i...

    0% of final (S1 2019) Write a function called sum_of_products(x), where x is a list of lists of integers, this function returns a number which is the sum of the products of each list of integers. For example: print(sum_of_products ([[1,2], [5], [2,5]])) will result in the output: 17 That is, the result of 2 + 5+ 10 For example: Test Result print(sum_of_products( [2,3]])) print sum_of_products([[2],[3]])) print(sum_of_products([[1,21,[S],[2,5]1)) 17 0% of final (S1 2019) Write a function called sum_of_products(x), where x is...

  • Write a Python function fun3(e) to update a list of numbers e such that the first...

    Write a Python function fun3(e) to update a list of numbers e such that the first and last elements have been exchanged. The function needs to also return multiplication of elements of e. You should assume that the list e has at least 2 elements. Example: >>>lst = [4, 1, 2, -1] >>>fun3(list) -8 >>>lst [-1, 1, 2, 4] *We are an intro to CS class so please do not use anything too advance or fancy. Stick to basics. Right...

  • Python: problem 1 Given an array of integers, return the sum of two indices from this...

    Python: problem 1 Given an array of integers, return the sum of two indices from this array based on input parameters, x and y. Example: Given nums = [2, 7, 11, 15], x = 3, y = 1 Because nums[x] + nums[y] = 15 + 7 = 22, return 22. You may use this as a template for your code class Solution: def two_sum(self, nums: List[int], x: int, y: int) -> int:

  • python help please and thank you Find the sum of two equal-number integer matrices. Example: 2...

    python help please and thank you Find the sum of two equal-number integer matrices. Example: 2 2 + 5 8 = 7 10 5 4 4 10 9 14 First it asks the user for the number of rows of the two matrices. Then ask for the value of each of the rows of the two matrices, where each column of the row must be separated by a space (use the split function to convert the captured text to a...

  • List Python

    A car park management system uses a list to represent which spaces in a car park are currently occupied and which are currently unoccupied. An empty space is represented by a 0 and a full space by a 1. Then the state of the car park would be represented by the following list: [1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0] The designers of the car park management system require a program that will accept a list such as the one above (although of course the length will not always be 11) and calculate what percentage of the spaces are currently occupied, rounded to the nearest percent. In the example above 7 spaces are occupied and there are 11 altogether, so the percentage occupied is: (7 / 11) x 100 = 63.63… = 64% to the nearest whole number. i.What are the admissible inputs of the problem? ii.What is the output of this problem? iii.Write three tests for this problem. The inputs should be different from the example given in the scenario description above. At least one of your tests must be a borderline case. Present the tests in a table, with a column for each input and output, and an extra column with a brief explanation of why you selected each test iv.Decompose the problem into sub-problems. Use the > notation and state in brackets the type of the problem and of each sub-problem v. Choose the patterns for the subproblem types you identified, instantiate the patterns into an algorithm, and translate the algorithm into code.This part of the question involves writing Python code. Write your code in this file and then submit the completed code file as part of the answer to this part of the question. Note: Although Python has a built-in function to find the sum of a list, please do not use it to compute how many 1s there are in the list. We want you to write your own code , because the purpose of this question is to practice following the problem solving approach described there, which will equip you to solve problems in other cases for which there is no built-in Python function. A Python program which is not preceded by a corresponding decomposition will gain at most half marks. Again, the reason for this is that we want you to follow a systematic problem-solving approach and not dive straight into code. Please therefore make sure that you have supplied an answer to iv. If you find it difficult to get the decomposition quite right at first there is no reason why you cannot review it when you have written the code. The main thing is to have a clear idea of what the solution needs to do (the decomposition) that ties in correctly with how it does it (the program). Make sure you use appropriate variable names and comments and that you have tested your code with the inputs of your test table. (Keep each of your test inputs in your code, but precede all of the test inputs, except for one, with the # symbol. Recall that # signals a comment, which is ignored by the Python interpreter.)

  • 1. Write a Python function that implements the following algorithm that computes the sum of the...

    1. Write a Python function that implements the following algorithm that computes the sum of the first n non-negative powers of 2: 20 + 21 + ... + 2n-1, where n ≥ 0: 1. Input n (assume n ≥ 0) 2. Set sum to 1 3. Set value to 2 4. Do the following n-1 times:    a. Add value to sum    b. Multiply value by 2 5. Output sum 2.Use turtle to draw two flags of two countries...

  • write a python program which finds three consecutive odd numbers whose sum adds up to 45...

    write a python program which finds three consecutive odd numbers whose sum adds up to 45 and return a list of the numbers in ascending order do not use any other packages such as numpy or math

  • Exercise 1 - Create a List to Sum Values Write a python script that sums the...

    Exercise 1 - Create a List to Sum Values Write a python script that sums the values in a list called add_list that contains the following values: (10, 2, -4, 8). Make sure you include a for loop when iterating through the list to sum the values. Take screenshots of the code and output. Exercise 2 – Create a Dictionary Write a python script that prints a dictionary where the key numbers are 1, 2, 3, 4, and 5 and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT