Thursday, January 2, 2014

Learn Python the hard way


Programming is fun
When the work is done
if you wanna make your work also fun:
      use Python!



######Exercise 1: A Good First Program

######Exercise 2: Comments And Pound Characters
a, How do I comment out multiple lines?
[Put a # in front of each one.]

######Exercise 3: Numbers And Math

######Exercise 4: Variables And Names
a, What is the difference between = (single-equal) and == (double-equal)?
[The = (single-equal) assigns the value on the right to a variable on the left. The == (double-equal) tests if two things have the same value]

######Exercise 5: More Variables And Printing (embedded a variable in the string)
a, print "He's got %s eyes and %s hair." % (my_eyes, my_hair)  ==> multiple format
b,  %r is a very useful one. It's like saying "print this no matter what."

######Exercise 6: Strings And Text
######Exercise 7: More Printing (watch the comman at the end)
print end1 + end2 + end3 + end4 + end5 + end6,
print end7 + end8 + end9 + end10 + end11 + end12

######Exercise 8: Printing, Printing
formatter = "%r %r %r %r"

print formatter % (1, 2, 3, 4)
print formatter % ("one", "two", "three", "four")

######Exercise 9: Printing, Printing, Printing
######Exercise 10: What Was That?
a, This use of the \ (backslash) character is a way we can put Difficult-To-Type characters into a string.
\\     Backslash ()
\'     Single-quote (')
\"     Double-quote (")
\a     ASCII bell (BEL)
\b     ASCII backspace (BS)
\f     ASCII formfeed (FF)
\n     ASCII linefeed (LF)
\N{name}     Character named name in the Unicode database (Unicode only)
\r ASCII     Carriage Return (CR)
\t ASCII     Horizontal Tab (TAB)
\uxxxx     Character with 16-bit hex value xxxx (Unicode only)
\Uxxxxxxxx     Character with 32-bit hex value xxxxxxxx (Unicode only)
\v     ASCII vertical tab (VT)
\ooo     Character with octal value ooo
\xhh     Character with hex value hh

######Exercise 11: Asking Questions
x = int(raw_input())  and raw_input()

######Exercise 12: Prompting People
a, [pydoc -p 80]
b, [age = raw_input("How old are you? ")]
c, install new package requests:
---download: curl -OL https://github.com/kennethreitz/requests/tarball/master
---tar -xvf xxx.tar
---python setup.py install

######Exercise 13: Parameters, Unpacking, Variables
a, [Remember that an important skill is paying attention to details.]  <=================
b, code:
---from sys import argv
---script, first, second, third = argv  ==>Easier way
---print "The script is called:", script

######Exercise 14: Prompting And Passing
likes = raw_input(prompt)

######Exercise 15: Reading Files
######Exercise 16: Reading And Writing Files
######Exercise 17: More Files
######Exercise 18: Names, Variables, Code, Functions
######Exercise 19: Functions And Variables
######Exercise 20: Functions And Files
######Exercise 21: Functions Can Return Something
######Exercise 22: What Do You Know So Far?
######Exercise 23: Read Some Code
######Exercise 24: More Practice
######Exercise 25: Even More Practice
######Exercise 26: Congratulations, Take A Test!
######Exercise 27: Memorizing Logic
######Exercise 28: Boolean Practice
######Exercise 29: What If
######Exercise 30: Else And If
######Exercise 31: Making Decisions
######Exercise 32: Loops And Lists
######Exercise 33: While Loops
######Exercise 34: Accessing Elements Of Lists
######Exercise 35: Branches and Functions
######Exercise 36: Designing and Debugging
######Exercise 37: Symbol Review
######Exercise 38: Doing Things To Lists
######Exercise 39: Dictionaries, Oh Lovely Dictionaries
######Exercise 40: Modules, Classes, And Objects
######Exercise 41: Learning To Speak Object Oriented
######Exercise 42: Is-A, Has-A, Objects, and Classes
######Exercise 43: Gothons From Planet Percal #25
######Exercise 44: Inheritance Vs. Composition
######Exercise 45: You Make A Game
######Exercise 46: A Project Skeleton
######Exercise 47: Automated Testing
######Exercise 48: Advanced User Input
######Exercise 49: Making Sentences
######Exercise 50: Your First Website
######Exercise 51: Getting Input From A Browser
######Exercise 52: The Start Of Your Web Game
Advice From An Old Programmer
Next Steps
Appendix A: Command Line Crash Course

No comments:

Post a Comment