原创 exercise 24 更多練習

print "Let's practice everything." print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'

原创 exercise16 讀寫文件

需要記住的常用命令: close -- 關閉文件,相當於編輯器中的File->Save read -- 讀取文件內容分配給一個變量 readline -- 讀取一行內容 truncate -- 清空文件,小心使用這個命 write(stu

原创 ex8

formatter = "%r %r %r %r" # 中間沒有標點符號 print formatter % (1, 2, 3, 4) print formatter % ("one", "two", "three", "four"

原创 exercise7 more printing

print "Mary had a little lamb." print "Its fleece was white as %s." % 'snow' print "And everywhere that Mary went." pri

原创 exercsie13 參數 解包 變量

from sys import argv                #從python功能庫中導入功能         “features"真正的名稱是:modules   / libraries script, first, s

原创 exercise 22&23 總結+讀代碼

Here's what you do: Go to bitbucket.org, github.com, or gitorious.org with your favorite web browser and search for "p

原创 exercise9

days = "Mon Tue Wed Thu Fri Sat Sun" months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug" \n 表示回車 就是新一行 \\表示一個反斜槓符號--轉義序

原创 exercise 25 更多更多練習

def break_words(stuff): """This function will break up words for us.""" words = stuff.split(' ') #單引號中表示分隔符 默

原创 exercise 21 函數能返回信息

def add(a, b):     print "ADDING %d + %d" % (a, b)     return a + b def subtract(a, b):     print "SUBTRACTING %d - %d"

原创 exercise 12 提示

age = raw_input("How old are you? ") height = raw_input("How tall are you? ") weight = raw_input("How much do you weig

原创 exercise17 更多文件

源程序: from sys import argv from os.path import exists    ##從os.path模塊中導入exists命令 script from_file, to_file = argv print

原创 exercise 17 讀取文件_2

源程序: from sys import argv from os.path import exists  ## 從os.path模塊中導入exists script, from_file, to_file = argv print

原创 exercise 19 函數和變量

##########################################ex19 def cheese_and_crackers(cheese_count, boxes_of_crackers):     print "

原创 exercise15 讀取文件

運行文件ex15.py ex15_sample.txt  //記事本的內容 This is stuff I typed into a file. It is really cool stuff. Lots and lots of fun

原创 exercise14 提示 傳遞

script, user_name = argv prompt = '> '   #加一個提示 print "Hi %s, I'm the %s script." % (user_name, script) print "I'd like