Ask Question
30 June, 23:55

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. 1 July, 03:20
    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 you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers