이 글에서는 양의 정수가 소수인지 판단하기 위한 Python프로그래밍 방법을 주로 소개합니다. 여기에는 Python 수학적 연산 관련 연산 기술이 포함됩니다. 필요한 친구들은 다음을 참고하시면 됩니다
본 글의 예시는 양의 정수가 소수인지 판단하는 파이썬 프로그래밍의 방법을 설명하고 있습니다. 참고하실 수 있도록 모두와 공유해 주세요. 자세한 내용은
import string import math #判断是否素数的函数 def isPrime(n): if(n<2): return False; elif(n==2): return True; elif(n>2): for d in range(2,int(math.ceil(math.sqrt(n))+1)): if(n%d==0): return False; return True; num=input(); strNum=list(str(num)) #将输入值转换为List字符串 flag=True; #设置一个标志位 #以下循环用于对用户输入数值进行循环位移后得到的所有结果 for i in range(0,len(strNum)): lastP=strNum.pop();#获取并删除最后一位 strNum.insert(0,lastP);#将上一步删除的数字添加到最前面 stempNumStr=''; #用于保存某一步位移结果的临时变量 for each in strNum: stempNumStr+=each;#将位移后的字符串合并 stempNum=string.atoi(stempNumStr);#转换为整形 #或者 stempNum= ( num//(10**i) ) + (num%(10**i))*(10**(lens-i)) if(isPrime(stempNum)==False):#再判断位移后的这个数是否是素数,如果不是 flag=False;#则直接判定当前用户输入的数字不是循环素数 print('%s not Loop prime number'%num); break;#并中止后续计算,退出循环 if(flag==True):#如果Flag的值依然为True,说明这个数一定是循环素数 print('%s is Loop prime number'%num);
실행 결과는 다음과 같습니다.
위 내용은 양의 정수가 소수인지 여부를 결정하는 Python 프로그래밍 샘플 코드 공유의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

Pythonusesahybridmodelofilationandlostretation : 1) ThePyThoninterPretreCeterCompileSsourcodeIntOplatform-IndependentBecode.

Pythonisbothingretedandcompiled.1) 1) it 'scompiledtobytecodeforportabilityacrossplatforms.2) thebytecodeisthentenningreted, withfordiNamictyTeNgreted, WhithItmayBowerShiledlanguges.

forloopsareusedwhendumberofitessiskNowninadvance, whilewhiloopsareusedwhentheationsdepernationsorarrays.2) whiloopsureatableforscenarioScontiLaspecOndCond

pythonisnotpurelynlogreted; itusesahybrideprophorfbyodecodecompilationandruntime -INGRETATION.1) pythoncompilessourcecodeintobytecode, thepythonVirtualMachine (pvm)

ToconcatenatelistsinpythonwithesameElements, 사용 : 1) OperatorTokeEpduplicates, 2) asettoremovedUplicates, or3) listComperensionForControlOverDuplicates, 각 methodHasDifferentPerferformanCeanDorderImpestications.

PythonisancerpretedLanguage, 비판적 요소를 제시하는 PytherfaceLockelimitationsIncriticalApplications.1) 해석 된 언어와 같은 thePeedBackandbackandrapidProtoTyping.2) CompilledlanguagesLikec/C transformt 해석

useforloopswhhenmerfiterationsiskNownInAdvance 및 WhileLoopSweHeniTesslationsDepoyConditionismet whilEroopsSuitsCenarioswhereTheLoopScenarioswhereTheLoopScenarioswhereTheLoopScenarioswhereTherInatismet, 유용한 광고 인 푸트 gorit


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

WebStorm Mac 버전
유용한 JavaScript 개발 도구

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

mPDF
mPDF는 UTF-8로 인코딩된 HTML에서 PDF 파일을 생성할 수 있는 PHP 라이브러리입니다. 원저자인 Ian Back은 자신의 웹 사이트에서 "즉시" PDF 파일을 출력하고 다양한 언어를 처리하기 위해 mPDF를 작성했습니다. HTML2FPDF와 같은 원본 스크립트보다 유니코드 글꼴을 사용할 때 속도가 느리고 더 큰 파일을 생성하지만 CSS 스타일 등을 지원하고 많은 개선 사항이 있습니다. RTL(아랍어, 히브리어), CJK(중국어, 일본어, 한국어)를 포함한 거의 모든 언어를 지원합니다. 중첩된 블록 수준 요소(예: P, DIV)를 지원합니다.

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구