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