Python Forum
Position after given movements
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Position after given movements
#1
Hello everybody,

I have a task that I don't quite understand how to tackle.

At the moment I have written this code but I do not get the result that it should give, I leave the code:
movement = str(input("Write movements: "))
m = list(movement)
lon = len(movement)
Turnleft = 0
Turnright = 0
Up = 0
Down = 0
Leftside = 0
Rightside = 0

for i in range(lon):
	p = m[i]
	if i == 0 and p == "F":
		Turnright += 1
	elif  p == "F":
		if m[i-1] == "L":
			Turnleft += 1
		if m[i-1] == "R":
			Turnright += 1
		if m[i-1] == "U":
			Up += 1
		if m[i-1] == "D":
			Down += 1
		if m[i-1] == "X":
			Leftside += 1
		if m[i-1] == "Y":
			Rightside += 1

	x = Turnright - Turnleft
	y = Up - Down
	z = Leftside - Rightside
	print(x, y, z)
If anyone can fix the code for me, I appreciate it.

TASK LINK
Reply


Messages In This Thread
Position after given movements - by SantiagoPB - Apr-18-2021, 07:22 PM
RE: Position after given movements - by Larz60+ - Apr-18-2021, 08:43 PM
RE: Position after given movements - by SantiagoPB - Apr-18-2021, 08:47 PM
RE: Position after given movements - by jefsummers - Apr-19-2021, 05:46 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020