본문 바로가기
728x90
반응형
SMALL

programming375

python) Counting Loop Iterations in a 5-Second Interval. import time number = 0 target_tick = time.time() + 5 while time.time() < target_tick: number += 1 print(" 5초 동안 {} 반복하였습니다".format(number)) 1. **`import time`**: This line imports the `time` module, which provides various time-related functions. It's used here to work with time operations, such as getting the current time and performing time-based calculations. 2. **`number = 0`**: Initializes a.. 2024. 11. 15.
python) Circle Class with Encapsulation and Property Decorators. import math class Circle: def __init__(self, radius): self.__radius = radius def get_circumference(self): return 2 * math.pi * self.__radius def get_area(self): return self.__radius **2 * math.pi def get_radius(self): return self.__radius def set_radius(self, value): self.__radius = value @property def radius(self): return self.__radius @radius.setter def radius(self, value): if value 2024. 11. 14.
python) Exploring Python's Enumerate Function with Lists example_list = [1,2,3,4,5,6,7,8,9] print("simple print") print(example_list) print() print("enumerate") print(enumerate(example_list)) print() print("#list function pull out") print(list(enumerate(example_list))) print() print("loop syntax for combination") for i, value in enumerate(example_list): print("{} 요소는 {}입니다.".format(i, value)) ### Source Code Explanation for Each Line 1. `example_list .. 2024. 11. 13.
python) use to isinstance class Student: def Study(self): print("print out study") class Teacher: def Teach(self): print("teach to student") classroom = [Student(), Student(), Teacher(), Student(), Student()] [person.Study() if isinstance(person, Student) else person.Teach() for person in classroom] ### Class and Method Definitions 1. **`class Student:`** Defines a class named `Student`. 2. **`def Study(self):`** Inside .. 2024. 11. 12.
728x90
반응형
LIST