Last active
January 18, 2024 20:03
-
-
Save TheMuellenator/dc4d84419c38a5aa023f85c26bea2dc7 to your computer and use it in GitHub Desktop.
Python Functions Coding Exercise - Part 1 Solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
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
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.