-
-
Save thinkjson/a05a0a3f7514b4087a43 to your computer and use it in GitHub Desktop.
Intro to Programming Lesson 2
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
| $ python | |
| Python 2.7.8 (default, Apr 8 2015, 14:55:10) | |
| [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin | |
| Type "help", "copyright", "credits" or "license" for more information. | |
| >>> from speech import say | |
| >>> say('this is a test') | |
| >>> say('this is a test') | |
| >>> say('Hello Ellisheva!') | |
| >>> say('hello daddy') | |
| >>> "na"*3 | |
| 'nanana' | |
| >>> "na"*10 + " batman" | |
| 'nananananananananana batman' | |
| >>> say("na"*10 + " batman") | |
| >>> say("happy happy joy joy"*4) | |
| >>> say("My name is Elisheva") | |
| >>> say("My name is Ellie") | |
| >>> say("hello mommy"") | |
| File "<stdin>", line 1 | |
| say("hello mommy"") | |
| ^ | |
| SyntaxError: EOL while scanning string literal | |
| >>> say("hello mommy") | |
| >>> say("hello mommy".replace('mommy', 'daddy')) | |
| >>> "hello " + "daddy" | |
| 'hello daddy' | |
| >>> say("hello " + "daddy") | |
| >>> say('no bite') | |
| >>> say('no bite!') | |
| >>> say('no BITE!') | |
| >>> for x in range(3): | |
| ... say('hip hip') | |
| ... say('horray') | |
| File "<stdin>", line 3 | |
| say('horray') | |
| ^ | |
| SyntaxError: invalid syntax | |
| >>> for x in range(3): | |
| ... say('hip hip') | |
| ... | |
| >>> say('horray') | |
| >>> for x in range(4): | |
| ... say('my name is') | |
| ... | |
| >>> say('sli sli slim shady') | |
| >>> while text = raw_input('say: '): | |
| File "<stdin>", line 1 | |
| while text = raw_input('say: '): | |
| ^ | |
| SyntaxError: invalid syntax | |
| >>> while text: | |
| ... text = raw_input('say: ') | |
| ... say(text) | |
| ... | |
| Traceback (most recent call last): | |
| File "<stdin>", line 1, in <module> | |
| NameError: name 'text' is not defined | |
| >>> text = None | |
| >>> while text: | |
| ... text = raw_input('say: ') | |
| ... say(text) | |
| ... | |
| >>> while True: | |
| ... text = raw_input('say: ') | |
| ... say(text) | |
| ... | |
| say: test | |
| say: this is a test | |
| say: hello ellie | |
| say: come in daddy |
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
| import subprocess | |
| import shlex | |
| def say(text): | |
| subprocess.call(shlex.split('say %s' % text)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment