Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Given the following parallel lists of songs and years they were released: songTitle = ['Baby', 'Finesse', 'Hips Don't Lie', 'Single Ladies', 'Blank Space'] yearList

1. Given the following parallel lists of songs and years they were released: songTitle = ['Baby', 'Finesse', 'Hips Don't Lie', 'Single Ladies', 'Blank Space'] yearList = [2010, 2016, 2005, 2008, 2014] write a line of Python code to print the year that Hips Don't Lie was released.

2. The following function computes the sum of a list of numbers.

def computeTotal(myList):

i = 0

total = 0

while i < len(myList):

total = total + myList[i]

i = i + 1

return total

- So if we have

myList = [20, 30, 40, 50, 60, 70]

x = computeTotal(myList)

x wouldbe 20+30+40+50+60+70 = 270.

a. Modify this code so that it computes the sum of a subset of the list of numbers starting at the given position (start) and adding the n numbers from there. For example, if we have:

myList = [20, 30, 40, 50, 60, 70]

x = computeTotal(myList, 2, 3)

x would be 120 because you are starting your sum at position 2 (40) and summing the next three numbers (40 + 50 + 60 = 150).

If n goes beyond the end of the list, your function should return -1. For example, if we have:

x = computeTotal(myList, 3, 5)

x would be -1 because there are not 5 numbers in the list starting from position 3. You can start with this function definition.

def computeSubTotal(myList, start, n):

return total

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

XML Data Management Native XML And XML Enabled Database Systems

Authors: Akmal Chaudhri, Awais Rashid, Roberto Zicari, John Fuller

1st Edition

ISBN: 0201844524, 978-0201844528

Students also viewed these Databases questions

Question

13-4 What are alternative methods for building information systems?

Answered: 1 week ago

Question

13-1 How does building new systems produce organizational change?

Answered: 1 week ago