Created
July 7, 2017 00:37
-
-
Save thinkjson/710e89bac3df35cd1ce08aa8b6f9178b to your computer and use it in GitHub Desktop.
Programming lesson: imports, function definition, keyboard shortcuts, function calls, for loops, iteration and conditionals
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
| # Imports | |
| import subprocess | |
| # Function definition | |
| def say(thing): | |
| subprocess.call('say %s' % thing, shell=True) | |
| # Keyboard shortcuts | |
| # Cmd+S save | |
| # Cmd+C copy | |
| # Cmd+V paste | |
| # Cmd+Z undo (oops) | |
| # Function calls | |
| # def mal(): | |
| # say("This is a malfunction ha ha") | |
| # mal() | |
| # For loops | |
| # for x in range(3): | |
| # say('ha') | |
| # for x in range(3): | |
| # say('hee') | |
| # Iteration and conditionals | |
| for phrase in ['ha', 'hee']: | |
| times = 3 if phrase == 'hee' else 1 | |
| for x in range(times): | |
| say(phrase) | |
| # PythonTurtle | |
| # go(50) | |
| # turn(270) | |
| # go(99) | |
| # go(400) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment