Answer to Question #256481 in Python for rasi

Question #256481

  20. Given that a man can jump X meters and after every jump, he comes back 1 meter as it is a slope model and given N poles to cross. Then print how many jumps are needed.

 Input1 = number of meters pirate can climb

Input2 = number of meters pirate will slide down

Input3 = total number of walls

Input4[] = array of length input3 containing height of walls

Print the total number of jumps required to cross the wall?

 


1
Expert's answer
2021-10-31T12:00:56-0400
m_up = int(input("number of meters pirate can climb: "))
m_down = int(input("number of meters pirate will slide down: "))
walls_num = int(input("total number of walls: "))
height = [int(i) for i in input("array of height of walls:\n").split()]
if m_up <= m_down:
    print("pirate can not cross the wall")
elif walls_num != len(height):
    print("incorrect input")
else:
    for i in range(walls_num):
        jumps = 0
        h = 0
        while h < height[i]:
            h += m_up
            jumps += 1
            if h >= height[i]:
                break
            else:
                h -= m_down
        print(f"the pirate will need {jumps} jumps to cross wall number {i+1}")

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