Question
Please help me with a solution using Python
Taxi zum zum def taxi zum_zum(moves) : A Manhattan taxicab starts at the origin point (e, e) of the two-dimensional integer g
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

#code

#REQUIRED METHOD
def taxi_zum_zum(moves):
    #creating a list of directions
   
directions=['N','E','S','W']
    #dir points the current index of directions
   
dir=0
    #current position
   
x=0
    y=0
    #looping through each character in moves
   
for i in moves:
        #if character is L, turning left
       
if i=='L':
            #decrementing dir
           
dir-=1
            #if dir goes below 0, starting from other side
           
if dir<0:
                dir=3
        elif i=='R':
            #doing the same for turning right
           
dir+=1
            if dir>3:
                dir=0
        elif i=='F':
            #in the question it was M for moving forward, but in the given output,
            #it is shown as F. Also, in common logic, x should be incrementing while
            #going east and decrementing while going west. but according to the sample
            #run, it is just opposite, clearly someone is high when writing this question.
            #anyway, I have written this solution according to the given output only.
           
if directions[dir]=='N':
                y+=1 #going up/north
           
elif directions[dir]=='S':
                y-=1 #going down/south
           
elif directions[dir]=='E':
                x-=1 #going east/right
           
elif directions[dir]=='W':
                x+=1 #going west/left
    #returning a tuple containing final position
   
return (x,y)


#testing
print(taxi_zum_zum('RFRL'))
print(taxi_zum_zum('LLFLFLRLFR'))
print(taxi_zum_zum('FR'*1000))
print(taxi_zum_zum('FFLLLFRLFLRFRLRRL'))

#output

(-1, 0)

(-1, 0)

(0, 0)

(-3, 2)

Add a comment
Know the answer?
Add Answer to:
Please help me with a solution using Python Taxi zum zum def taxi zum_zum(moves) : A...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT