Skip to content

30 Days Of Python: Day 3 - Operators

Twitter Follow Author: Asabeneh Yetayeh
Second Edition: July, 2021

<< Day 2 | Day 4 >>

30DaysOfPython

๐Ÿ“˜ 3์ผ์ฐจ

๋ถˆ๋ฆฌ์–ธ

๋ถˆ๋ฆฌ์–ธ ๋ฐ์ดํ„ฐ ํƒ€์ž…์€ True ๋˜๋Š” False ๋‘ ๊ฐ’ ์ค‘ ํ•˜๋‚˜๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค. ๋น„๊ต ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ด ๋ฐ์ดํ„ฐ ํƒ€์ž…์˜ ์‚ฌ์šฉ์ด ๋ช…ํ™•ํ•ด์งˆ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ฒซ ๋ฒˆ์งธ ๋ฌธ์ž T ๋Š” ์ฐธ, F ๋Š” ๊ฑฐ์ง“์œผ๋กœ ํ‘œํ˜„๋˜๋Š” ์ž๋ฐ” ์Šคํฌ๋ฆฝํŠธ์™€ ๋‹ฌ๋ฆฌ ๋Œ€๋ฌธ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ์‹œ: ๋ถˆ๋ฆฌ์–ธ ๊ฐ’

print(True)
print(False)

์—ฐ์‚ฐ์ž

ํŒŒ์ด์ฌ์€ ๋ช‡ ๊ฐ€์ง€ ํƒ€์ž…์˜ ์—ฐ์‚ฐ์ž๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. ์ด ์„น์…˜์—์„œ ์ด๊ฒƒ์— ๋Œ€ํ•ด ์•Œ์•„๋ณผ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๋Œ€์ž… ์—ฐ์‚ฐ์ž

๋Œ€์ž… ์—ฐ์‚ฐ์ž๋Š” ๋ณ€์ˆ˜์— ๊ฐ’์„ ๋Œ€์ž…ํ•  ๋•Œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. = ๋กœ ์˜ˆ์‹œ๋ฅผ ๋“ค์–ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ˆ˜ํ•™์—์„œ ๋“ฑํ˜ธ๋ž€ ๋‘ ๊ฐ’์ด ๋™์ผํ•˜๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•˜์ง€๋งŒ, ํŒŒ์ด์ฌ์—์„œ๋Š” ํŠน์ • ๋ณ€์ˆ˜๊ฐ€ ๊ฐ’์„ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉฐ, ์ด ๋ณ€์ˆ˜์— ๊ฐ’์„ ๋Œ€์ž…ํ•œ๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ํ‘œ๋Š” w3school์—์„œ ๊ฐ€์ ธ์˜จ ๋‹ค์–‘ํ•œ ์œ ํ˜•์˜ ํŒŒ์ด์ฌ ํ• ๋‹น ์—ฐ์‚ฐ์ž๋ฅผ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

๋Œ€์ž… ์—ฐ์‚ฐ์ž

