본문 바로가기

728x90

python

C276x260.fwebp.q85 [WIP] Python 로또 번호 생성기 -2 Python 로또 번호 생성기 -2Python 코드vim generate_lotto_numbers.pyimport random# 로또 번호 생성 함수def generate_lotto_numbers(): numbers = [] while len(numbers) 실행 권한 부여chmod +x generate_lotto_numbers.py프로그램 실행python generate_lotto_numbers.py또는./generate_lotto_numbers.py실행기본값 사용$ python generate_lotto_numbers.py로또 번호를 몇 개 출력하시겠습니까? (기본값: 3)[3, 7, 14, 22, 34, 41][2, 5, 11, 19, 28, 37][6, 12, 18, 23, 31, 45.. 더보기
C276x260.fwebp.q85 [WIP] Python 로또 번호 생성기 Python 로또 번호 생성기Python 코드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 range(stop) -> range object range(start, stop[, step])range() : 시작(포함), 끝(제외), step(옵션)ex) range(1, 46), 6 = 시작(1), 끝(45)프로그램 실행$ python lotto_v1.py시행 횟수 : .. 더보기
C276x260.fwebp.q85 [draft] python tcp 소켓 통신 python tcp 소켓 통신code : https://github.com/madscheme/introducing-python tcp_server.py 작성from datetime import datetimeimport socketaddress = ('localhost', 6789)max_size = 1000print('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 = client.re.. 더보기
C276x260.fwebp.q85 [draft] python udp 소켓 통신 python udp 소켓 통신code : https://github.com/madscheme/introducing-python udp_server.py 작성from datetime import datetimeimport socketserver_address = ('localhost', 6789)max_size = 4096print('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)print('At.. 더보기
C276x260.fwebp.q85 [draft] python ModuleNotFoundError: No module named 'PIL' python ModuleNotFoundError: No module named 'PIL'테스트 환경운영체제 정보$ sw_versProductName: macOSProductVersion: 12.5BuildVersion: 21G72$ python --versionPython 3.9.13Module Not Found ErrorTraceback (most recent call last): File "/Users/.../convert_image.py", line 2, in from PIL import ImageModuleNotFoundError: No module named 'PIL'pillow(PIL) 모듈 설치pip 명령을 사용하여 pillow(PIL) 모듈 설치pip3 install Pillow$.. 더보기
C276x260.fwebp.q85 [draft] Amazon Linux 2에서 Python 3.10를 설치하는 방법 Amazon Linux 2에서 Python 3.10를 설치하는 방법테스트 환경운영체제 버전 정보$ cat /etc/os-releaseNAME="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_BIT64시스템에 설치된 python version$ python --versionPython 2.7.18$ python3 --versionPython 3.7.91. 필수 패키지 설치Pyth.. 더보기
C276x260.fwebp.q85 [draft] 우분투에서 python 명령어를 사용할 수 있도록 설정하는 방법 우분투에서 python 명령어를 사용할 수 있도록 설정하는 방법테스트 환경$ lsb_release -dDescription: Ubuntu 24.04.1 LTS시스템에 python 명령어가 설정되어 있지 않다는 메시지 출력$ python --versionCommand 'python' not found, did you mean: command 'python3' from deb python3 command 'python' from deb python-is-python31. 기본 설치 확인우분투에서는 기본적으로 python3가 설치되어 있습니다. 하지만 python 명령어는 별도로 설정하지 않으면 사용할 수 없습니다. python3가 설치되어 있는지 확인합니다.python3 --versionPython.. 더보기

728x90