MOOC作業練習10

2021-09-18 06:06:39 字數 1018 閱讀 6355

請完成以下檔案綜合程式設計迷你專案。

(1) 建立乙個檔案blowing in the wind.txt,其內容是:

how many roads must a man walk down

before they call him a man

how many seas must a white dove sail

before she sleeps in the sand

how many times must the cannon balls fly

before they』re forever banned

the answer my friend is blowing in the wind

the answer is blowing in the win

(2) 在檔案頭部插入歌名「blowin』 in the wind」

(3) 在歌名後插入歌手名「bob dylan」

(4) 在檔案末尾加上字串「1962 by warner bros. inc.」

(5) 在螢幕上列印檔案內容

def

insert_line

(lines)

: lines.insert(0,

"blowin'in the wind\n"

) lines.insert(1,

"bob dylan\n"

)"\n1962 by warner bros.inc"

)return

"".join(lines)

with

open

('blowing in the wind.txt'

,'r+'

)as f:

lines = f.readlines(

) string=insert_line(lines)

print

(string)

f.seek(0)

f.write(string)

MOOC作業練習6

驗證命題 如果乙個三位整數是 37 的倍數,則這個整數迴圈左移後得到的另兩個 3 位 數也是 37 的倍數。注意驗證命題的結果輸出方式,只要輸出命題為真還是假即可,而 非每乙個三位數都有乙個真假的輸出 先把37的倍數都求出來,再檢查 a i for i in range 100 1000 if i ...

MOOC作業練習8

驗證哥德 猜想之一 2000 以內的正偶數 大於等於 4 都能夠分解為兩個質數之 和。每個偶數表達成形如 4 2 2 的形式。ast i for i in range 4 2001,2 把所有大於4的偶數做成列表 bst for i in range 2 2000 找出2000內所有的素數 k in...

MOOC作業練習12

一 序列函式 students jack bob rose wolf for i,j in enumerate students 列舉列表 print i,j 0 jack 1 bob 2 rose 3 wolf list reversed students 反轉並生成新列表 wolf rose b...