MapleStory Finger Point

πŸ’Ž Python/πŸ“šνŒŒμ΄μ¬ for Beginner (2판)

ch 9 μ—°μŠ΅λ¬Έμ œ 풀이 - 파이썬 for Beginner (2판)

HYEJU01 2024. 3. 30. 04:00

1. λ§žλŠ” 것을 κ³ λ₯΄μ‹œμ˜€.

1번, 2번, 3번

4번 => ν•¨μˆ˜λŠ” μ—¬λŸ¬λ²ˆ ν˜ΈμΆœν•΄μ„œ μ‚¬μš©ν•˜λŠ” 것이 νš¨μœ¨μ μ΄λ‹€.

 

2. λΉˆμΉΈμ„ μ±„μš°μ‹œμ˜€

 def , return

def sum (v1,v2):
	result =0;
    result = v1,v2
    return result

 

3. 2번 ν•¨μˆ˜ 호좜 λ°©λ²•μœΌλ‘œ μ˜¬λ°”λ₯Έ 것은?

4번 hap  = sum(10,20)

 

4. ν•¨μˆ˜ λ°˜ν™˜κ°’κ³Ό κ΄€λ ¨λœ λ‚΄μš© 쀑 ν‹€λ¦° 것은?

4번 λ°˜ν™˜κ°’μ΄ μ—†λ‹€λ©΄ return 문은 쓰지 μ•Šμ•„λ„ λœλ‹€.

 

5. λ§€κ°œλ³€μˆ˜ 숫자 상관없이 λͺ¨λ“  λ§€κ°œλ³€μˆ˜λ₯Ό κ³±ν•˜λŠ” ν•¨μˆ˜ , λΉˆμΉΈμ„ μ±„μš°μ‹œμ˜€

def multiply *var:
	result = 1
    for num in var
    	result = result *num
        
    return result

 

 

6. 좜λ ₯λ˜λŠ” 값을 μ°¨λ‘€λŒ€λ‘œ μ μœΌμ‹œμ˜€

a = 222

def func1():
	print(a)
    
def func2():
	a=111
    print(a)

func1()
func2()

222

111

(1은 μ „μ—­λ³€μˆ˜ 222λ₯Ό 좜λ ₯ν•˜κ³  2λŠ” μ§€μ—­λ³€μˆ˜ μš°μ„  111 좜λ ₯)

 

 

7. 였λ₯˜κ°€ λ°œμƒν•˜λŠ” 것을 κ³ λ₯΄μ‹œμ˜€

v1은 μ΄ˆκΈ°ν™”κ°€λ˜μ§€ μ•Šμ•˜κΈ° λ•Œλ¬Έμ—

ν˜ΈμΆœμ‹œ func () < λ§€κ°œλ³€μˆ˜λ₯Ό λΉ„μ›Œλ‘λ©΄ μ•ˆλœλ‹€.

 

8. 였λ₯˜ λ°œμƒ μ½”λ“œλ₯Ό κ³ λ₯΄μ‹œμ˜€ 

1번 import myFunc.py (.py μ§€μ›Œμ•Όν•¨)

3번 from myFunc import fun1()  (κ΄„ν˜Έ μ§€μ›Œμ•Όν•¨)

 

9. λ‹€μŒ μ½”λ“œκ²°κ³Ό μ˜ˆμΈ‘ν•˜μ‹œμ˜€

def myRange(start,end,hop = 1) :
    retVal =start
    while retVal <= end:
    yield retVal
    retVal += hop
    
hap = 0
for i in myRange(1,5,2) :
	hap += i
print(hap)

yield λ°˜ν™˜ 이후에도 retVal += hop ꡬ문이 계속 λŒμ•„κ°€κΈ°λ•Œλ¬Έ.

1,3,5 κ°€  i 둜 λ„˜μ–΄μ˜€λ©΄μ„œ 값은 9κ°€ λœλ‹€.