Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a function sum_5_consecutive that takes a list of numbers as input and returns True if there are 5 consecutive numbers in the list that
Write a function sum_5_consecutive that takes a list of numbers as input and returns True if there are 5 consecutive numbers in the list that sum to zero. Otherwise it returns False. The function should also return False if the list has less than 5 elements Solve this in two ways: 1.for loop (over indices of the list) 2. while loop (over indices of the list) In both cases you need to think about "stopping condition" in order to avoid "Indexerror: list index out of range" 3. Test your function with at least the examples below >um_5_consecutive ([2,3,3,2,4,6]) True >>> sum_5_consecutive ([10,1,1,4,2,10,13]) False >> sum_5_consecutive ([2,1,3,3,3,2,7,4,6]) True >>> sum_5_consecutive ([]) False >> sum_5_consecutive ([1,1,0]) False
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started