Ask Question
25 November, 15:19

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".

+1
Answers (1)
  1. 25 November, 15:38
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers