Write a function doubles() that takes as a list of integers as a parameter and p
ID: 3670626 • Letter: W
Question
Write a function doubles() that takes as a list of integers as a parameter and prints the values in the list, one per line, that are exactly twice the previous value in the list. If the list is empty or there are no values that are double the value of their predecessor, then the function does not print anything. The list provided as a parameter should not be changed. Note that the first item in the list will never be printed since it does not have a predecessor in the list. The following shows how the function could be used on several examples:
Explanation / Answer
def doubles(integers): index = 0 for index in range(1,len(integers)): if integers[index] == 2*integers[index-1]: print(integers[index])
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.