# π₯ Nested If Statements

Min-Ho LeeΒ·2020λ 6μ 24μΌ
0

## Learn Python

9/22

Wednesday_June_24
.
.
.

# β Nested If Statements(μ€μ²© Ifλ¬Έ)

ifλ¬Έ μμ λ λ€λ₯Έ ifλ¬Έμ΄ μ‘΄μ¬νλ κ² μ΄λ€.

μ΄κ±Έ μ? μΈκΉ?

## π€­ μλ¬Έ

if status == "νμ" and year >= 3:
print("μ·¨μμ΄ κ³§ λ€κ°μ¨λ€!")
elif status == "νμ" and year == 2:
print("κ·Έλλ μμ§ λ μκ°μ΄ μλ€..")
elif status == "νμ" and year < 2:
print("νμ°½ λλμ§..")
else:
print("μ΄μ¬ν κ³΅λΆ ν΄μ λνκ΅ λΆν° κ°λΌ!")

μ΄ μ½λμμλ status == "νμ" μ΄λΌλ
μ‘°κ±΄μ΄ κ²ΉμΉκ² λλ€.

μ΄λ κ² λ°λ³΅λλ μ»¨λμμ΄ μμλλ nested if statemens μ¦ μ€μ²©λλ if κ΅¬λ¬Έμ μ¬μ©νλ©΄ κ°λμ±μ΄ ν¨μ¬ λμμ§κ³  μ½λλ κ°κ²°ν΄μ§λλ€.

if status == "νμ":
if year >= 3:
print("μ·¨μμ΄ κ³§ λ€κ°μ¨λ€")
elif year == 2:
print("κ·Έλλ μμ§ λ μκ°μ΄ μλ€..")
elif year < 2:
print("νμ°½ λλμ§..")
else:
print("μ΄μ¬ν κ³΅λΆ ν΄μ λνκ΅ λΆν° κ°λΌ!")

## π€― λ¬Έμ 

λ€μμ λ°©μ μμ ν΄κ²°νλ xμ κ°μ κ΅¬νλ νλ‘κ·Έλ¨ κ΅¬ννκΈ°.

ax = b

## π³ μ‘°κ±΄

1οΈβ£ Input μΌλ‘ μ£Όμ΄μ§ a μ b κ°μΌλ‘ μμ λ°©μ μμ μΆ©μ‘±νλ λ¨ νλμ μ μκ° μ‘΄μ¬νλ€λ©΄ ν΄λΉ μ μλ₯Ό μΆλ ₯

2οΈβ£ λ§μΌ a μ b κ°μΌλ‘ μμ λ°©μ μμ μΆ©μ‘±νλ μ μκ° μλ€λ©΄ "No Solution"μ μΆλ ₯ν΄μ£ΌμΈμ.

4οΈβ£ aλ bλ 0μ΄ λ  μ μλ€.

μλ₯Ό λ€μ΄

a = 1, b = -2
μΆλ ₯κ°μ -2

a = 2, b = -1
μΆλ ₯κ°μ "No Solution"

### π€¬ λμ νμ΄

if a == 0:
if b == 0:
print("Many Solutions")
else:
print("No Solution")
elif a != 0 and b == 0:
print(b // a)
elif a > 0:
if (b > 0 and (b % a) == 0) or (b < 0 and (-b % a) == 0):
print(b // a)
else:
print("No Solution")
elif a < 0:
if (b > 0 and (b % (-a)) == 0) or (b < 0 and (-b % (-a)) == 0):
print(b // a)
else:
print("No Solution")

if a == 0:
if b == 0:
print('Many Solutions')
else:
print('No Solution')
elif b % a == 0:
print(b // a)
else:
print('No Solution')

### βοΈ μκ°

μΌλ¨ μ€λλ§μ λ¨Έλ¦¬μ’ κ΅΄λ Έλ€.
μμ½λ κ΅Ώμ¦μΈ λΈνΈμ νμ κΊΌλ΄λ©° λΉμ¨ λλ κΈ°λ¦μΉ μ ν΄μ£Όμλ€.
.
μ¬μ€ λ΄κ° μ§  μ½λκ° μλ μ κ²λ³΄λ€ 2λ°°λ λ κΈΈμλλ°,
μ λ§νΌ μ€μ¬μ μλ§μ μ°λ€μ΄ μμλ€. λ¬Όλ‘  λ©ν λμ μ½λκ° λ°μ±νκ² ν΄μ£Όμλ€.
.
μΌλ¨ λ΄κ° μ΄ λ¬Έμ λ₯Ό κ°μ§κ³  2μκ°? 3μκ°? μ μ½μ§ ν  μ€ λͺ°λλ€.
.
μλ§νμ§ μκ³  κ²Έμνκ² μ΄μμΌ νλλ° λ€μ νλ² λ°μ± μ€μ΄λ€ ππ»ββοΈ
.
λ λ€λ₯΄κ² λλμ μ, μμ° λ©ν λκ»μ λ§μν΄μ£Όμ
β° μ λμ μΈ μκ° ν¬μ = β μ½μ§
νλ€μμ§λ§ μ€λλ μ¦κ²Όκ³  μ¬λ°μλ€.

π Rabbit can take a rest, but π’ turtle can't