Python学习Day10
程序员文章站
2024-02-24 15:01:07
...
距离上一次学习Python过去了十天,被老师召唤去了了解了weka的一些知识
今天主要是完成了之前弄到一半的数值统计的代码;
字典类型的数据的定义、函数以及操作;
第三方库jieba库的安装以及jieba库的三种模式及对应的函数的应用。
'''def getNum():
num=[]
iNumStr=input("Please input a number:")
while iNumStr!="":
num.append(eval(iNumStr))
iNumStr = input("Please input a number:")
return num
def mean(numbers):
s=0.0
for num in numbers:
s+=num
return s/len(numbers)
def dev(numbers,mean):
sdev=0.0
for num in numbers:
sdev+=(num-mean)**2
return pow((sdev/len(numbers)-1),0.5)
def medain(numbers):
sorted(numbers)
size=len(numbers)
if size%2==0:
med=(numbers[size//2-1]+numbers[size//2])/2
else:
med=numbers[size]/2
return med
n=getNum()
m=mean(n)
print("The mean is:{},The dev is:{},The medain is:{}".format(mean(n),dev(n,m),medain(n)))
'''
'''#Dictionary
d={"China":"Beijing","American":"Washington","United Kindom":"London"}
print(d.keys())
print(d.values())
print(d.items())
d["Janpan"]="Tokyo" #input an item into the dic
print(d.items())
print(d.get("China","Error"))
print(d.popitem())
print(len(d))
'''
#The Using of jieba
import jieba
s="*是一个伟大的国家"
print(jieba.lcut(s))#精确模式
print(jieba.lcut(s,cut_all=True))#全模式
print(jieba.lcut_for_search(s))#搜索模式
上一篇: 用函数将一串字符分类