본문 바로가기

메뉴135

[Python] 기초 알고리즘 문제 풀이 [Python] 기초 알고리즘 문제 풀이초보자를 위한 기본적인 알고리즘 문제와 해결 방법을 Python 코드로 살펴보자. 순차 탐색기본 순차 탐색def sequential_search(arr, target): for i in range(len(arr)): if arr[i] == target: return i # 찾은 위치 반환 return -1 # 못 찾은 경우# 사용 예시numbers = [4, 2, 7, 1, 9, 3]result = sequential_search(numbers, 7)print(f"위치: {result}") # 위치: 2 문자열에서 문자 찾기def find_all_positions(text, char): positions = [].. 2024. 11. 27.
[Python] 모듈과 패키지 [Python] 모듈과 패키지import 문 이해기본 import 방법# 모듈 전체 가져오기import mathprint(math.pi) # 3.141592...# 특정 함수/변수만 가져오기from random import randintnumber = randint(1, 10)# 별칭 사용하기import pandas as pdimport numpy as np# 여러 항목 가져오기from datetime import datetime, timedelta 패키지 구조 이해my_package/ ├── __init__.py ├── module1.py └── module2.py# module1.py에서 module2 가져오기from .module2 import some_function # 상대 .. 2024. 11. 26.
[Python] if문과 조건문 [Python] if문과 조건문 조건문은 프로그래밍의 기본 구성 요소로, 프로그램의 흐름을 제어하는 핵심 요소다. Python의 조건문 사용법을 기초부터 심화까지 알아보자.  조건문 기초기본 if문 구조# 단순 if문temperature = 30if temperature > 28: print("에어컨을 켭니다")# if-else문age = 20if age >= 18: print("성인입니다")else: print("미성년자입니다")# 중첩 if문score = 85if score >= 60: print("합격입니다") if score >= 90: print("우수한 성적입니다") 비교 연산자# 다양한 비교 연산자 활용x = 10y = 20if x == y: # .. 2024. 11. 26.
[Python] for문과 while문 실전 활용 [Python] for문과 while문 실전 활용반복문은 프로그래밍의 기본 중의 기본이다. Python의 for문과 while문을 효과적으로 사용하는 방법을 알아보자.반복문 기초for문 기본 구조# 리스트 순회fruits = ['apple', 'banana', 'orange']for fruit in fruits: print(fruit)# 문자열 순회message = "Python"for char in message: print(char)# 인덱스와 함께 순회for index, fruit in enumerate(fruits): print(f"{index}번째 과일: {fruit}")while문 기본 구조# 기본 while문count = 0while count 0: print(numb.. 2024. 11. 23.