728x90 반응형 SMALL programming375 python) Memoization dictionary = {1 : 1, 2 : 1} def fibonacci(n): if n in dictionary: return dictionary[n] else: output = fibonacci(n-1) + fibonacci(n-2) dictionary[n] = output return output number = int(input()) print("fibonacci({}) : {} ".format(number , fibonacci(number))) ### Code Breakdown - **`dictionary = {1: 1, 2: 1}`**: Initializes a dictionary with the first two Fibonacci numbers. The keys are the positio.. 2024. 11. 3. python) Understanding Custom Exception Handling in Python class Custom(Exception): def __init__(self, message, value): super().__init__() self.message = message self.value = value def __str__(self): return self.message def print(self): print("warning Error") print("message : ", self.message) print("value : ", self.value) try: raise Custom("betzni eiina",273) except Custom as e: e.print() ### Understanding Custom Exception Handling in Python This code s.. 2024. 11. 2. python) custom exception class class Custom(Exception): def __init__(self): super().__init__() raise Custom In this simplified example, a custom exception class named `Custom` is defined, which inherits from Python's built-in `Exception` class. The `__init__` method of this class calls the initializer of the base `Exception` class using `super().__init__()`. This setup ensures that `Custom` behaves like a standard exception i.. 2024. 11. 1. python) Class Definitions and Inheritance class Parent: def __init__(self): self.value = "Test" print("Parent class __init()__ mathod is called") def test(self): print("Parent class of test() mathod") class Child(Parent): def __init__(self): super().__init__() print("Child class __init()__ mathod is called") child = Child() child.test() print(child.value) ### Class Definitions and Inheritance - **`class Parent:`** Defines a base (or par.. 2024. 10. 31. 이전 1 ··· 22 23 24 25 26 27 28 ··· 94 다음 728x90 반응형 LIST