-
-
Save TheMuellenator/dc4d84419c38a5aa023f85c26bea2dc7 to your computer and use it in GitHub Desktop.
tracker = 0 | |
def moveForwards(): | |
global tracker | |
tracker += 1 | |
print('moved forward by one step.') | |
def turnRight(): | |
global tracker | |
tracker -= 1 | |
print('turning right') | |
def move(): | |
#Solution | |
moveForwards() | |
turnRight() | |
turnRight() | |
turnRight() | |
moveForwards() | |
turnRight() | |
turnRight() | |
turnRight() | |
moveForwards() | |
turnRight() | |
moveForwards() | |
turnRight() | |
moveForwards() | |
moveForwards() | |
return tracker | |
can you plz explain me how this tracker is moving ?
moveForwards()
turnRight()
turnRight()
turnRight()
moveForwards()
turnRight()
turnRight()
turnRight()
moveForwards()
turnRight()
moveForwards()
turnRight()
moveForwards()
moveForwards()
instead of turning it left by 90deg, here we are turning to right by 270deg
Can you please explain whats the need of global tracker variable ? Why do we need to check its count?
Could you pleas give an explaination for the given solution:
#Solution
moveForwards()
turnRight()
turnRight()
turnRight()
moveForwards()
turnRight()
turnRight()
turnRight()
moveForwards()
turnRight()
moveForwards()
turnRight()
moveForwards()
moveForwards()
I hope this explanation works.
moveForward() --> moves one FULL box instead of HALF a box.
@TheMuellenator Could the answer have fewer lines of code if you add this function?
def turnLeft():
turnRight()
turnRight()
turnRight()
print('turning left')
#Solution
moveForwards()
turnLeft()
moveForwards()
turnLeft()
moveForwards()
turnRight()
moveForwards()
turnRight()
moveForwards()
moveForwards()
def turnLeft():
global tracker
tracker -= 3
print('turning left')
def move():
moveForwards()
turnLeft()
moveForwards()
turnLeft()
moveForwards()
turnRight()
moveForwards()
turnRight()
moveForwards()
moveForwards()
return tracker
Can you please explain global function in here?
cant you just make/trick the tracker into making negative right turns rather than the analog right(), right(), right(), until desired direction?
If you ever get stuck in coding, just ask ChatGPT; they will make the script for you and you can ask anything to explain it in detail.
wonder what its got to say about jesus taking the wheel... i know... i'll ask
for those asking about the tracker, since "moveforwards" and "turnright" does not mean anything to Python, the tracker exists to serve as a proxy test to see whether you moved forward or moved right the correct number of times.
This exersice have logical issue. We define function move() by calling two functions moveForwards() and trunRight()
BUT
we never call function move(). And this is where the logic error occure: if you only define function you pass exersice, but if you define and call it you fail test. But only defining function doesn't make move so this excersice omite important part of calling the function.
can you plz explain me how this tracker is moving ?
moveForwards()
turnRight()
turnRight()
turnRight()
moveForwards()
turnRight()
turnRight()
turnRight()
moveForwards()
turnRight()
moveForwards()
turnRight()
moveForwards()
moveForwards()