IPO(Input Processing Output)模式,即輸入數(shù)據(jù)→處理數(shù)據(jù)→輸出結(jié)果。例如:
# month.py months="JanFebMarAprMayJunJulAugSepOctNovDec" n=input("請輸入月份數(shù)(1-12):") tran=(int(n)-1)*3 monthAbbrev=months[tran:tran+3] print("月份簡寫是:"+monthAbbrev+".")
注:采用input輸入內(nèi)容為字符串格式,若輸入為數(shù)值時,應(yīng)采用int()、float()和complex()等指令將輸入值(字符串類型)轉(zhuǎn)化為數(shù)字類型。
若想直接得到數(shù)字類型的輸入值,可采用eval_r()函數(shù)取得輸入結(jié)果返回值。
python學(xué)習(xí)網(wǎng),免費(fèi)的在線學(xué)習(xí)python平臺,歡迎關(guān)注!