Question

Help with this coding problem. Please in python Thank you

You are choreograhing a circus show with various animals. For one act, you are given two kangaroos on a number line ready to jump in the positive direction (i.e, toward positive infinity).

The first kangaroo starts at location x1 and moves at a rate of v1 meters per jump.

The second kangaroo starts at location x2 and moves at a rate of v2 meters per jump.

You have to figure out a way to get both kangaroos at the same location as part of the show.

Complete the function kangaroo which takes starting location and speed of both kangaroos as input, and return Yes or No or appropriately. Can you determine if the kangaroos will ever land at the same location at the same time? The two kangaroos must land at the same location after making the same number of jumps.

Input Format

A single line of four space-separated integers denoting the respective values of x1, v1 ,x2 , and v2 .

Constraints

0< rl <r2< 1000

1\leq v1\leq 1000

1\leq v2\leq 1000

Output Format

Print YES if they can land on the same location at the same time; otherwise, print NO.

Note: The two kangaroos must land at the same location after making the same number of jumps.

Sample Input 0

0 3 4 2

Sample Output 0

YES

Explanation 0

The two kangaroos jump through the following sequence of locations:

From the image, it is clear that the kangaroos meet at the same location (number 12 on the number line) after same number of jumps (4 jumps), and we print YES.

Sample Input 1

0 2 5 3

Sample Output 1

NO

Explanation 1

The second kangaroo has a starting location that is ahead (further to the right) of the first kangaroo's starting location (i.e.,x2> x1 ). Because the second kangaroo moves at a faster rate (meaning v2> v1 ) and is already ahead of the first kangaroo, the first kangaroo will never be able to catch up. Thus, we print NO.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
x1, v1, x2, v2 = map(int, input().split())
X = [x1, v1]
Y = [x2, v2]
back = min(X, Y)
fwd = max(X, Y)
dist = fwd[0] - back[0]

while back[0] < fwd[0]:
    back[0] += back[1]
    fwd[0] += fwd[1]
    if fwd[0] - back[0] >= dist:
        break
    elif fwd[0] == back[0]:
        print ('YES')
        break
if fwd[0] != back[0]:
    print ('NO')
Add a comment
Know the answer?
Add Answer to:
Help with this coding problem. Please in python Thank you You are choreograhing a circus show with various animals. For...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE ANSWER QUESTION 1 & 2. ALSO PLEASE SUBMIT CODE + PDF OF REPORT/ASSIGNMENT Problem1 You are choreographing a...

    PLEASE ANSWER QUESTION 1 & 2. ALSO PLEASE SUBMIT CODE + PDF OF REPORT/ASSIGNMENT Problem1 You are choreographing a circus show with various animals. For one act, you are given two kangaroos on a number line ready to jump in the positive direction (i.e, toward positive infinity). The first kangaroo starts at location z1 and moves at a rate of vl meters per jump. The second kangaroo starts at location z2 and moves at a rate of u2 meters per...

  • Problem 10.001 please help me find the solution to parts a b and c. show work please. Thanks! ...

    Problem 10.001 please help me find the solution to parts a b and c. show work please. Thanks! Your answer is partially correct. Try again. Consider the hypothesis test against with known variances and Suppose that sample sizes and and that and Use (a) Test the hypothesis and find the P-value. (b) What is the power of the test in part (a) for a true difference in means of 3? (c) Assuming equal sample sizes, what sample size should be...

  • Please use TI-83+ calculator to solve this. thank you! You wish to test the following claim...

    Please use TI-83+ calculator to solve this. thank you! You wish to test the following claim (HaHa) at a significance level of α=0.10α=0.10.       Ho:p1=p2Ho:p1=p2       Ha:p1<p2Ha:p1<p2 You obtain 26.7% successes in a sample of size n1=333n1=333 from the first population. You obtain 28.2% successes in a sample of size n2=476n2=476 from the second population. For this test, you should NOT use the continuity correction, and you should use the normal distribution as an approximation for the binomial distribution. What is the...

  • Need help. Please write Python program that answer the prompt and has an sample output as...

    Need help. Please write Python program that answer the prompt and has an sample output as shown below. Thank you. We were unable to transcribe this imageCommand: view Number: 2 Name: Eric Idle Email: [email protected] Phone: +44 20 7946 0958 Command: add Name: Mike Murach Email: [email protected] Phone: 559-123-4567 Mike Murach was added. Command: del Number: 1 Guido van Rossum was deleted. Command: list 1. Eric Idle 2. Mike Murach Command: exit Thank you for using my app. Specifications Your...

  • *** Please use TI-83+ calculator to solve this problem *** You wish to test the following...

    *** Please use TI-83+ calculator to solve this problem *** You wish to test the following claim (HaHa) at a significance level of α=0.02α=0.02.       Ho:p1=p2Ho:p1=p2       Ha:p1<p2Ha:p1<p2 You obtain 465 successes in a sample of size n1=592n1=592 from the first population. You obtain 593 successes in a sample of size n2=687n2=687 from the second population. For this test, you should NOT use the continuity correction, and you should use the normal distribution as an approximation for the binomial distribution. What is...

  • C++ problem Please help me with it. Thank you. the output would be like this: 10-20...

    C++ problem Please help me with it. Thank you. the output would be like this: 10-20 with sequence 10 - 30 no sequence: this is the background: Project Description / Specification Your program takes as input three integer values (same line, space separated) the first two integers, the beginning and ending value in a range of integers you are going to examine, as space separated integers. They are in that order: the first is the lower range and the second...

  • please help. thank you! Total Question 12 3 4 5 6 7 8 9 10 11...

    please help. thank you! Total Question 12 3 4 5 6 7 8 9 10 11 1213 14 15 16 | 435(11.4%) 12 -/1 -/1 -8-6-6-/1 -3-13 ㅢ1-1 0/3 1/1 0,1 Points Assignment Submission For this assignment, you submit answers by question parts. The number of submissions remaining for each question part only cha Assignment Scoring Your last submission is used for your score. 4. 0/1 points I Previous Answers OSPreCalc1 8.1.041 Find the measure of angle x, If possible....

  • The game of “Jump It” consists of a board with n positive integers in a row,...

    The game of “Jump It” consists of a board with n positive integers in a row, except for the first column, which always contains zero. These numbers represent the cost to enter each column. Here is a sample game board where n is 6: 0 3 80 6 57 10 The object of the game is to move from the first column to the last column with the lowest total cost. The number in each column represents the cost to...

  • Use C++. The game of “Jump It” consists of a board with n positive integers in...

    Use C++. The game of “Jump It” consists of a board with n positive integers in a row, except for the first column, which always contains zero. These numbers represent the cost to enter each column. Here is a sample game board where n is 6: 0 3 80 6 57 10 The object of the game is to move from the first column to the last column with the lowest total cost. The number in each column represents the...

  • someone please help me with this. help me to solve where i went wrong. and please...

    someone please help me with this. help me to solve where i went wrong. and please show all steps and explain every step. a more clear picture i uploaded the same picture i hope u can understand italso these notes 11:47 00 in the made DU - . F -BUT Sez(-BUT") (P = BTV 7 ( 5 . lavity, energy, Gibbs I re-de the free energy quiz - Going over Quiz PV=const. Ideal Gas it 7=const BB p=constant srT3V =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT