Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this task you can turn pages in a book either from the front or the back of the book. You always turn the page
In this task you can turn pages in a book either from the front or the back of the book. You always turn the page one at a time. If the book is n pages long and you want to turn to page p, what is the minimum number of pages to turn. Given n and p find and print the minimum number of pages that must be turned in order to arrive at page p.
Below is the correct code.
I dont understand why we have st=p//2 and en=n//2 and then why do we have return [st,en-st]? and what does it do?
def pageCount (n,p): st=p //2# spread from start en=n//2 \# spread from end return min ([ st, en-st ])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