Last login: Wed Apr 23 02:28:43 on ttys001 $ python3 Python 3.4.0 (v3.4.0:04f714765c13, Mar 15 2014, 23:02:41) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> help() Welcome to Python 3.4! This is the interactive help utility. If this is your first time using Python, you should definitely check out the tutorial on the Internet at http://docs.python.org/3.4/tutorial/. Enter the name of any module, keyword, or topic to get help on writing Python programs and using Python modules. To quit this help utility and return to the interpreter, just type "quit". To get a list of available modules, keywords, symbols, or topics, type "modules", "keywords", "symbols", or "topics". Each module also comes with a one-line summary of what it does; to list the modules whose name or summary contain a given string such as "spam", type "modules spam". help> int help> q You are now leaving help and returning to the Python interpreter. If you want to ask for help on a particular object directly from the interpreter, you can type "help(object)". Executing "help('string')" has the same effect as typing a particular string at the help> prompt. >>> bob = >>> bob = {"name":"Bob Smith", "age":25, "height":65, "weight": 155} File "", line 1 bob = {"name":"Bob Smith"Bob Smith", "age":25, "height":65, "weight": 155} ^ SyntaxError: invalid syntax >>> bob = {"name":"Bob Smith", "age":25, "height":65, "weight": 155} >>> bob {'weight': 155, 'age': 25, 'height': 65, 'name': 'Bob Smith'} >>> bob["name"] 'Bob Smith' >>> bob["age"] 25 >>> alice = {"name": "Alice Jones", "age":15, "weight":130, "height": 57} >>> alice {'weight': 130, 'age': 15, 'height': 57, 'name': 'Alice Jones'} >>> alice["age"] == bob["age"} File "", line 1 alice["age"] == bob["age"} ^ SyntaxError: invalid syntax >>> alice["age"] == bob["age"] False >>> alice["age"] + 5 20 >>> 15 + 5 20 >>> "15" + 5 Traceback (most recent call last): File "", line 1, in TypeError: Can't convert 'int' object to str implicitly >>> people = [12, 5] >>> people [12, 5] >>> people = [] >>> people.append(bob) >>> people [{'weight': 155, 'age': 25, 'height': 65, 'name': 'Bob Smith'}] >>> people.append(alice) >>> people [{'weight': 155, 'age': 25, 'height': 65, 'name': 'Bob Smith'}, {'weight': 130, 'age': 15, 'height': 57, 'name': 'Alice Jones'}] >>> people[0] {'weight': 155, 'age': 25, 'height': 65, 'name': 'Bob Smith'} >>> people[1] {'weight': 130, 'age': 15, 'height': 57, 'name': 'Alice Jones'} >>> people[0:2] [{'weight': 155, 'age': 25, 'height': 65, 'name': 'Bob Smith'}, {'weight': 130, 'age': 15, 'height': 57, 'name': 'Alice Jones'}] >>> people[0:1] [{'weight': 155, 'age': 25, 'height': 65, 'name': 'Bob Smith'}] >>> people[0:2] [{'weight': 155, 'age': 25, 'height': 65, 'name': 'Bob Smith'}, {'weight': 130, 'age': 15, 'height': 57, 'name': 'Alice Jones'}] >>> people[:2] [{'weight': 155, 'age': 25, 'height': 65, 'name': 'Bob Smith'}, {'weight': 130, 'age': 15, 'height': 57, 'name': 'Alice Jones'}] >>> for person in people: ... Display all 190 possibilities? (y or n) ... c KeyboardInterrupt >>> for person in people: ... print(person["weight"]) ... 155 130 >>> for person in people: ... print(person["weight"]) ... print(person["height"]) ... 155 65 130 57 >>> my_string = "Hello there" >>> my_string 'Hello there' >>> for letter in my_string: ... print(letter) ... H e l l o t h e r e >>> for blahblah in my_string: ... print(blahblah) ... H e l l o t h e r e >>> def join(word1, word2): ... return word1 + word2 ... >>> join("hello", "world") 'helloworld' >>> def firstletter(word): ... return word[0] ... >>> firstletter("hello") 'h' >>> def isLong(word): ... return len(word) > 3 ... >>> isLong("and"0 File "", line 1 isLong("and"0 ^ SyntaxError: invalid syntax >>> isLong("and") False >>> isLong("andy") True >>> from functools import reduce >>> def acronym(sentence): ... return reduce(join, map(firstletter, filter(isLong, sentence.split()))) ... >>> acronym("Beauty and Joyy of Computing") 'BJC' >>> ^D Michael at Mavericks-Retina in ~/Dropbox/CS10-2014Sp/Lectures/L23 - Besides Blocks II/code $ python3 ttt.py Welcome to Tic-Tac-Toe, brought to you by GamesCrafters! We've 'solved' the game, so you can see the value (win, lose, tie) of moves to make. Just type V whenever you want to see the values. 3 | 2 | 1 | +------ A B C Choose your move (e.g., A1, B3, etc), V for values, Q for quit: B2 3 | 2 | X 1 | +------ A B C Choose your move (e.g., A1, B3, etc), V for values, Q for quit: V Here are the values for this position's moves (W=win, T=tie, L=lose) 3 | T L T 2 | L L 1 | T L T +------ A B C Choose your move (e.g., A1, B3, etc), V for values, Q for quit: u http://nyc.cs.berkeley.edu:8080/gcweb/service/gamesman/puzzles/ttt/getNextMoveValues;board=%20%20%20%20X%20%20%20%20;width=3;height=3;pieces=3 Choose your move (e.g., A1, B3, etc), V for values, Q for quit: Please choose V or one of (without quotes): ['C1', 'A2', 'C2', 'A3', 'B3', 'C3', 'B1', 'A1'] Choose your move (e.g., A1, B3, etc), V for values, Q for quit: Please choose V or one of (without quotes): ['C1', 'A2', 'C2', 'A3', 'B3', 'C3', 'B1', 'A1'] Choose your move (e.g., A1, B3, etc), V for values, Q for quit: Please choose V or one of (without quotes): ['C1', 'A2', 'C2', 'A3', 'B3', 'C3', 'B1', 'A1'] Choose your move (e.g., A1, B3, etc), V for values, Q for quit: q Thanks for the game! Michael at Mavericks-Retina in ~/Dropbox/CS10-2014Sp/Lectures/L23 - Besides Blocks II/code $