반응형

[백준] 2016번 제곱ㄴㄴ수 - PYTHON

import math

min, max = map(int, input().split())
 
NN = [1] * (max - min + 1) 

tmp_01 = []

for i in range(2, int(math.sqrt(max)) + 1):
    tmp_01.append(i ** 2)


for i in tmp_01:
    j = math.ceil(min / i)
    while i * j <= max:
        NN[i * j - min] = 0
        j += 1

print(sum(NN))
반응형
반응형

 

import sys
import math

A_size = int(sys.stdin.readline())
A = sys.stdin.readline().replace("\n", "").split(' ')
A = [int(i) for i in A]

# A를 오름차순으로 정렬하여 작은 숫자부터 순서대로 정리된 새로운 list를 할당 
sorted_A = [i for i in A]
sorted_A.sort()

P = []
# A의 각 숫자들에 대해 sorted_A에서의 index를 찾아 몇번째로 작은 숫자인지 P 수열에 새롭게 append함.
for i in A:
    P.append(sorted_A.index(i))
    # 이미 할당한 숫자는 sorted_A에서 -1로 대채해 재탐색되지 않도록 함.
    sorted_A[sorted_A.index(i)] = -1

results = [i for i in P]

for result in results:
    sys.stdout.write(str(result)+' ')
    
#  출처 : https://nerogarret.tistory.com/31
반응형
반응형

[PYTHON] 모듈 예제, 모듈 불러오기- 파이썬

 

mod1.py를 생성하고 다른 파일에서 모듈을 호출한다.

https://github.com/ngio/python_study/blob/main/module_py.py

 

GitHub - ngio/python_study: python, konply, numpy, matplotlib, networkx, pandas

python, konply, numpy, matplotlib, networkx, pandas - GitHub - ngio/python_study: python, konply, numpy, matplotlib, networkx, pandas

github.com

import mod1
print(" module name is ", mod1.__name__)

 

# mod1.py 
def add(a, b): 
    return a+b

def sub(a, b): 
    return a-b

# if __name__ == "__main__"을 사용하면 C:\doit>python mod1.py처럼 직접 이 파일을 실행했을 때는 __name__ == "__main__"이 참이 되어 
# if문 다음 문장이 수행된다. 
# 반대로 대화형 인터프리터나 다른 파일에서 이 모듈을 불러서 사용할 때는 __name__ == "__main__"이 거짓이 되어 
# if문 다음 문장이 수행되지 않는다.

if __name__ == "__main__":
    print(add(1, 4))
    print(sub(4, 2))
반응형
반응형

https://wikidocs.net/7040

 

241 ~ 250

.answer {margin-top: 10px;margin-bottom: 50px;padding-top: 10px;border-top: 3px solid LightGray;bo…

wikidocs.net

248 os 모듈

os 모듈의 getcwd 함수를 호출하여 현재 디렉터리의 경로를 화면에 출력해보세요.

정답확인
import os
ret = os.getcwd()
print(ret, type(ret))

249 rename 함수

바탕화면에 텍스트 파일을 하나 생성한 후 os 모듈의 rename 함수를 호출하여 해당 파일의 이름을 변경해보세요.

정답확인
import os
os.rename("C:/Users/hyunh/Desktop/before.txt", "C:/Users/hyunh/Desktop/after.txt")

250 numpy

numpy 모듈의 arange 함수를 사용해서 0.0 부터 5.0까지 0.1씩 증가하는 값을 화면에 출력해보세요.

정답확인
import numpy
for i in numpy.arange(0, 5, 0.1):
    print(i)
 

 

반응형
반응형

파이썬 제어문 python control-flow

""" Python Control-Flow
    if
    if - else
    for
    while
    break
    continue
"""


print("----- if, if - else")
a = 33
b = 200
if b > a:
    print("b is greater than a")
elif a == b:
    print("a and b equal")
    
print("----- for")
fruits = [ "apple", "banana", "cherry"]    
for x in fruits:
    print(x)
    

print("----- while, break")    
i = 1
while i < 6:
    print(i)    
    if( i == 3 ):
        break
    i += 1

print("----- continue")
i = 0
while i < 6: 
    i += 1   
    if( i == 3 ):
        continue
    print(i)

반응형
반응형

google.colab 가져오기 파일에서 Jupyterlab에서 파일의 동일한 동작을 얻는 방법

 

현재 colab에서 잘 돌아가는 프로젝트를 진행하고 있는데 로컬 jupyterlab에서 수정하고 실행하고 싶지만 해당 프로젝트에는 colab과 같은 특정 기능이 있고 이런 방식으로 가져온 files기능  output있습니다 .from google.colab import filesfrom google.colab import output

 

 

pypi에서 찾았으니 기본적 으로 모듈을 로컬에 설치한 pip install google-colab다음 노트북에서 사용할 수 있습니다.

 

 

https://stackoverflow.com/questions/64103409/from-google-colab-import-files-how-to-get-the-same-behaviour-of-files-in-jupyte

반응형
반응형

Text2Art
AI Powered Text-to-Art Generator
Try It Out »
View Notebook · Read Article · Report Bug · Request Feature

 

https://colab.research.google.com/github/mfrashad/text2art/blob/main/text2art.ipynb

 

Copy of Text2Art

Run, share, and edit Python notebooks

colab.research.google.com

https://github.com/mfrashad/text2art

 

GitHub - mfrashad/text2art: AI-powered Text-to-Art Generator - Text2Art.com

AI-powered Text-to-Art Generator - Text2Art.com. Contribute to mfrashad/text2art development by creating an account on GitHub.

github.com

반응형
반응형

https://github.com/ngio/python_study/blob/main/true_false_quiz.py

 

GitHub - ngio/python_study: python, konply, numpy, matplotlib, networkx, pandas

python, konply, numpy, matplotlib, networkx, pandas - GitHub - ngio/python_study: python, konply, numpy, matplotlib, networkx, pandas

github.com

 

    What will be the output? 
    A.True
    B.False
    C.Error
    D.None of above 

"""_summary_
    What will be the output? 
    A.True
    B.False
    C.Error
    D.None of above
"""

a = True
b = False

print(a or a and b and a)

"""
    True
"""
반응형

+ Recent posts