Question: Let's start by learning about indexing. Indexing allows us to access the ith element in a sequence. For example, if we have the list lst
Let's start by learning about indexing. Indexing allows us to access the ith element in a sequence. For example,
if we have the list lst = [`a', `b', `c', `d'] and we want to access the `b' we can ask for lst[1]. Notice
that Python indexes from 0. This means if we want the rst element in a sequence we have to ask for seq[0].
If the rst element is at 0, in our list lst what index is the last element? How could we write a loop that
would look at every element?
Part A - Adding
Write a function add(numbers) that returns the sum of every second number in a given list. (E.g. calling
add([2,-3,5,8,10,1]) returns 6 because jQuery22406987211055221731_1585648880324??3 + 8 + 1 = 6.)
Part B - Flipping
Write a function flip(binary string) that takes a binary string (a string containing only 1s and 0s) and
returns a new string where every bit has been
ipped. (E.g. calling flip('001011') returns '110100'.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
