Question: 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?

In this task you can turn pages in a book either from

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!