Ask Question
5 September, 04:29

A certain robot can perform only 4 types of movement. It can move either up or down or left or right. These movements are represented by 'U', 'D', 'L', 'R'. Assume all these movements to be of unit distance. Write a function named theRoundTrip that takes all the movements the robot made in a day as input and output True of bool type if the robot returned to its starting position after its journey. Otherwise, return False. If the input is bad print the message "bad input".

+3
Answers (1)
  1. 5 September, 07:25
    0
    def theRoundTrip (movement):

    x=0

    y=0

    for i in movement:

    if i not in ["U","L","D","R"]:

    print ("bad input")

    return

    if i=="U":

    y+=1

    if i=="L":

    x-=1

    if i=="D":

    y-=1

    if i=="R":

    x+=1

    return x==0 and y==0
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “A certain robot can perform only 4 types of movement. It can move either up or down or left or right. These movements are represented by ...” in 📙 Engineering if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers