python数据处理不用编程_用Python玩转数据数据处理相关小例编程题
描述
有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?”)
code
a = dict(xiaoyun = '88888', xiaohong = '5555555', xiaoteng = '11111', xiaoyi = '1234321', xiaoyang = '1212121')
def findDalao(dicta, b = 'y'):
while b == 'y':
name = raw_input("Please input the name:")
while name not in dicta:
name = raw_input("invalid key,pls enter again:")
print('The QQ of %s is %s'% (name, dicta[name]))
b = raw_input('text y if you wanna continue:')
else:
print('find dalao qq ends')
def findNiceQQ(x):
print('Who has the nice number:')
for y in x.keys():
if len(x[y]) <= 5:
print(y)
findDalao(a)
findNiceQQ(a)
result
Please input the name:xiaoha
invalid key,pls enter again:xiaocheng
invalid key,pls enter again:xiaoteng
The QQ of xiaoteng is 11111
text y if you wanna continue:y
Please input the name:xiaoyun
The QQ of xiaoyun is 88888
text y if you wanna continue:n
find dalao qq ends
Who has the nice number:
xiaoyun
xiaoteng
總結
以上是生活随笔為你收集整理的python数据处理不用编程_用Python玩转数据数据处理相关小例编程题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python爬虫网络请求超时是什么意思_
- 下一篇: python url编码 空格_使用请求