# -*- coding: utf-8 -*- ####ID robot #### Exercise: #### #### You have a robot moving in the plane. The robot obeys the following commands. #### #### e: move one unit to the right, w: move one unit to the left, n: move one unit upwards, s: move one unit downwards #### .: do not move, d: double the size of the unit of motion, h: halve the size of the unit of motion #### r: move to the point symmetric with respect to the x-axis, R: move to the point symmetric with respect to the y-axis #### #### Initially the robot is at location (0, 0) and the unit of motion is 1. #### #### Write a python function #### #### move(command) #### #### where command is a string each of whose letters is one of the above commands. The robot reads the string from left to right #### and executes the commands. Your function must return a list with two numbers (floats) [x, y] with the robot's final position. #### #### If the string contains letters which are not among the above-listed commands then these letters must be skipped. #### #### For example, if command is the string "e.enAwwsSs" then [x, y] shall be [0., -1.]. #### #### Write your code only between the the two lines marked START and STOP below. Do not alter any of the other lines. #### #### To run your program, stored in the file user.py, you give the command #### #### python user.py #### #### To check your program with the tester you give the command #### #### python tester.py #### #### or #### #### python tester.py filename.py #### #### if your program has been stored in filename.py. command = raw_input("Please give the command string to the robot: ") #### Assumptions: #### #### At this point the string command has been given. #### #### Requirements: #### #### The function move() that you must fill in below must compute what is described above. ############################################################################# #### You must not give any print or input functions in your code below. ############################################################################# #### Do not change anything down to the next line. ####START You write your code after this line. def move(command): x, y = 0., 0. step = 1. for c in command: if c=="e": x += step; continue if c=="w": x -= step; continue if c=="n": y += step; continue if c=="s": y -= step; continue if c=="d": step *= 2.; continue if c=="h": step *= 0.5; continue if c=="r": y = -y; continue if c=="R": x = -x; continue return [x, y] ####STOP Do not change anything on this line or below. print "input = %r\noutput = %r" % (command, move(command))