1. 程式人生 > >笨辦法學Python-9/1

笨辦法學Python-9/1

開始

用power shell 啟動 py

mkdir  xx

cd fileee(用來儲存py的資料夾)

python ex11.py

⬆可以直接得到上次輸入的內容

習題12  raw_input

age=raw_input("who are you \n")
print "oh,you are %r,welcome" %(age)

wrong: %(age) forget  

good: add \n,prettier

習題13 argv

from sys import argv
script,first,second,third = argv
print "script:",script 
print "first;", first
print "second:", second
print "third:", third

POWERSHELL
python  2ex12.py aaa bbb ccc

wrong:import;  程式碼上一半的First second third可以更改,但必須對應; python後的為檔案 輸入輸入資料

習題13 argv

from sys import argv

script,name = argv
prompt = '>'

print "hi,%s,i am %s" %(name, script)
print "let me ask you, do you like me, %s" %name
likes = raw_input(prompt)
print "why are you here? %s" %name 
lives = raw_input(prompt)

print """
so you said %r,i am happy,and i am sorry %r
"""%(likes,lives)

wrong1:最後print漏了一個%r,

image/