python程序设计基础九

北京中科白瘕风是几级医院 https://m-mip.39.net/m/mipso_5963408.html
python程序设计基础(九)02:06来自LearningYard学苑

python程序设计基础(九)

今天讲诉python的案例理解函数。

个人用python实现目标一般有下面4个步骤。

首先,明确目的;

其次,为实现目的而使用的方法;

再其次,理清实现流程,即方法的具体化;

最后是流程的代码化。

案例:输入一个2-的整数,输出两个素数且两素数为输入整数的和,若存在多个组合,则全部输出。

分析题目。整体来说,需要有3个功能。

读取整数。直接使用input()函数;

判断是否为素数。则对该整数2到该数1/2+1()依次取余判断,这里之所以取到该数1/2+1是因为素数的实质是对该数因式分解后的数字组合进行判断是否有除1和数字本身的因子,数字的因子最大取数字的1/2,若最大范围大数字本身会重复判断,就像66=2*33,66=33*2一样,后面的33不需要判断。

案例涉及函数嵌套使用。Tu(n)调用tu()函数,在函数中调用开始定义的issu()函数。此函数开始时在后面一个对i的遍历,范围到n*0.5+1与上面道理一样,防止重复。

在(1,n*0.55+1)找两个何为n的数,调用issu()判断整数是否为素数。当两个满足且返回Ture时,即满足题目要求。

英文翻译

TodayIwilltalkaboutthecaseunderstandingfunctionofpython.

Therearegenerallythefollowing4stepstoachievepersonalgoalswithpython.

First,clarifythepurpose;

Second,themethodusedtoachievethepurpose;

Secondly,clarifytherealizationprocess,thatis,theconcreteizationofthemethod;

Thelastisthecodingoftheprocess.

Explainwithacase.

Topic:Inputanintegerfrom2-,outputtwoprimenumbersandthetwoprimenumbersarethesumoftheinputintegers.Iftherearemultiple


转载请注明:http://www.aierlanlan.com/rzgz/6556.html

  • 上一篇文章:
  •   
  • 下一篇文章: