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?
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}")
Comments
Leave a comment