πŸ“„ Python

9. λͺ¨λ“ˆ

sa1t 2022. 6. 9. 10:54
λ°˜μ‘ν˜•
# λͺ¨λ“ˆ
# λͺ¨λ“ˆ : ν•¨μˆ˜μ˜ 집합 vs νŒ¨ν‚€μ§€ : λ‹€μš΄λ°›μ•„μ„œ μ“°λŠ”κ±°

# ν‘œμ€€ λͺ¨λ“ˆ : νŒŒμ΄μ¬μ—μ„œ μ œκ³΅ν•˜λŠ” λͺ¨λ“ˆ
# μ‚¬μš©μž μ •μ˜ λͺ¨λ“ˆ : 직접 λ§Œλ“€μ–΄μ„œ μ‚¬μš©
# μ„œλ“œ νŒŒν‹° (3rd party) : 파이썬, μ‚¬μš©μžκ°€ μ•„λ‹Œ μ™ΈλΆ€ νšŒμ‚¬λ‚˜ λ‹¨μ²΄μ—μ„œ 제곡

# import sys
# print(sys.builtin_module_names)     # ν‘œμ€€ λͺ¨λ“ˆ 확인 λͺ…λ Ήμ–΄

import module
module.func1()
module.func2()
# λ‹¨μˆœ ν”„λ¦°νŠΈ ꡬ문

sum = module.plus(50,30)
print(sum)

sum2 = module.para_func(10,20)
print(sum2)

# ν•¨μˆ˜ λͺ…μœΌλ‘œλ§Œ 호좜
# from λͺ¨λ“ˆλͺ… import ν•¨μˆ˜λͺ…1, ν•¨μˆ˜λͺ…2 ...

from module import func1, func2, para_func, plus

func1()
func2()

# 파일(λͺ¨λ“ˆ)에 μžˆλŠ” λͺ¨λ“  ν•¨μˆ˜ λ‹€
# λ‘œλ“œλŸ‰ 증가, μ‚¬μš©ν•˜κΈ° νŽΈν•΄μ§

from module import *
func1()
func2()

# Quiz) model 파일 μƒˆλ‘œ λ§Œλ“€κΈ°
# 사칙연산, 둜또 번호, 닀이아λͺ¬λ“œ, ꡬꡬ단 좜λ ₯

from model import *
calc(11,23,'*')
lottonum()
dia(5)
dan2(66)
# 사칙 μ—°μ‚°
def calc(v1,v2,op) :
    result= 0   # ν˜Ήμ‹œ λͺ°λΌμ„œ
    if op=="+":
        result=v1+v2
        print("%d %s %d = %d" %(v1,op,v2,result))
    elif op=="-":
        result=v1-v2
        print("%d %s %d = %d" %(v1,op,v2,result))
    elif op=="*":
        result=v1*v2
        print("%d %s %d = %d" %(v1,op,v2,result))
    elif op=="/":
        result=v1/v2
        print("%d %s %d = %d" %(v1,op,v2,result))
    else:
        print("잘λͺ» μž…λ ₯ν•˜μ…¨μŠ΅λ‹ˆλ‹€.")
    return result



# 둜또 번호
def lottonum():
    import random

    def getNumber():
        return random.randrange(1, 46)

    lotto = []
    num = 0
    print("##### 둜또 번호 좔첨 ##### \n")

    while True:
        num = getNumber()
        if lotto.count(num) == 0:
            lotto.append(num)
        if len(lotto) >= 7:
            break

    print("좔첨 둜또 번호 : ", end='')

    ll6 = lotto[0:6]
    ll6.sort()
    print(ll6)

    print("좔첨 둜또 λ³΄λ„ˆμŠ€ 번호 : ", end='')
    print(lotto[6])

# 닀이아λͺ¬λ“œ
def dia(di):
    a = str("*")
    i = 0

    if di % 2 == 0:
        print(" 숫자λ₯Ό λ‹€μ‹œ μž…λ ₯ν•΄ μ£Όμ„Έμš” ")
    else:
        for i in range(0, di + 1, 2):
            print(("*" * (i + 1)).center(di))

        for i in range(di - 2, 0, -2):
            print(("*" * (i)).center(di))

# ꡬꡬ단 좜λ ₯ ν•¨μˆ˜
def dan2(dan):
    i = 0

    for i in range(1, 10):  # 증가 κ°’ μƒλž΅ν•˜λ©΄ 1이 λ””ν΄νŠΈ
        print("%d * %d = %d" % (dan, i, dan * i))
    print("끝")
λ°˜μ‘ν˜•