40피트 컨테이너 적재 계산 엑셀 시트 자동 생성: 체적, 수량, 남는 공간 계산
전달받은 요청에 따라 엑셀 시트를 생성하여 40피트 컨테이너에 적재할 수 있는 체적과 수량, 그리고 남는 체적을 계산해주는 함수를 작성하겠습니다. 아래는 해당 함수의 예시 코드입니다.\n\npython\nimport openpyxl\n\ndef calculate_container_volume(length, width, height):\n container_length = 40 * 12 # 40피트 컨테이너의 길이 (inch)\n container_width = 8 * 12 # 40피트 컨테이너의 너비 (inch)\n container_height = 8 * 12 # 40피트 컨테이너의 높이 (inch)\n \n volume_per_box = length * width * height # 상자 1개의 체적 (inch^3)\n \n max_quantity = (container_length * container_width * container_height) // volume_per_box # 컨테이너 내 최대 상자 수량\n \n remaining_volume = (container_length * container_width * container_height) % volume_per_box # 남는 체적 (inch^3)\n \n return max_quantity, remaining_volume\n\n# 엑셀 시트 생성\nwb = openpyxl.Workbook()\nsheet = wb.active\n\n# 시트 헤더 추가\nsheet['A1'] = 'Length (inch)'\nsheet['B1'] = 'Width (inch)'\nsheet['C1'] = 'Height (inch)'\nsheet['D1'] = 'Max Quantity'\nsheet['E1'] = 'Remaining Volume (inch^3)'\n\n# 사용자로부터 상자의 치수 입력 받기\nnum_boxes = int(input('상자의 개수를 입력하세요: '))\n\n# 상자 치수 및 계산 결과 시트에 추가\nfor i in range(num_boxes):\n length = int(input(f'{i+1}번째 상자의 길이를 입력하세요 (inch): '))\n width = int(input(f'{i+1}번째 상자의 너비를 입력하세요 (inch): '))\n height = int(input(f'{i+1}번째 상자의 높이를 입력하세요 (inch): '))\n\n max_quantity, remaining_volume = calculate_container_volume(length, width, height)\n\n sheet.append([length, width, height, max_quantity, remaining_volume])\n\n# 시트를 엑셀 파일로 저장\nwb.save('container_info.xlsx')\n\n\n위 코드를 실행하면 엑셀 파일 "container_info.xlsx"가 생성되며, 사용자는 상자의 개수와 각 상자의 길이, 너비, 높이를 입력할 수 있습니다. 입력이 완료되면 엑셀 파일에는 상자의 치수, 컨테이너 내 최대 수량, 남는 체적이 표시됩니다.
原文地址: https://www.cveoy.top/t/topic/pRoP 著作权归作者所有。请勿转载和采集!