Skip to content

Instantly share code, notes, and snippets.

@thinkjson
Created July 7, 2017 00:37
Show Gist options
  • Select an option

  • Save thinkjson/710e89bac3df35cd1ce08aa8b6f9178b to your computer and use it in GitHub Desktop.

Select an option

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
# 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