찾다
백엔드 개발파이썬 튜토리얼Python Day- 반복-연습 및 작업

Python Day- Looping-Exercises and tasks

소수:
1과 자기 자신으로 나누어 떨어지는 수를 소수라고 합니다.(예-->3,5,7)

1) 소수 찾기 여부:

no = int(input("Enter no. "))
div = 2
while div<no: if no print prime break div else:>



<p>출력:<br>
</p>

<pre class="brush:php;toolbar:false">1)Enter no. 5
  Prime
2)Enter no. 6
  Not Prime

2) 입력 숫자를 뒤집어서 그 숫자가 소수인지 아닌지 알아보세요:

def reverse_a_no(no):
    reverse = 0
    while no>0:
        rem = no%10
        reverse = (reverse*10) + rem
        no//=10 #no=no//10
    return reverse

no = int(input("Enter no. ")) 
reversed_no = reverse_a_no(no) #31 71
print(reversed_no)
def find_prime(no):
    div = 2
    while div<no: if no return false break div else: true result1="find_prime(no)" result2="find_prime(reversed_no)" result2: print number emirp>



<p>출력:<br>
</p>

<pre class="brush:php;toolbar:false">1)Enter no. 15
  51
  EMIRP number
2)Enter no. 14
  41
  not EMIRP number

완수
완전수는 나누어지는 숫자의 합이 그 숫자와 같다는 것을 의미합니다.(예: 6은 1,2,3으로 나누어지고 1 2 3=6)

def find_perfect(no):
    total = 0
    div = 1
    while div<no: if no total="total" div else: no: return true false no. result="find_perfect(no)" true: print number perfect>



<p>출력:<br>
</p>

<pre class="brush:php;toolbar:false">Enter no. 6
Perfect Number

제곱근:

입력 숫자의 제곱과 해당 제곱근 숫자의 합을 구합니다.

def square(no):
    return no**2

no=int(input("Enter the number:"))
result=square(no)

def sum_of_digits(num):
        sum=0
        while num>0:
            sum=sum+num%10
            num=num//10
        return sum

if result



<p>출력:<br>
</p>

<pre class="brush:php;toolbar:false">Enter the number:4
7

위의 예에서 주어진 입력 번호는 4입니다.
-->4의 제곱근은 4x4=16
-->그 제곱수의 자릿수 합 1 6=7.

작업 -1 **
**자동형태수

숫자의 사각형이 같은 숫자로 끝나는지 확인하세요.
예: 5 → 자동형(5²=25), 6 → 자동형(6²=36), 7 → 자동형 아님

def square(no):
    return no**2

no=int(input("Enter the number:"))
result=square(no)
print(result)

while result>0:
    rem=result%10
    if rem==no:
        print("Automorphic number")
        break
    else:
        print("Not Automorphic number")
        break

출력:

1)Enter the number:5
  25
  Automorphic number
2)Enter the number:4
  16
  Not Automorphic number

작업:2
피보나치 수열

주어진 숫자까지 피보나치 수열을 생성합니다.
예: 입력: 10 → 출력: 0, 1, 1, 2, 3, 5, 8.

no = int(input("Enter the number of required sequence: "))

first_num,sec_num =0 ,1

while first_num 



<p>출력:<br>
</p>

<pre class="brush:php;toolbar:false">Enter the number of required sequence: 10
0 1 1 2 3 5 8 

위 내용은 Python Day- 반복-연습 및 작업의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
파이썬 목록을 어떻게 슬라이스합니까?파이썬 목록을 어떻게 슬라이스합니까?May 02, 2025 am 12:14 AM

slicepaythonlistisdoneusingthesyntaxlist [start : step : step] .here'showitworks : 1) startistheindexofthefirstelementtoinclude.2) stopistheindexofthefirstelemement.3) stepisincrementbetwetweentractionsoftortionsoflists

Numpy Array에서 수행 할 수있는 일반적인 작업은 무엇입니까?Numpy Array에서 수행 할 수있는 일반적인 작업은 무엇입니까?May 02, 2025 am 12:09 AM

NumpyAllowsForVariousOperationsOnArrays : 1) BasicArithmeticLikeadDition, Subtraction, A 및 Division; 2) AdvancedOperationsSuchasmatrixmultiplication; 3) extrayintondsfordatamanipulation; 5) Ag

파이썬으로 데이터 분석에 어레이가 어떻게 사용됩니까?파이썬으로 데이터 분석에 어레이가 어떻게 사용됩니까?May 02, 2025 am 12:09 AM

Arraysinpython, 특히 Stroughnumpyandpandas, areestentialfordataanalysis, setingspeedandefficiency

목록의 메모리 풋 프린트는 파이썬 배열의 메모리 풋 프린트와 어떻게 비교됩니까?목록의 메모리 풋 프린트는 파이썬 배열의 메모리 풋 프린트와 어떻게 비교됩니까?May 02, 2025 am 12:08 AM

ListSandnumpyArraysInpythonHavedifferentmoryfootPrints : ListSaremoreFlexibleButlessMemory-Efficer, whilumpyArraySareOptimizedFornumericalData.1) ListSTorERENFERENCESTOOBJECTS, OverHeadAround64ByTeson64-BitSyStems.2) NumpyArraysTATACONTACOTIGUOU

실행 파이썬 스크립트를 배포 할 때 환경 별 구성을 어떻게 처리합니까?실행 파이썬 스크립트를 배포 할 때 환경 별 구성을 어떻게 처리합니까?May 02, 2025 am 12:07 AM

ToensurePythonScriptTscriptsBecorrectelyRossDevelopment, Staging and Production, UsethesEStrategies : 1) EnvironmberVariblesForsimplesettings, 2) ConfigurationFilesforcomplexSetups 및 3) DynamicLoadingForAdAptability

파이썬 어레이를 어떻게 슬라이스합니까?파이썬 어레이를 어떻게 슬라이스합니까?May 01, 2025 am 12:18 AM

Python List 슬라이싱의 기본 구문은 목록 [start : stop : step]입니다. 1. Start는 첫 번째 요소 인덱스, 2.Stop은 첫 번째 요소 인덱스가 제외되고 3. Step은 요소 사이의 단계 크기를 결정합니다. 슬라이스는 데이터를 추출하는 데 사용될뿐만 아니라 목록을 수정하고 반전시키는 데 사용됩니다.

어떤 상황에서 목록이 배열보다 더 잘 수행 될 수 있습니까?어떤 상황에서 목록이 배열보다 더 잘 수행 될 수 있습니까?May 01, 2025 am 12:06 AM

ListSoutPerformArraysin : 1) DynamicsizingandFrequentInsertions/Deletions, 2) StoringHeterogeneousData 및 3) MemoryEfficiencyForsParsEdata, butMayHavesLightPerformanceCosceperationOperations.

파이썬 어레이를 파이썬 목록으로 어떻게 변환 할 수 있습니까?파이썬 어레이를 파이썬 목록으로 어떻게 변환 할 수 있습니까?May 01, 2025 am 12:05 AM

TOCONVERTAPYTHONARRAYTOALIST, USETHELIST () CONSTUCTORORAGENERATERATOREXPRESSION.1) importTheArrayModuleAndCreateAnarray.2) USELIST (ARR) 또는 [XFORXINARR] TOCONVERTITTOALIST.

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

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

뜨거운 도구

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

mPDF

mPDF

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

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

SublimeText3 Mac 버전

SublimeText3 Mac 버전

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