分类:python
创建一个示例数据框:importpandasaspddf=pd.DataFrame([['乔峰','男',95,'降龙十八掌','主角'],['虚竹','男',93,'天上六阳掌','主角'],['段誉','男',92,'六脉神剑','主角'],['王语嫣','女',95,'熟知武诀','主角'],['包不同','男',65,'胡搅蛮缠','配角'],['康敏','女',40,'惑夫妒人','配角']],index=list('abcdef'.upper()),c...
继续阅读 >
1、定义一个画圆的函数importnumpyasnpimportmatplotlib.pyplotaspltdefplot_circle(center=(3,3),r=2):x=np.linspace(center[0]-r,center[0]+r,5000)y1=np.sqrt(r**2-(x-center[0])**2)+center[1]y2=-np.sqrt(r**2-(x-center[0])**2)+center[1]plt.plot(x,y1,c='k')plt.plot(x,y2,c='k')plt.show()2、调用plot_circle()plot_circle((5,5),r=3)调整坐标轴,重新绘图importm...
继续阅读 >
2020
09-30
方法一,用for循环来实现num=[];i=2foriinrange(2,100):j=2forjinrange(2,i):if(i%j==0):breakelse:num.append(i)print(num)方法二,用函数来实现importmathdeffunc_get_prime(n):returnfilter(lambdax:not[x%iforiinrange(2,int(math.sqrt(x))+1)ifx%i==0],range(2,n+1))printfunc_get_prime(100)输出结果为:[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,...
继续阅读 >