Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 20 (Advanced problem) It is required to write a function to check if a robot have been instructed to move in a loop (starts

image text in transcribed

Question 20 (Advanced problem) It is required to write a function to check if a robot have been instructed to move in a loop (starts and stops at the same location). The robot is positioned on a grid, in the location (0,0) and facing North. The robot can receive a sequence of instructions, where: F: move forward L: rotate 90deg on the spot R: rotate -90deg on the spot For example: FFLLFF, in this sequence the robot moves from (0,0) to (0,1), then (0,2), turns 180 degrees, and then returns to (0,1) then (0,0). Write a function that accept a string that represent sequence of moves (path) and return True if this sequence represent a loop, False otherwise. The function has the following definition: def is_loop (path): BE IT IT IT Input: path as string represent the robot moves Output: True if path is a loop, False otherwise Examples: >>> is_loop ('FFLLFF') True >>> is loop ('FFRFRFFRF') True >>> is_loop ('FRFF') False >>> is_loop ("') True >>> is_loop ('F') False >>> is_loop ('L') True

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions

Question

1-6 What is an ethical lapse? [LO-5]

Answered: 1 week ago

Question

If possible, shake hands.

Answered: 1 week ago

Question

Have roles been defined and assigned?

Answered: 1 week ago

Question

Are these written ground rules?

Answered: 1 week ago