재귀호출
1. 함수에서 재귀호출 사용하기 def hello(): print('Hello, world!') hello() hello() Hello, world! Hello, world! Hello, world! ...(생략) Traceback (most recent call last): File "C:\project\recursive_function_error.py", line 5, in hello() File "C:\project\recursive_function_error.py", line 3, in hello hello() File "C:\project\recursive_function_error.py", line 3, in hello hello() File "C:\project\recursive_functi..
2023. 11. 21.
두점 사이 거리구하기
import math class Point2D: def __init__(self, x, y): self.x = x self.y = y p1 = Point2D(x=30, y=20) # 점1 p2 = Point2D(x=60, y=50) # 점2 a = p2.x - p1.x # 선 a의 길이 b = p2.y - p1.y # 선 b의 길이 c = math.sqrt(math.pow(a, 2) + math.pow(b, 2)) print(c) # 42.42640687119285 import math class Point2D: def __init__(self, x=0, y=0): self.x = x self.y = y length = 0.0 p = [Point2D(), Point2D(), Point2D(), Point..
2023. 11. 17.
self
class AdvancedList(list): def replace(self, old, new): while old in self: self[self.index(old)] = new x = AdvancedList([1, 2, 3, 1, 2, 3, 1, 2, 3]) x.replace(1, 100) print(x)
2023. 11. 17.