有5名某界大佬xiaoyun、xiaohong、xiaoteng、xiaoyi和xiaoyang,其qq號分別是88888、5555555、11111、1234321和1212121,用字典將這些資料組織起來。程式設計實現以下兩個功能:
(1)使用者輸入某乙個大佬的姓名後可以輸出其qq號,如果輸入的姓名不在字典中則返回提示資訊並允許再次輸入;
(2)尋找所有有qq靚號(5位數或小於5位數)的大佬,輸出所有姓名。
其中python 2中提示輸入和輸出結果的兩句提示語請使用如下形式:
name = raw_input("please input the name:")
print "who has the nice qq number?"
其中python 3中提示輸入和輸出結果的兩句提示語請使用如下形式:
name = input("please input the name:")
print("who has the nice qq number?")
>>> adict =
>>> def qq():
name = input('please input the name:')
if name in adict.keys():
print(adict[name])
else:
print( 'the name does not exist.')
a = input('try again:y or n?')
if a == 'y':
qq()
else:
return 'bey!'
>>> qq()
please input the name:q
the name does not exist.
try again:y or n?y
please input the name:xiaoyun
88888
>>> qq()
please input the name:xiaoyun
88888
>>> qq()
please input the name:q
the name does not exist.
try again:y or n?n
'bey!'
>>> def nm():
print('who has the nice qq number?')
for i in adict.keys(): #!!!
if len(str(adict[i])) <= 5: #整數沒有長度,要轉化成字串
print(i)
>>> nm()
who has the nice qq number?
xiaoyun
xiaoteng
python資料處理相關
1.enumerate sequence,start 0 函式 列舉函式,傳入乙個序列或迭代物件,列舉輸出乙個序號物件。可用於對序列資料進行編號。2.字串的split 方法和strip 方法 同屬字串物件的方法。split 方法用於指定分割字元並返回乙個字串列表。strip 方法用於去除掉首位的指定...
Python 資料處理 小函式
preface 最近在整內比賽mdd。遇到一些資料處理方面的事情,用python pandas是最為方便的,遠比我想象的強大。幾行 就完成了資料的處理,多個檔案的融合,再用sklearn裡面的模型跑一跑,就能得到結果。為此,經常記錄下來,對資料處理的應用。df pd.read csv s s inp...
資料處理相關
資料集分為特徵值和目標值 由特徵值得到目標值 對特徵值的處理為特徵工程 1 缺失值處理 2 重複值的去重 特徵工程的意義 提高對未知資料的 字典特徵資料抽取 對字串轉成數字的,類 sklearn.feature extraction.dictvectorizer 文字特徵抽取 類 sklearn.f...