Skip to content

Instantly share code, notes, and snippets.

@TheMuellenator
Last active January 18, 2024 20:03
Show Gist options
  • Save TheMuellenator/dc4d84419c38a5aa023f85c26bea2dc7 to your computer and use it in GitHub Desktop.
Save TheMuellenator/dc4d84419c38a5aa023f85c26bea2dc7 to your computer and use it in GitHub Desktop.
Python Functions Coding Exercise - Part 1 Solution
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
@Dade-Isard
Copy link

wonder what its got to say about jesus taking the wheel... i know... i'll ask

@vicentesurraco
Copy link

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.

@PiotrSochaczewski
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment