Python語言程序程序設(shè)計(jì)-第一章習(xí)題解答

作為一名非計(jì)算機(jī)專業(yè)畢業(yè)的學(xué)生豌习,一直想學(xué)Python用來解決工作中遇到的問題,但是對計(jì)算機(jī)一直摸不到好的門路,于是買到了Python語言程序程序設(shè)計(jì)這本書,用做習(xí)題的形式角钩,積累自己的學(xué)習(xí)成果,相信不怕慢呻澜,只怕站递礼。

# 1.1

print "Welcome to Python"

print "Welcome to Computer Science"

print "Program is fun"

# 1.2

print "Welcome to Python" * 5

# 1.3

print "F"*7," "*3,"U"," "*5,"U"," "*3,"N"*2," "*4,"N"*2

print "F"*2," "*4," "*3,"U"," "*5,"U"," "*3,"N"*3," "*3,"N"*2

print "F"*7," "*3,"U"," "*5,"U"," "*3,"N"*2,"","N"*1," "*1,"N"*2

print "F"*2," "*4," "*3,"","U"," "*3,"U"," "*4,"N"*2," "*2,"N","N"*2

print "F"*2," "*4," "*5,""*3,"U"*3," "*2," "*3,"N"*2," "*3,"N"*3

# 1.4

value = [1,2,3,4]

print "a"," "*4,"a^2"," "*2,"a^3"," "*4

print "1"," "*4,"1"," "*5,"1"," "*4

print "2"," "*4,"4"," "*5,"8"," "*4

print "3"," "*4,"9"," "*5,"27"," "*4

print "4"," "*4,"16"," "*4,"64"," "*4

# 1.5

solve = (9.5*4.5 - 2.5*3)/(45.5-3.5)

print solve

# 1.6

sum = 0

for i in range(10):

sum+=i

print sum

# 1.7

from __future__ import division

pi = 0.0

for i in range(1,8):

pi += 4*(((-1)**(i+1))/(2*i-1))

print pi

from __future__ import division

pi = 0.0

for i in range(1,11):

pi += 4*(((-1)**(i+1))/(2*i-1))

print pi

# 1.7

import numpy as np

class sl():

"""docstring for sl"""

def __init__(self, radius):

super(sl, self).__init__()

self.radius = radius

def area():

s = np.pi*self.radius*self.radius

return s

def perimeter():

l = 2*np.pi*self.radius

return l

solve = sl()

radius = 5

print solve.area(radius)

def area(radius):

s = np.pi*radius*radius

return s

def perimeter(radius):

l = 2*np.pi*radius

return l

r = 5

# print "area is %s" % area(r),"perimeter is %s" perimeter(r)

print area(r),perimeter(r)

# 1.9

def s(width,height):

s = width*height

return s

def l(width,height):

l = 2*width+2*height

return l

print s(4.5,7.9),l(4.5,7.9)

# 1.10

def milePerHour(m,s,mile):

enmile = mile/1.6

hour = (m*60+s)/3600

enmile_h = enmile/hour

return enmile_h

print milePerHour(40,30,14)

# 1.11

def predictPop(year):

a0 = 3120324986

s = year*365*3600

predict_pop = a0+(s/7.0+s/45.0-s/13.0)

return predict_pop

print predictPop(1)

print predictPop(2)

print predictPop(3)

print predictPop(4)

print predictPop(5)

# 1.12

import turtle

turtle.forward(100)

turtle.right(90)

turtle.forward(200)

turtle.right(90)

turtle.forward(200)

turtle.right(90)

turtle.forward(100)

turtle.right(90)

turtle.forward(200)

turtle.right(90)

turtle.forward(100)

turtle.right(90)

turtle.forward(100)

turtle.right(90)

turtle.forward(100)

turtle.left(90)

turtle.forward(100)

turtle.right(90)

turtle.forward(100)

turtle.right(90)

turtle.forward(100)

turtle.right(90)

turtle.forward(100)

# 1.13

import turtle

turtle.right(0)

turtle.forward(200)

turtle.right(180)

turtle.forward(100)

turtle.right(90)

turtle.forward(100)

turtle.right(180)

turtle.forward(200)

# 1.14

import turtle

turtle.right(60)

turtle.forward(100)

turtle.right(120)

turtle.forward(100)

turtle.right(120)

turtle.forward(100)

# 1.15

import turtle

turtle.right(60)

turtle.forward(100)

turtle.right(120)

turtle.forward(100)

turtle.right(120)

turtle.forward(200)

turtle.left(120)

turtle.forward(100)

turtle.left(120)

turtle.forward(100)

# 1.16

import turtle

turtle.color('red')

turtle.penup()

turtle.goto(0,0)

turtle.pendown()

turtle.circle(50)

turtle.color('blue')

turtle.penup()

turtle.goto(100,0)

turtle.pendown()

turtle.circle(50)

turtle.color('orange')

turtle.penup()

turtle.goto(0,-100)

turtle.pendown()

turtle.circle(50)

turtle.color('yellow')

turtle.penup()

turtle.goto(100,-100)

turtle.pendown()

turtle.circle(50)

# 1.17

import turtle

import math

import numpy as np

from __future__ import division

turtle.penup()

turtle.goto(-39,48)

turtle.write("(-39,48)")

turtle.pendown()

turtle.goto(50,-50)

# turtle.pendown()

turtle.write("50,-50")

turtle.done()

# 1.18

import turtle

# import math

# import numpy as np

# from __future__ import division

turtle.forward(200)

turtle.right(144)

turtle.forward(200)

turtle.right(144)

turtle.forward(200)

turtle.right(144)

turtle.forward(200)

turtle.right(144)

turtle.forward(200)

# 1.19

import turtle

turtle.penup()

turtle.goto(40,-69.28)

turtle.pendown()

turtle.goto(-40,-69.28)

turtle.goto(-80,-9.8)

turtle.goto(-40,69)

turtle.goto(40,69)

turtle.goto(80,0)

turtle.goto(40,-69.28)

turtle.done()

# 1.20

import turtle

turtle.goto(100,0)

turtle.goto(150,50)

turtle.goto(50,50)

turtle.goto(0,0)

turtle.goto(0,100)

turtle.goto(100,100)

turtle.goto(100,0)

turtle.penup()

turtle.goto(0,100)

turtle.pendown()

turtle.goto(50,150)

turtle.goto(150,150)

turtle.goto(100,100)

turtle.penup()

turtle.goto(50,150)

turtle.pendown()

turtle.goto(50,50)

turtle.penup()

turtle.goto(150,150)

turtle.pendown()

turtle.goto(150,50)

turtle.done()

# 1.21

import turtle

turtle.color("blue")

turtle.penup()

turtle.goto(0,0)

turtle.pendown()

turtle.circle(100)

turtle.penup()

turtle.goto(0,0)

turtle.pendown()

turtle.write("6")

turtle.penup()

turtle.goto(0,183)

turtle.pendown()

turtle.write("12")

turtle.penup()

turtle.goto(-96,100)

turtle.pendown()

turtle.write("9")

turtle.penup()

turtle.goto(90,100)

turtle.pendown()

turtle.write("3")

turtle.penup()

turtle.goto(0,100)

turtle.pendown()

turtle.goto(0,180)

turtle.penup()

turtle.goto(0,100)

turtle.pendown()

turtle.goto(-90,100)

turtle.penup()

turtle.goto(0,100)

turtle.pendown()

