1. μ΄λ¦μ μΈμλ‘ λ°μ λ€μκ³Ό κ°μ΄ μΈμΏλ§μ μΆλ ₯νλ ν¨μλ₯Ό μμ±νμμ€.
νκΈΈλλ μλ
νμΈμ!
-> λ΅ :
name = input("name : ")
print(f"{name}λ μλ
νμΈμ!")
2. λ€μ μ½λλ₯Ό μ€ννμ λμ μΆλ ₯ κ²°κ³Όλ₯Ό μμ±νμμ€.
def f(x):
y = x
x = 7
return y * x
x = 4
print(f(3))
print(x)
-> λ΅ : 21, 4
3. f(3)μμμ xμ yμ κ°μ΄ 무μμΈμ§ μμ±νμμ€.
-> λ΅ : xκ° : 7, yκ°: 3
4. μ§μλ³μμ μ μλ³μ κ°κ° νλμ© μ¬μ©νμ¬ λ€μκ³Ό κ°μ΄ μΆλ ₯νμμ€.
Value : 10
Value : 20
-> λ΅ :
def pValue(Value):
print("Value :", Value)
pValue(10)
Value = 20
print("Value :", Value)
5. λ€μ μ½λμ μΆλ ₯ κ²°κ³Όλ₯Ό μμ±νμμ€.
a = 111
b = 222
def function_1():
print(a)
print(b)
def function_2():
a = 333
print(a)
print(b)
function_1()
function_2()
-> λ΅ : 111
222
333
222
6. λ€μ 쑰건μ λ§μΆ° μμ΄μ»¨ 리λͺ¨μ½ νλ‘κ·Έλ¨μ λ§λλ €κ³ νλ€.
a. μ¬μ©μμκ² μ¨λλ₯Ό 18 ~ 28μ μ«μλ‘ μ λ ₯λ°μ μμ΄μ»¨ μ¨λλ₯Ό μ€μ νκ³ ,
b. λͺ©ν μ¨λκ° μ€μ λλ©΄ ν¨μλ₯Ό μ΄μ©ν΄ νμ¬ μ¨λμμ λͺ©ν μ¨λκΉμ§ 1μ© μ¦κ°, κ°μνμ¬ λͺ©ν μ¨λκ° λλλ‘ νλ€.
c. 'μ’ λ£'λ₯Ό μ λ ₯λ°μΌλ©΄ νλ‘κ·Έλ¨μ μ’ λ£νλ€.
d. νλ‘κ·Έλ¨μ μ’ λ£νκΈ° μ κΉμ§λ κ³μ μ¨λλ₯Ό μ λ ₯λ°μ μ μμ΄μΌ νλ€.
e. μμ μ¨λλ 21λμ΄λ€.
cur_tem : νμ¬ μ¨λ
des_tem : λͺ©ν μ¨λ
put_tem : μ λ ₯λ°μ μ¨λ
set_tem : μ¨λλ₯Ό μ€μ νλ ν¨μ
cur_tem = 21 # νμ¬ μ¨λ
def set_tem
...
print("μμ΄μ»¨ μλμ μμν©λλ€.")
while True:
put_tem = input("μ¨λ μ€μ νκΈ° : ")
if ( (1) ): # μ’
λ£λ₯Ό μ
λ ₯λ°μΌλ©΄ μ’
λ£
print("μλμ μ€μ§ν©λλ€.")
break
elif( (2) ): # μ μ ν μ¨λ κ°μ μ
λ ₯λ°μΌλ©΄ set_tem ν¨μ νΈμΆ
( (3) ) # νμ¬ μ¨λ μ리기
( (4) ) # μ¨λλ₯Ό μ€μ νλ ν¨μ νΈμΆνκΈ°
else:
print("μ
λ ₯μ νμΈν΄μ£ΌμΈμ")
whileλ¬Έκ³Ό ifλ¬Έμ μ¬μ©νμ¬ μ¬μ©μμκ² μ¨λλ₯Ό 18 ~ 28 μ¬μ΄μ μ«μλ‘ μ λ ₯ λ°λ μ½λλ₯Ό μμ±νκΈ° μν΄ λ€μ κ΄νΈλ₯Ό μ±μ°μμ€.
-> λ΅ :
(1) : put_tem == "μ’ λ£"
(2) : (int(put_tem) > 18) and (int(put_tem) < 28)
(3) : print(f"νμ¬ μ¨λλ {cur_tem}λ μ λλ€.")
(4) : set_tem(int(put_tem)
7. μ¨λλ₯Ό μ€μ νλ ν¨μ set_tem ν¨μλ₯Ό μ μνλ μ½λλ₯Ό μμ±νκΈ° μν΄ λ€μ κ΄νΈλ₯Ό μ±μ°μμ€.
cur_tem = 21 # νμ¬ μ¨λ
def set_tem( (a) ): # μ¨λ μ€μ ν¨μ
( (b) ) # νμ¬ μ¨λ λ°μμ€κΈ°
...
print("μμ΄μ»¨ μλμ μμν©λλ€.")
while True:
put_tem = input("μ¨λ μ€μ νκΈ° : ")
if ( (1) ): # μ’
λ£λ₯Ό μ
λ ₯λ°μΌλ©΄ μ’
λ£
print("μλμ μ€μ§ν©λλ€.")
break
elif( (2) ): # μ μ ν μ¨λ κ°μ μ
λ ₯λ°μΌλ©΄ set_tem ν¨μ νΈμΆ
( (3) ) # νμ¬ μ¨λ μ리기
( (4) ) # μ¨λλ₯Ό μ€μ νλ ν¨μ νΈμΆνκΈ°
else:
print("μ
λ ₯μ νμΈν΄μ£ΌμΈμ")
-> λ΅ :
(a) : des_tem
(b) : global cur_tem
8. set_tem ν¨μμ λͺ λ Ήλ¬Έμ μμ±νκ³ μ νλ€. κ΄νΈλ₯Ό μ±μ μ½λλ₯Ό μμ±νμμ€.
cur_tem = 21 # νμ¬ μ¨λ
def set_tem( (a) ): # μ¨λ μ€μ ν¨μ
( (b) ) # νμ¬ μ¨λ λ°μμ€κΈ°
if cur_tem < des_tem :
while(cur_tem < des_tem):
( (γ±) )
print(f"νμ¬ μ¨λ : {cur_tem}λ")
else:
while(cur_tem > des_tem):
( (γ΄) )
print(f"νμ¬ μ¨λ : {cur_tem}λ")
print("μμ΄μ»¨ μλμ μμν©λλ€.")
while True:
put_tem = input("μ¨λ μ€μ νκΈ° : ")
if ( (1) ): # μ’
λ£λ₯Ό μ
λ ₯λ°μΌλ©΄ μ’
λ£
print("μλμ μ€μ§ν©λλ€.")
break
elif( (2) ): # μ μ ν μ¨λ κ°μ μ
λ ₯λ°μΌλ©΄ set_tem ν¨μ νΈμΆ
( (3) ) # νμ¬ μ¨λ μ리기
( (4) ) # μ¨λλ₯Ό μ€μ νλ ν¨μ νΈμΆνκΈ°
else:
print("μ
λ ₯μ νμΈν΄μ£ΌμΈμ")
-> λ΅ :
(γ±) : cur_tem += 1
(γ΄) : cur_tem -= 1
9. λ κ°μ μ μλ₯Ό μ λ ₯ λ°μμ λ§μ , λΊμ , κ³±μ , λλμ μ νλ κ³μ°κΈ° ν¨μλ₯Ό λ§λ€μ΄ λ€μκ³Ό κ°μ΄ μΆλ ₯νμμ€.
κ³μ°μ μ
λ ₯νμΈμ (+, -, *, / μ€ νλ): -
첫 λ²μ§Έ μλ₯Ό μ
λ ₯νμΈμ : 45
λ λ²μ§Έ μλ₯Ό μ
λ ₯νμΈμ : 12
κ³μ° κ²°κ³Ό: 33
-> λ΅ :
def cal():
mode = input("κ³μ°μ μ
λ ₯νμΈμ (+, -, *, / μ€ νλ): ")
a = int(input("첫 λ²μ§Έ μλ₯Ό μ
λ ₯νμΈμ :"))
b = int(input("λ λ²μ§Έ μλ₯Ό μ
λ ₯νμΈμ :"))
if mode == "+":
result = a + b
elif mode == "-":
result = a - b
elif mode == "*":
result = a * b
elif mode == "/":
result = a / b
else:
print("μ¬λ°λ₯Έ κΈ°νΈλ₯Ό μ νν΄μ£ΌμΈμ")
return result
print(cal())
'π μ€ν°λ > νμ΄μ¬ μ€ν°λ κ³Όμ μ μΆ' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[1ν/κΉμν]6μ°¨μ νμ΄μ¬ κ³Όμ - λ¬Έμμ΄ (0) | 2023.05.09 |
---|---|
[4ν/κΉμ€] 6μ°¨μ νμ΄μ¬ κ³Όμ - λ¬Έμμ΄ (0) | 2023.05.09 |
[2ν/μ€μν] 6μ°¨μ νμ΄μ¬ κ³Όμ - λ¬Έμμ΄ (0) | 2023.05.07 |
[4ν / κΉμ κ²½] 5μ°¨μ νμ΄μ¬ κ³Όμ - ν¨μν (0) | 2023.04.13 |
[3ν / κΉμμ] 5μ°¨μ νμ΄μ¬ κ³Όμ - ν¨μν (0) | 2023.04.12 |