Last active
December 15, 2015 12:59
-
-
Save Glench/5264091 to your computer and use it in GitHub Desktop.
A new-to-programming student asked me why you would use functions. I gave this example and I feel like this explains it well, building up abstraction from a concrete example to a more powerful, general one. For the record, you shouldn't use '+' to put strings together and you shouldn't do language translation this way. This is just to illustrate…
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
def say_hello_glen(): | |
return 'hello, glen' | |
def say_hello(name): | |
return 'hello, ' + name | |
def greet(name, language): | |
if language is 'spanish': | |
return 'hola, ' + name | |
if language is 'english': | |
return 'hello, ' + name | |
else: | |
return 'heeeey' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment