【Python爬蟲】-笨辦法學(xué) Python 習(xí)題 0-10

習(xí)題1:第一個程序

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 rouch this.')

加分習(xí)題

1. 讓你的腳本再多打印一行。?

舉例:print("Hello 线脚;World!")

2. 讓你的腳本只打印一行。

舉例:print("Hello World!")

3. 在一行的起始位置放一個 ‘#’ (octothorpe) 符號浑侥。它的作用是什么姊舵?

‘#’ (octothorpe) 符號--單行注釋所用


習(xí)題2:注釋和井號

#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")

print("This will run.")


習(xí)題3:數(shù)字和數(shù)學(xué)計算

print("I will now count mu 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("It is 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("It is greater?",5> -2)

print("It is greater or equal?",5>= -2)

print("It is less or equral?",5<= -2)


習(xí)題 4:? 變量(variable) 和命名

cars =100

space_in_a_car =4.0

drives =30

passengers =90

cars_not_driven = cars - drives

cars_driven = drives

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",drives,"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.")


習(xí)題 5:更多的變量和打印

my_name='Zed A.Shaw'

my_age =35#not a lie

my_height =74#inches

my_weight =180#lbs

my_eyes ='Blue'

my_teeth ='White'

my_hair ='Brown'

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

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

print("He's %d pounds heavy"% my_weight)

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

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

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

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

print("If I add %d,%d ,and%d I get %d."% (my_age,my_height,my_weight,my_age+my_height+my_weight))


習(xí)題 6:? 字符串(string)和文本

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)


習(xí)題 7:更多打印

print("Mary had a little lamb.")

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

print("And everywhere that Mary went.")

print("."*10)#what'd that do?

end1 ="C"

end2 ="h"

end3 ="e"

end4 ="e"

end5="s"

end6 ="e"

end7 ="B"

end8 ="u"

end9 ="r"

end10 ="g"

end11 ="e"

end12 ="r"

# watch that comma at the end. try removing it to see what happens

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

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


習(xí)題 8:? 打印寓落,打印

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

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

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

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

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

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


習(xí)題9:打印,打印伶选,打印

# Here's some new strange stuff, remember type it exactly.

days ="Mon Tue Wed Thu Fri Sat Sun"

months ="Jan\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.

''')


習(xí)題10:那是什么?

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

"""

print(tabby_cat)

print(persian_cat)

print(backslash_cat)

print(fat_cat)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末仰税,一起剝皮案震驚了整個濱河市构资,隨后出現(xiàn)的幾起案子陨簇,更是在濱河造成了極大的恐慌吐绵,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,968評論 6 482
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件拦赠,死亡現(xiàn)場離奇詭異,居然都是意外死亡葵姥,警方通過查閱死者的電腦和手機句携,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,601評論 2 382
  • 文/潘曉璐 我一進(jìn)店門榔幸,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人削咆,你說我怎么就攤上這事〈浪瘢” “怎么了拨齐?”我有些...
    開封第一講書人閱讀 153,220評論 0 344
  • 文/不壞的土叔 我叫張陵昨寞,是天一觀的道長瞻惋。 經(jīng)常有香客問我,道長歼狼,這世上最難降的妖魔是什么掏导? 我笑而不...
    開封第一講書人閱讀 55,416評論 1 279
  • 正文 為了忘掉前任羽峰,我火速辦了婚禮趟咆,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘梅屉。我一直安慰自己,他們只是感情好坯汤,可當(dāng)我...
    茶點故事閱讀 64,425評論 5 374
  • 文/花漫 我一把揭開白布虐唠。 她就那樣靜靜地躺著,像睡著了一般凿滤。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上庶近,一...
    開封第一講書人閱讀 49,144評論 1 285
  • 那天,我揣著相機與錄音鼻种,去河邊找鬼反番。 笑死叉钥,一個胖子當(dāng)著我的面吹牛罢缸,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播投队,決...
    沈念sama閱讀 38,432評論 3 401
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼敷鸦!你這毒婦竟也來了息楔?” 一聲冷哼從身側(cè)響起扒披,我...
    開封第一講書人閱讀 37,088評論 0 261
  • 序言:老撾萬榮一對情侶失蹤值依,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后愿险,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,586評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡价说,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,028評論 2 325
  • 正文 我和宋清朗相戀三年风秤,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片褒链。...
    茶點故事閱讀 38,137評論 1 334
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖甫匹,靈堂內(nèi)的尸體忽然破棺而出甸鸟,到底是詐尸還是另有隱情兵迅,我是刑警寧澤抢韭,帶...
    沈念sama閱讀 33,783評論 4 324
  • 正文 年R本政府宣布,位于F島的核電站恍箭,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏扯夭。R本人自食惡果不足惜惠赫,卻給世界環(huán)境...
    茶點故事閱讀 39,343評論 3 307
  • 文/蒙蒙 一瘸恼、第九天 我趴在偏房一處隱蔽的房頂上張望奥吩。 院中可真熱鬧构拳,春花似錦咆爽、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,333評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽凫海。三九已至呛凶,卻和暖如春行贪,著一層夾襖步出監(jiān)牢的瞬間把兔,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,559評論 1 262
  • 我被黑心中介騙來泰國打工瓮顽, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留围橡,地道東北人暖混。 一個月前我還...
    沈念sama閱讀 45,595評論 2 355
  • 正文 我出身青樓,卻偏偏與公主長得像拣播,于是被迫代替她去往敵國和親晾咪。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 42,901評論 2 345

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