์‚ฐ์ˆ  ์—ฐ์‚ฐ์ž:

  • ๋”ํ•˜๊ธฐ(+): a + b
  • ๋นผ๊ธฐ(-): a - b
  • ๊ณฑํ•˜๊ธฐ(*): a * b
  • ๋‚˜๋ˆ„๊ธฐ(/): a / b
  • ๋‚˜๋จธ์ง€ ์—ฐ์‚ฐ(%): a % b
  • ๋ฒ„๋ฆผ ๋‚˜๋ˆ—์…ˆ(//): a // b
  • ์ง€์ˆ˜(**): a ** b

์‚ฐ์ˆ  ์—ฐ์‚ฐ์ž

์˜ˆ์‹œ: Integers

# Arithmetic Operations in Python
# Integers

print('Addition: ', 1 + 2)        # 3
print('Subtraction: ', 2 - 1)     # 1
print('Multiplication: ', 2 * 3)  # 6
print ('Division: ', 4 / 2)       # 2.0  ํŒŒ์ด์ฌ์˜ ๋‚˜๋ˆ„๊ธฐ๋Š” ๋ถ€๋™ ์†Œ์ˆ˜๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
print('Division: ', 6 / 2)        # 3.0         
print('Division: ', 7 / 2)        # 3.5
print('Division without the remainder: ', 7 // 2)   # 3, ๋ถ€๋™ ์†Œ์ˆ˜ ๋˜๋Š” ๋‚˜๋จธ์ง€๊ฐ€ ์—†๋Š” ๊ฐ’์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
print ('Division without the remainder: ',7 // 3)   # 2
print('Modulus: ', 3 % 2)         # 1, ๋‚˜๋จธ์ง€๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
print('Exponentiation: ', 2 ** 3) # 9  2 * 2 * 2 ๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์‹œ: Floats

# Floating numbers
print('Floating Point Number, PI', 3.14)
print('Floating Point Number, gravity', 9.81)

์˜ˆ์‹œ: ๋ณต์†Œ์ˆ˜

# Complex numbers
print('Complex number: ', 1 + 1j)
print('Multiplying complex numbers: ',(1 + 1j) * (1 - 1j))

๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  ์ˆซ์ž ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ๋Š” ๋‹จ์ผ ๋ฌธ์ž ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•  ๊ฒƒ์ด์ง€๋งŒ, ์ด๋Ÿฐ ์œ ํ˜•์˜ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๋Š” ์Šต๊ด€์€ ์ข‹์ง€ ์•Š๋‹ค๋Š” ๊ฒƒ์„ ๊ธฐ์–ตํ•˜์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋ณ€์ˆ˜ ์ด๋ฆ„์€ ํ•ญ์ƒ ๊ธฐ์–ตํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Example:

# ์ฒซ ๋ฒˆ์งธ๋กœ ๋ณ€์ˆ˜๋ฅผ ๋จผ์ € ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค.

a = 3 # a๋Š” ๋ณ€์ˆ˜์˜ ์ด๋ฆ„์ด๋ฉฐ ์ •์ˆ˜ ๋ฐ์ดํ„ฐ ํƒ€์ž…์ž…๋‹ˆ๋‹ค.
b = 2 # b๋Š” ๋ณ€์ˆ˜์˜ ์ด๋ฆ„์ด๋ฉฐ ์ •์ˆ˜ ๋ฐ์ดํ„ฐ ํƒ€์ž…์ž…๋‹ˆ๋‹ค.

# ์‚ฐ์ˆ  ์—ฐ์‚ฐ ๋ฐ ๊ฒฐ๊ณผ๋ฅผ ๋ณ€์ˆ˜์— ๋Œ€์ž…ํ•ฉ๋‹ˆ๋‹ค.
total = a + b
diff = a - b
product = a * b
division = a / b
remainder = a % b
floor_division = a // b
exponential = a ** b

# sum ๋Œ€์‹  total์„ ์‚ฌ์šฉํ–ˆ์–ด์•ผ ํ•˜์ง€๋งŒ sum์€ ๋‚ด์žฅ ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค. ๋‚ด์žฅ ํ•จ์ˆ˜๋ฅผ ์žฌ์ •์˜ํ•˜์ง€ ์•Š๋„๋ก ํ•˜์‹ญ์‹œ์˜ค.
print(total) # ๋งŒ์•ฝ ๋ช‡๋ช‡ ์ถœ๋ ฅ์— ๋ฌธ์ž์—ด๋กœ ํ‘œ์‹œ๋ฅผ ํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด, ์–ด๋””์„œ ๊ฒฐ๊ณผ๊ฐ€ ์˜ค๋Š”์ง€ ์•Œ์ง€ ๋ชปํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.
print('a + b = ', total)
print('a - b = ', diff)
print('a * b = ', product)
print('a / b = ', division)
print('a % b = ', remainder)
print('a // b = ', floor_division)
print('a ** b = ', exponentiation)

Example:

print('== Addition, Subtraction, Multiplication, Division, Modulus ==')

# ๊ฐ’์„ ์„ ์–ธํ•˜๊ณ  ํ•จ๊ป˜ ์ •๋ฆฌ
num_one = 3
num_two = 4

# ์‚ฐ์ˆ  ์—ฐ์‚ฐ
total = num_one + num_two
diff = num_two - num_one
product = num_one * num_two
div = num_two / num_one
remainder = num_two % num_one

# ๋ ˆ์ด๋ธ”๋กœ ๊ฐ’ ์ถœ๋ ฅ
print('total: ', total)
print('difference: ', diff)
print('product: ', product)
print('division: ', div)
print('remainder: ', remainder)

์ด์ œ ์  ์—ฐ๊ฒฐ์„ ์‹œ์ž‘ํ•˜๊ณ  ์ด๋ฏธ ์•Œ๊ณ  ์žˆ๋Š” ๊ณ„์‚ฐ ๋ฐฉ๋ฒ•(๋ฉด์ , ๋ถ€ํ”ผ, ๋ฐ€๋„, ๋ฌด๊ฒŒ, ๋‘˜๋ ˆ, ๊ฑฐ๋ฆฌ, ํž˜)์„ ์‚ฌ์šฉํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

Example:

# ์›์˜ ๋„“์ด ๊ณ„์‚ฐ
radius = 10                                 # ์›์˜ ๋ฐ˜์ง€๋ฆ„
area_of_circle = 3.14 * radius ** 2         # ๋‘ ๊ฐœ์˜ * ๊ธฐํ˜ธ๋Š” ์ง€์ˆ˜๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค
print('Area of a circle:', area_of_circle)

# ์ง์‚ฌ๊ฐํ˜•์˜ ๋„“์ด ๊ณ„์‚ฐ
length = 10
width = 20
area_of_rectangle = length * width
print('Area of rectangle:', area_of_rectangle)

# ๊ฐœ์ฒด์˜ ๋ฌด๊ฒŒ ๊ณ„์‚ฐ
mass = 75
gravity = 9.81
weight = mass * gravity
print(weight, 'N')                         # ๋ฌด๊ฒŒ์— ๋‹จ์œ„ ์ถ”๊ฐ€

# ์•ก์ฒด์˜ ๋ฐ€๋„ ๊ณ„์‚ฐ
mass = 75 # in Kg
volume = 0.075 # in cubic meter
density = mass / volume # 1000 Kg/m^3

๋น„๊ต ์—ฐ์‚ฐ์ž

ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ ์šฐ๋ฆฌ๋Š” ๋น„๊ต ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‘ ๊ฐ’์„ ๋น„๊ตํ•ฉ๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๋Š” ๊ฐ’์ด ๋‹ค๋ฅธ ๊ฐ’๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ ํ‘œ๋Š”w3shool์—์„œ ๊ฐ€์ ธ์˜จ ํŒŒ์ด์ฌ์˜ ๋น„๊ต ์—ฐ์‚ฐ์ž๋ฅผ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

Comparison Operators Example: ๋น„๊ต ์—ฐ์‚ฐ์ž

print(3 > 2)     # ์ฐธ, 3์ด 2๋ณด๋‹ค ํฌ๊ธฐ ๋•Œ๋ฌธ์—
print(3 >= 2)    # ์ฐธ, 3์ด 2๋ณด๋‹ค ํฌ๊ธฐ ๋•Œ๋ฌธ์—
print(3 < 2)     # ๊ฑฐ์ง“, 3์ด ๋” ํฌ๊ธฐ ๋•Œ๋ฌธ์—
print(2 < 3)     # ์ฐธ, 2๊ฐ€ 3๋ณด๋‹ค ์ž‘๊ธฐ ๋•Œ๋ฌธ์—
print(2 <= 3)    # ์ฐธ, 2๊ฐ€ 3๋ณด๋‹ค ์ž‘๊ธฐ ๋•Œ๋ฌธ์—
print(3 == 2)    # ๊ฑฐ์ง“, 3๊ณผ 2๋Š” ๊ฐ™์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์—
print(3 != 2)    # ์ฐธ, 3์€ 2์™€ ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์—
print(len('mango') == len('avocado'))  # ๊ฑฐ์ง“
print(len('mango') != len('avocado'))  # ์ฐธ
print(len('mango') < len('avocado'))   # ์ฐธ
print(len('milk') != len('meat'))      # ๊ฑฐ์ง“
print(len('milk') == len('meat'))      # ์ฐธ
print(len('tomato') == len('potato'))  # ์ฐธ
print(len('python') > len('dragon'))   # ๊ฑฐ์ง“


# ๋ฌด์–ธ๊ฐ€๋ฅผ ๋น„๊ตํ•˜๋ฉด ์ฐธ ๋˜๋Š” ๊ฑฐ์ง“์ด ๋ฉ๋‹ˆ๋‹ค.

print('True == True: ', True == True)
print('True == False: ', True == False)
print('False == False:', False == False)

์œ„์˜ ๋น„๊ต ์—ฐ์‚ฐ์ž ์™ธ์— ํŒŒ์ด์ฌ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค:

  • is: ๋‘ ๋ณ€์ˆ˜๊ฐ€ ๋™์ผํ•  ๊ฒฝ์šฐ ์ฐธ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.(x is y)
  • is not: ๋‘ ๋ณ€์ˆ˜๊ฐ€ ๋™์ผํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ ์ฐธ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.(x is not y)
  • in: ์ œ์‹œ๋œ ๋ชฉ๋ก์— ํŠน์ • ํ•ญ๋ชฉ์ด ํฌํ•จ๋œ ๊ฒฝ์šฐ ์ฐธ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.(x in y)
  • not in: ์ œ์‹œ๋œ ๋ชฉ๋ก์— ํŠน์ • ํ•ญ๋ชฉ์ด ์—†์œผ๋ฉด ์ฐธ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.(x in y)
print('1 is 1', 1 is 1)                   # ์ฐธ - ๋ฐ์ดํ„ฐ ๊ฐ’์ด ๋™์ผํ•˜๊ธฐ ๋•Œ๋ฌธ์—
print('1 is not 2', 1 is not 2)           # ์ฐธ - 1๊ณผ 2๋Š” ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์—
print('A in Asabeneh', 'A' in 'Asabeneh') # ์ฐธ - ๋ฌธ์ž์—ด์—์„œ A๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค
print('B in Asabeneh', 'B' in 'Asabeneh') # ๊ฑฐ์ง“ - ๋Œ€๋ฌธ์ž B๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค
print('coding' in 'coding for all') # ์ฐธ - coding์ด๋ผ๋Š” ๋‹จ์–ด๋ฅผ coding for all์ด ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์—
print('a in an:', 'a' in 'an')      # ์ฐธ
print('4 is 2 ** 2:', 4 is 2 ** 2)   # ์ฐธ

๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž

๋‹ค๋ฅธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์™€ ๋‹ฌ๋ฆฌ ํŒŒ์ด์ฌ์€ ๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž๋ฅผ ์œ„ํ•ด and, or, not ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์กฐ๊ฑด๋ฌธ์„ ๊ฒฐํ•ฉํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

Logical Operators

print(3 > 2 and 4 > 3) # ์ฐธ - ๋‘ ๊ฐœ์˜ ๋ฌธ์žฅ์ด ์ฐธ์ด๊ธฐ ๋•Œ๋ฌธ์— 
print(3 > 2 and 4 < 3) # ๊ฑฐ์ง“ - ๋‘ ๋ฒˆ์งธ ๋ฌธ์žฅ์ด ๊ฑฐ์ง“์ด๊ธฐ ๋•Œ๋ฌธ์—
print(3 < 2 and 4 < 3) # ๊ฑฐ์ง“ - ๋‘ ๊ฐ€์ง€ ๋ฌธ์žฅ ๋ชจ๋‘ ๊ฑฐ์ง“์ด๊ธฐ ๋•Œ๋ฌธ์—
print('True and True: ', True and True)
print(3 > 2 or 4 > 3)  # ์ฐธ - ๋‘ ๊ฐ€์ง€ ๋ฌธ์žฅ ๋ชจ๋‘ ์ฐธ์ด๊ธฐ ๋•Œ๋ฌธ์—
print(3 > 2 or 4 < 3)  # ์ฐธ - ๋‘ ๊ฐ€์ง€ ์ค‘ ํ•˜๋‚˜์˜ ๋ฌธ์žฅ์ด ์ฐธ์ด๊ธฐ ๋•Œ๋ฌธ์—
print(3 < 2 or 4 < 3)  # ๊ฑฐ์ง“ - ๋‘ ๊ฐ€์ง€ ๋ฌธ์žฅ ๋ชจ๋‘ ๊ฑฐ์ง“์ด๊ธฐ ๋•Œ๋ฌธ์—
print('True or False:', True or False)
print(not 3 > 2)     # ๊ฑฐ์ง“ - 3์ด 2๋ณด๋‹ค ํฐ ๊ฒƒ์€ ์ฐธ์ด๊ธฐ ๋•Œ๋ฌธ์—, ์ฐธ์ด ์•„๋‹ ๊ฒฝ์šฐ ๊ฑฐ์ง“์„ ์ค๋‹ˆ๋‹ค.
print(not True)      # ๊ฑฐ์ง“ - ๋ถ€์ •์œผ๋กœ ์ฐธ์—์„œ ๊ฑฐ์ง“์œผ๋กœ ๋ฐ”๋€๋‹ˆ๋‹ค.
print(not False)     # True
print(not not True)  # True
print(not not False) # False

๐ŸŒ• ๋‹น์‹ ์€ ๋ฌดํ•œํ•œ ์—๋„ˆ์ง€๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์š”. ์—ฌ๋Ÿฌ๋ถ„์€ ์ด์ œ ๋ง‰ 3์ผ์ฐจ ๋„์ „์„ ๋งˆ์ณค๊ณ  ์œ„๋Œ€ํ•จ์œผ๋กœ ๊ฐ€๋Š” ๊ธธ์— ์„ธ ๊ฑธ์Œ ์•ž์„œ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด์ œ ์—ฌ๋Ÿฌ๋ถ„์˜ ๋‡Œ์™€ ๊ทผ์œก์„ ์œ„ํ•œ ์šด๋™์„ ํ•˜์„ธ์š”.

๐Ÿ’ป 3์ผ์ฐจ ์‹ค์Šต

  1. ๋‚˜์ด๋ฅผ ์ •์ˆ˜ ๋ณ€์ˆ˜๋กœ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค.
  2. ์ž์‹ ์˜ ํ‚ค๋ฅผ ํ”Œ๋กœํŠธ ๋ณ€์ˆ˜๋กœ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค.
  3. ๋ณต์†Œ์ˆ˜๋ฅผ ์ €์žฅํ•˜๋Š” ๋ณ€์ˆ˜ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค.
  4. ์‚ผ๊ฐํ˜•์˜ ๋ฐ‘๋ฉด๊ณผ ๋†’์ด๋ฅผ ์ž…๋ ฅํ•˜๋„๋ก ์‚ฌ์šฉ์ž์—๊ฒŒ ์ง€์‹œํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  ์ด ์‚ผ๊ฐํ˜•์˜ ๋ฉด์ (๋ฉด์  = 0.5 x b x h)์„ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.
    Enter base: 20
    Enter height: 10
    The area of the triangle is 100
  1. ์‚ผ๊ฐํ˜•์˜ ์ธก๋ฉด a, ์ธก๋ฉด b, ์ธก๋ฉด c๋ฅผ ์ž…๋ ฅํ•˜๋ผ๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ํ‘œ์‹œํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. ์‚ผ๊ฐํ˜•์˜ ๋‘˜๋ ˆ(์ง€๋ฆ„ = a + b + c)๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.
Enter side a: 5
Enter side b: 4
Enter side c: 3
The perimeter of the triangle is 12
  1. ํ”„๋กฌํ”„ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ง์‚ฌ๊ฐํ˜•์˜ ๊ธธ์ด์™€ ๋„ˆ๋น„๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค. ๋ฉด์ (๋ฉด์  = ๊ธธ์ด x ํญ) ๋ฐ ๋‘˜๋ ˆ(๋ฉด์  = 2 x (๊ธธ์ด + ํญ)) ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.
  2. ํ”„๋กฌํ”„ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์›์˜ ๋ฐ˜์ง€๋ฆ„์„ ๊ตฌํ•ฉ๋‹ˆ๋‹ค. ๋ฉด์ (๋ฉด์  = ํ”ฝ์Šค r x r)๊ณผ ์›์ฃผ(c = 2 x ํ”ฝ์Šค r)๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ pi = 3.14์ž…๋‹ˆ๋‹ค.
  3. y = 2x-2์˜ ๊ธฐ์šธ๊ธฐ, x-์ œ๊ณฑ ๋ฐ y-์ œ๊ณฑ์„ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.
  4. ๊ธฐ์šธ๊ธฐ๋Š” (m = y2-y1/x2-x1)์ž…๋‹ˆ๋‹ค. ๊ธฐ์šธ๊ธฐ์™€ ์œ ํด๋ฆฌ๋“œ ๊ฑฐ๋ฆฌ ์ (2,2)๊ณผ ์ (6,10) ์‚ฌ์ด๋ฅผ ๊ตฌํ•ฉ๋‹ˆ๋‹ค.
  5. ๊ณผ์ œ 8๊ณผ 9์˜ ๊ธฐ์šธ๊ธฐ๋ฅผ ๋น„๊ตํ•ฉ๋‹ˆ๋‹ค.
  6. y ๊ฐ’(y = x^2 + 6x + 9)์„ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค. ๋‹ค๋ฅธ x ๊ฐ’์„ ์‚ฌ์šฉํ•˜๊ณ  y ๊ฐ’์ด 0์ด ๋˜๋Š” x ๊ฐ’์„ ๊ณ„์‚ฐํ•ด ๋ณด์‹ญ์‹œ์˜ค.
  7. 'python'๊ณผ 'dragon'์˜ ๊ธธ์ด๋ฅผ ์ฐพ์•„ ๊ฑฐ์ง“ ๋น„๊ต๋ฅผ ํ•ฉ๋‹ˆ๋‹ค.
  8. and ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ 'python'๊ณผ 'dragon' ๋ชจ๋‘์— 'on'์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
  9. ๋‚˜๋Š” ์ด ๊ฐ•์ขŒ๊ฐ€ ์ „๋ฌธ์šฉ์–ด๋กœ ๊ฐ€๋“ํ•˜์ง€ ์•Š๊ธฐ๋ฅผ ๋ฐ”๋ž๋‹ˆ๋‹ค. _in ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ jargon ์ด ๋ฌธ์žฅ์— ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
  10. dragon๊ณผ python ๋ชจ๋‘ 'On'์ด ์—†์Šต๋‹ˆ๋‹ค.
  11. python ํ…์ŠคํŠธ์˜ ๊ธธ์ด๋ฅผ ์ฐพ์•„์„œ ๊ฐ’์„ float๋กœ ๋ณ€ํ™˜ํ•˜๊ณ  ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
  12. ์ง์ˆ˜๋Š” 2๋กœ ๋‚˜๋ˆ„๊ณ  ๋‚˜๋จธ์ง€๋Š” 0์ž…๋‹ˆ๋‹ค. ํŒŒ์ด์ฌ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ˆซ์ž๊ฐ€ ์ง์ˆ˜์ธ์ง€ ์•„๋‹Œ์ง€ ์–ด๋–ป๊ฒŒ ํ™•์ธํ•˜๊ฒ ์Šต๋‹ˆ๊นŒ?
  13. 7 x 3์˜ ๋‚˜๋ˆ—์…ˆ ๋ฒ„๋ฆผ์ด 2.7์˜ int ๋ณ€ํ™˜๊ฐ’๊ณผ ๋™์ผํ•œ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
  14. '10'์˜ ์œ ํ˜•์ด 10์˜ ์œ ํ˜•๊ณผ ๋™์ผํ•œ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
  15. if int('9.8')์ด 10๊ณผ ๊ฐ™์€์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
  16. ์‚ฌ์šฉ์ž์—๊ฒŒ ์‹œ๊ฐ„ ๋ฐ ์‹œ๊ฐ„๋‹น ์š”๊ธˆ์„ ์ž…๋ ฅํ•˜๋„๋ก ์š”์ฒญํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. ๊ทธ ์‚ฌ๋žŒ์˜ ๊ธ‰์—ฌ๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๊นŒ?
Enter hours: 40
Enter rate per hour: 28
Your weekly earning is 1120
  1. ์‚ฌ์šฉ์ž์—๊ฒŒ ๋…„ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜๋„๋ก ์š”์ฒญํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. ์‚ฌ๋žŒ์ด ์‚ด ์ˆ˜ ์žˆ๋Š” ์‹œ๊ฐ„์„ ์ดˆ ๋‹จ์œ„๋กœ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค. ์‚ฌ๋žŒ์ด 100๋…„์„ ์‚ด ์ˆ˜ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ์‹œ๋‹ค.
Enter number of years you have lived: 100
You have lived for 3153600000 seconds.
  1. ๋‹ค์Œ์„ ํ‘œ์‹œํ•˜๋Š” ํŒŒ์ด์ฌ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.
1 1 1 1 1
2 1 2 4 8
3 1 3 9 27
4 1 4 16 64
5 1 5 25 125

๐ŸŽ‰ ์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค ! ๐ŸŽ‰

<< Day 2 | Day 4 >>