Answered step by step
Verified Expert Solution
Link Copied!

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?

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

Students also viewed these Databases questions

Question

2. Always guess when you can eliminate some of the alternatives.

Answered: 1 week ago

Question

mple 10. Determine d dx S 0 t dt.

Answered: 1 week ago