Answer to Question #256451 in Python for rasi

Question #256451

 19. A thief trying to escape from jail. He has to cross N walls each with varying heights (every height is greater than 0). He climbs X feet every time. But, due to the slippery nature of those walls, every time he slips back by Y feet. Now the task is to calculate the total number of jumps required to cross all walls and escape from the jail.

  


1
Expert's answer
2021-10-31T00:16:24-0400
# Python program to find the number of
# jumps required
 
# function to calculate jumps required to
# cross walls
def jumpcount(x, y, n, height):
    jumps = 0
  
    for i in range(n):
        if (height[i] <= x):
            jumps += 1
            continue
  
        """ If height of wall is greater than
           up move """
        h = height[i]
        while (h > x):
            jumps += 1
            h = h - (x - y)
        jumps += 1
    return jumps
  

x = 10
y = 1
height = [ 11, 10, 10, 9 ]
n = len(height)
print (jumpcount(x, y, n, height))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS