본문 바로가기

728x90

python

[스크립트] 로또 번호 생성기 로또 번호 생성기 vim generate_lotto_numbers.py import random def generate_lotto_numbers(): numbers = [] while len(numbers) < 6: num = random.randint(1, 45) if num not in numbers: numbers.append(num) return sorted(numbers) def print_lotto_numbers(): count = input("로또 번호를 몇 개 출력하시겠습니까? (기본값: 3) ") count = int(count) if count.isdigit() else 3 for i in range(count): numbers = generate_lotto_numbers() print.. 더보기
[스크립트] python 예약어 python 예약어 키워드(keyword) import keyword keyword.kwlist >>> import keyword >>> keyword.kwlist ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'] 내장함수(built.. 더보기
[python] tcp 소켓 통신 python tcp 소켓 통신 code : https://github.com/madscheme/introducing-python tcp_server.py 작성 from datetime import datetime import socket address = ('localhost', 6789) max_size = 1000 print('Starting the server at', datetime.now()) print('Waiting for a client to call.') server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind(address) server.listen(5) client, addr = server.accept() data.. 더보기
[python] udp 소켓 통신 python udp 소켓 통신 code : https://github.com/madscheme/introducing-python udp_server.py 작성 from datetime import datetime import socket server_address = ('localhost', 6789) max_size = 4096 print('Starting the server at', datetime.now()) print('Waiting for a client to call.') server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) server.bind(server_address) data, client = server.recvfrom(max_size.. 더보기
Amazon Linux 2에서 Python 3.10를 설치하는 방법 Amazon Linux 2에서 Python 3.10를 설치하는 방법 테스트 환경 운영체제 버전 정보 확인 $ cat /etc/os-release NAME="Amazon Linux" VERSION="2" ID="amzn" ID_LIKE="centos rhel fedora" VERSION_ID="2" PRETTY_NAME="Amazon Linux 2" ANSI_COLOR="0;33" CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2" HOME_URL="https://amazonlinux.com/" $ getconf LONG_BIT 64 시스템에 설치된 python version $ python --version Python 2.7.18 $ python3 --version Python.. 더보기
[python] ModuleNotFoundError: No module named 'PIL' python ModuleNotFoundError: No module named 'PIL' 테스트 환경 $ sw_vers ProductName:macOS ProductVersion:12.5 BuildVersion:21G72 $ python --version Python 3.9.13 Module Not Found Error Traceback (most recent call last): File "/Users/.../convert_image.py", line 2, in from PIL import Image ModuleNotFoundError: No module named 'PIL' pillow(PIL) 모듈 설치 pip 명령을 사용하여 pillow(PIL) 모듈 설치 pip3 install Pillow $ .. 더보기
[python] 파이썬 로또 번호 생성기 파이썬 로또 번호 생성기 lotto_v1.py 생성 import random ### 로또 번호 생성 def lotto_numbers(): numbers = random.sample(range(1, 46), 6) numbers.sort() print(numbers) ### 로또 시행 횟수 def lotto_count(): count = int(input("시행 횟수 : ")) print("#" * 30) if 0 < count range object range(start, stop[, step]) range() : 시작(포함), 끝(제외), step(옵션) ex) range(1, 46), 6 = 시작(1), 끝(45) 실행 $ python lotto_v1.py 시행 횟수 : 1 ###############.. 더보기
python 모듈 탐색 경로 찾기 python 모듈 탐색 경로 찾기 테스트 환경 $ python --version Python 3.9.13 파이션 3.9의 sys.path 값 - 임포트할 모듈 경로 python import sys for place in sys.path: print(place) $ python Python 3.9.13 (main, Aug 7 2022, 01:19:39) [Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> for place in sys.path: ... print(place) ... /opt/homebrew/Cella.. 더보기

728x90