【Python爬蟲】-笨辦法學Python練習01-10文章

習題一:

#-*- coding: utf-8-*-

print("Hello World!")

print("Hello Again")

print("I like typing this.")

print("This is fun.")

print('Yay! Printing.')

print("I'd much rather you 'not'.")

print('I "said" do not touch this.')

習題二:

# A comment, this is so you can read your program later.

# Anything after the # is ignored by python.

print ("I could have code like this.") # and the comment after is ignored

# You can also use a comment to "disable" or comment out a piece of code:

# print "This won't run."

# # is call 'octothorpe' or 'pound character'.

print ("This won't run.")

習題三:

print("I will now count my chickens:")

print("Hens",25+30//6)

print("Roosters",100-25*3%4)

print("Now I will count the eggs:")

print(3+2+1-5+4%2-1//4+6)

print("Is it true that 3 + 2 < 5 - 7?")

print(3+2<5-7)

print("What is 3 + 2?",3+2)

print("What is 5 - 7?",5-7)

print("Oh, that's why it's False.")

print("How about some more.")

print("Is it greater?",5> -2)

print("Is it greater or equal?",5>= -2)

print("Is it less or equal?",5<= -2)

習題四:

cars = 100

space_in_a_car = 4

drivers = 30

passengers = 90

cars_not_driven = cars - drivers

cars_driven = drivers

carpool_capacity = cars_driven * space_in_a_car

average_passengers_per_car = passengers / cars_driven

print("There are", cars, "cars available.")

print("There are only", drivers, "drivers available.")

print("There will be", cars_not_driven, "empty cars today.")

print("We can transport", carpool_capacity, "people today.")

print("We have", passengers, "to carpool today.")

print("We need to put about", average_passengers_per_car, "in each car.")

習題五:

name = 'Zed A. Shaw'

age = 35 # not a lie

height = 74 # inches

weight = 180 # lbs

eyes = 'Blue'

teeth = 'White'

hair = 'Brown'

# %s %r的區(qū)別

print ("Let's talk about %r." % name)

print ("Let's talk about %s." % name)

print ("He's %d inches tall." % height)

print ("He's %d pounds heavy." % weight)

print ("Actually that's not too heavy.")

print ("He's got %s eyes and %s hair." % (eyes,hair))

print ("His teeth are ususlly %s depending on the coffee. " % teeth)

# this line is tricky, try to get is exactly right

print ("If I add %d, %d, and %d I get %d." % (age, height, weight, age + height + weight))

習題六:

x="There are %d types of people."%10

binary ="binary"

do_not ="don't"

y=" Those who know %s and those who %s."% (binary, do_not)

print(x)

print(y)

print("I said: %r."%x)print("I also said: '%s."%y)

hilarious = False

joke_evaluation ="Isn't that joke so funny?! %r"

print(joke_evaluation % hilarious)

w ="This is the left side of ..."

e ="a string with a right side."

print(w + e)

習題七:

print("Mary had a little lamb.")

print ("Its fleece was white as %s ." % 'snow')

print("And everywhere that Mary went.")

print ("." * 10)?

end1 = "C"

end2 = "h"

end3 = "e"

end4 = "e"

end5 = "s"

end6 = "e"

end7 = "B"

end8 = "u"

end9 = "r"

end10 = "g"

end11 = "e"

end12 = "r"

print (end1 + end2 + end3 + end4 + end5 + end6,)

print (end7 + end8 + end9 + end10 + end11 + end12)

習題八:

formatter ="%r %r %r %r"

print(formatter% (1,2,3,4))

print(formatter% ("one","two","three","four"))

print(formatter% (True, False, False, True))

print(formatter% (formatter, formatter, formatter, formatter))

print(formatter% ("I had this thing.","That you could type up right.","But it didn't sing.","So I said goodnight."))

習題九:

days = "Mon Tue Wed Thu Fri Sat Sun"

months = "\nJan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"

print ("Here are the days:", days)

print ("Here are the months: ", months)

print("""

There's something going on here:

With the three double quotes.

We'll be able to type as much as we like.

Even 4 lines if we want, or 5 or 6.

""")

習題十:

tabby_cat="\tI'm tabbed in."

persian_cat="I'm split\non a line."

backslash_cat="I'm \\ a\\ cat."

fat_cat="""

I'll do a list:

\t* Cat food

\t* Fishies

\t* Catnip\n\t* Grass

"""

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末钮糖,一起剝皮案震驚了整個濱河市募胃,隨后出現(xiàn)的幾起案子兄渺,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,858評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件底哗,死亡現(xiàn)場離奇詭異宪哩,居然都是意外死亡,警方通過查閱死者的電腦和手機纬乍,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,372評論 3 395
  • 文/潘曉璐 我一進店門碱茁,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人仿贬,你說我怎么就攤上這事纽竣。” “怎么了茧泪?”我有些...
    開封第一講書人閱讀 165,282評論 0 356
  • 文/不壞的土叔 我叫張陵蜓氨,是天一觀的道長。 經(jīng)常有香客問我队伟,道長穴吹,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,842評論 1 295
  • 正文 為了忘掉前任嗜侮,我火速辦了婚禮港令,結(jié)果婚禮上啥容,老公的妹妹穿的比我還像新娘。我一直安慰自己顷霹,他們只是感情好咪惠,可當我...
    茶點故事閱讀 67,857評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著淋淀,像睡著了一般遥昧。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上朵纷,一...
    開封第一講書人閱讀 51,679評論 1 305
  • 那天炭臭,我揣著相機與錄音,去河邊找鬼柴罐。 笑死徽缚,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的革屠。 我是一名探鬼主播凿试,決...
    沈念sama閱讀 40,406評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼似芝!你這毒婦竟也來了那婉?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,311評論 0 276
  • 序言:老撾萬榮一對情侶失蹤党瓮,失蹤者是張志新(化名)和其女友劉穎详炬,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體寞奸,經(jīng)...
    沈念sama閱讀 45,767評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡呛谜,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,945評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了枪萄。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片隐岛。...
    茶點故事閱讀 40,090評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖瓷翻,靈堂內(nèi)的尸體忽然破棺而出聚凹,到底是詐尸還是另有隱情,我是刑警寧澤齐帚,帶...
    沈念sama閱讀 35,785評論 5 346
  • 正文 年R本政府宣布妒牙,位于F島的核電站,受9級特大地震影響对妄,放射性物質(zhì)發(fā)生泄漏湘今。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,420評論 3 331
  • 文/蒙蒙 一饥伊、第九天 我趴在偏房一處隱蔽的房頂上張望象浑。 院中可真熱鬧蔫饰,春花似錦、人聲如沸愉豺。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,988評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽蚪拦。三九已至杖剪,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間驰贷,已是汗流浹背盛嘿。 一陣腳步聲響...
    開封第一講書人閱讀 33,101評論 1 271
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留括袒,地道東北人次兆。 一個月前我還...
    沈念sama閱讀 48,298評論 3 372
  • 正文 我出身青樓,卻偏偏與公主長得像锹锰,于是被迫代替她去往敵國和親芥炭。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,033評論 2 355

推薦閱讀更多精彩內(nèi)容