Menu
CoddyTech

프로젝트: 주문 모델링

Coddy의 Go 개발자를 위한 Python 코스 레슨. 48개 중 43번째.

메모리 내 주문 처리기를 네 단계로 만드세요. Go 구조체 모델링은 Python 클래스로, 인터페이스 값 정책은 협력 객체로, 명시적 파싱 오류는 예외로, 맵 집계는 딕셔너리로 옮기세요. 전체 과정에서 동일한 여섯 개 파일을 유지하세요. 다음 단계마다 어떤 입력 및 출력 동작을 대체해야 하는지 설명하며, 각 정답은 지금까지 완성된 프로그램 전체입니다.

challenge icon

챌린지

초급

메모리 내 주문 처리기의 4단계 과정을 시작하세요. order.py에서 Order(customer,quantity,unit_cents)와 subtotal()을 구현하세요. 입력은 콜론이 없는 비어 있지 않은 고객명, 양의 정수 수량, 0 이상의 정수 센트 금액이며, 각각 세 줄에 입력됩니다. customer:quantity:subtotal을 출력하세요. Go 주문 모델처럼 센트는 정수로 유지하면서 상태를 Python 클래스에 넣으세요. 이후 정책 및 도우미 뼈대 코드는 그대로 두고 subtotal을 완성하세요. 시작 코드는 미완성 결과로 실행됩니다. 네 단계 모두 같은 파일을 사용합니다.

편집 가능한 파일: order.py, standard_policy.py, bulk_policy.py, functions.py, main.py. 제공된 import문과 필수 API 이름을 그대로 유지하세요. 잠긴 driver.py가 실행과 검사를 담당하므로 수정하지 마세요.

네 단계 모두 order.py, standard_policy.py, bulk_policy.py, functions.py, main.py와 잠긴 driver.py를 사용합니다. 제공된 진입 래퍼를 그대로 유지하세요. 드라이버는 main()을 한 번 호출한 다음 추가 입력이나 출력 없이 API를 테스트합니다. 각 단계의 정답은 해당 단계까지 완성된 전체 프로그램입니다.

직접 해보기

from order import Order
from standard_policy import StandardPolicy
from bulk_policy import BulkPolicy
from functions import make_policy, parse_order
from main import main

main()

probe_order = Order("probe", 3, 7)
assert (probe_order.customer, probe_order.quantity, probe_order.unit_cents) == ("probe", 3, 7)
assert probe_order.subtotal() == 21
probe_order.quantity = 4
assert probe_order.subtotal() == 28
other_order = Order("other", 1, 0)
assert other_order.subtotal() == 0 and probe_order.subtotal() == 28

Go 개발자를 위한 Python의 모든 레슨

직접 연습해 보세요: 온라인 Python 컴파일러