Python Programming: An Introduction to Computer Science, 3rd Ed.
Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
bartleby

Videos

Question
Book Icon
Chapter 11, Problem 7PE
Program Plan Intro

Computing inner product

Program Plan:

  • Define the main function.
    • Create two lists of same length with some values.
    • Declare a variable “sum”.
    • Loop through the length of the list.
      • Calculate the product of the two list and store it in the variable “x”.
      • Calculate sum value and store it in the variable “sum”.
    • Print the result.

Blurred answer
Students have asked these similar questions
The function interleave_lists in python takes two parameters, L1 and L2, both lists. Notice that the lists may have different lengths. The function accumulates a new list by appending alternating items from L1 and L2 until one list has been exhausted.  The remaining items from the other list are then appended to the end of the new list, and the new list is returned. For example, if L1 = ["hop", "skip", "jump", "rest"] and L2 = ["up", "down"], then the function would return the list: ["hop", "up", "skip", "down", "jump", "rest"]. HINT: Python has a built-in function min() which is helpful here.    Initialize accumulator variable newlist to be an empty list Set min_length = min(len(L1), len(L2)), the smaller of the two list lengths Use a for loop to iterate k over range(min_length) to do the first part of this function's work. On each iteration, append to newlist the item from index k in L1, and then append the item from index k in L2 (two appends on each iteration). AFTER the loop…
Write a recursive function named Multiply2 that multiples by 2 and prints each element in a given list. For example: mylist=[1,2,3,4] Multiply2(mylist) prints: 2 4 6 8 Note: the function takes only one parameter, which is the list on which the operation will be performed.
Recursive Max! Write a recursive function rc_max(L:List[int]) -> int that takes a list L and returns an element with highest value in the list. For example, rc_max([1,2,3]) returns 3. Note that L is not necessarily sorted. You may assume that the input L is not empty. You cannot use the built-in max() Your Answer: 1 # Put your answer here 2 Submit
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Introduction to Linked List; Author: Neso Academy;https://www.youtube.com/watch?v=R9PTBwOzceo;License: Standard YouTube License, CC-BY
Linked list | Single, Double & Circular | Data Structures | Lec-23 | Bhanu Priya; Author: Education 4u;https://www.youtube.com/watch?v=IiL_wwFIuaA;License: Standard Youtube License