turtle.goto(80,100)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市易迹,隨后出現(xiàn)的幾起案子宰衙,更是在濱河造成了極大的恐慌平道,老刑警劉巖睹欲,帶你破解...
    沈念sama閱讀 211,290評論 6 491
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異一屋,居然都是意外死亡窘疮,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,107評論 2 385
  • 文/潘曉璐 我一進(jìn)店門冀墨,熙熙樓的掌柜王于貴愁眉苦臉地迎上來闸衫,“玉大人,你說我怎么就攤上這事诽嘉∥党觯” “怎么了弟翘?”我有些...
    開封第一講書人閱讀 156,872評論 0 347
  • 文/不壞的土叔 我叫張陵,是天一觀的道長骄酗。 經(jīng)常有香客問我稀余,道長,這世上最難降的妖魔是什么趋翻? 我笑而不...
    開封第一講書人閱讀 56,415評論 1 283
  • 正文 為了忘掉前任睛琳,我火速辦了婚禮,結(jié)果婚禮上踏烙,老公的妹妹穿的比我還像新娘师骗。我一直安慰自己,他們只是感情好讨惩,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,453評論 6 385
  • 文/花漫 我一把揭開白布辟癌。 她就那樣靜靜地躺著,像睡著了一般荐捻。 火紅的嫁衣襯著肌膚如雪愿待。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,784評論 1 290
  • 那天靴患,我揣著相機(jī)與錄音仍侥,去河邊找鬼。 笑死鸳君,一個(gè)胖子當(dāng)著我的面吹牛农渊,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播或颊,決...
    沈念sama閱讀 38,927評論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼砸紊,長吁一口氣:“原來是場噩夢啊……” “哼囱挑!你這毒婦竟也來了醉顽?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,691評論 0 266
  • 序言:老撾萬榮一對情侶失蹤平挑,失蹤者是張志新(化名)和其女友劉穎游添,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體通熄,經(jīng)...
    沈念sama閱讀 44,137評論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡唆涝,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,472評論 2 326
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了唇辨。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片廊酣。...
    茶點(diǎn)故事閱讀 38,622評論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖赏枚,靈堂內(nèi)的尸體忽然破棺而出亡驰,到底是詐尸還是另有隱情晓猛,我是刑警寧澤,帶...
    沈念sama閱讀 34,289評論 4 329
  • 正文 年R本政府宣布凡辱,位于F島的核電站鞍帝,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏煞茫。R本人自食惡果不足惜帕涌,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,887評論 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望续徽。 院中可真熱鬧蚓曼,春花似錦、人聲如沸钦扭。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,741評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽客情。三九已至其弊,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間膀斋,已是汗流浹背梭伐。 一陣腳步聲響...
    開封第一講書人閱讀 31,977評論 1 265
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留仰担,地道東北人糊识。 一個(gè)月前我還...
    沈念sama閱讀 46,316評論 2 360
  • 正文 我出身青樓,卻偏偏與公主長得像摔蓝,于是被迫代替她去往敵國和親赂苗。 傳聞我的和親對象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,490評論 2 348

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

  • 一贮尉、異同對比選擇1拌滋、Python和ruby的相同點(diǎn): * 都強(qiáng)調(diào)語法簡單,都具有更一般的表達(dá)方式猜谚。python是縮...
    沃倫蓋茨閱讀 4,139評論 2 24
  • 本文把程序員所需掌握的關(guān)鍵知識總結(jié)為三大類19個(gè)關(guān)鍵概念败砂,然后給出了掌握每個(gè)關(guān)鍵概念所需的入門書籍,必讀書籍龄毡,以及...
    dle_oxio閱讀 11,087評論 6 244
  • 昨天是圣誕節(jié)吠卷,和平常的節(jié)日一樣锡垄。提前收到一些平常不怎么聯(lián)系的朋友的祝福信息沦零。 感謝微信里有你!今天是平安夜 祝大家...
    Tan_9閱讀 472評論 0 0
  • 昨天和爸爸一起陪媽媽出去學(xué)習(xí)货岭。昨天太累了路操,今天一天又特別忙疾渴,所以沒有打卡。今天再累也要把卡打了再睡覺屯仗。 昨天順路到...
    索小佳閱讀 194評論 0 0
  • 【Step1】選摘 ......接下來我們再聊聊具體執(zhí)行中有用的三個(gè)技巧:記錄搞坝、定期回顧與付費(fèi)購買。記錄的過程其實(shí)...
    糖豆豆的簡書閱讀 183評論 0 0