Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Because the user can provide any non-negative number, its value needs to somehow map any non-negative num to one of the elements stored in the
Because the user can provide any non-negative number, its value needs to somehow map any non-negative num to one of the elements stored in the list. Given that there is a fixed number of elements in the list, in order to always pick an element from the list, we can think of numbers that are greater than len(stepsToSuccess) mapping to the remainder that's left when we divide num by the size of the list. So if we apply this logic to the example above, instead of indexing at numbers [7], we would index at numbers [2], because there are 5 elements in the list, so 7 % 5 gives us 2. Now, use this idea of "mapping to the remainder" to modify the function below. Note that you shouldn't hard-code values and instead use the functions that would provide the correct value to you (i.e., for the number of elements, use len instead). def getAdvice(num): Given an input number >= 0, return an element from the list, which we'd land on if we loop around the list num times. stepsToSuccess = [ "Keep track of deadlines", "Read the book", " "Do the homework yourself", " "Attend lectures", "Ask questions", \ "Attend labs", "Enjoy studying" ] if num > 0 : advice = stepsToSuccess [num % ...] # TODO: replace ... return
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