내가 다음을 수행 좌석 예약 프로그램을 코딩하는 노력했습니다 값 :검색 중 목록 항목
- 는 대한 사용자 입력 (행, 좌석 번호)
- 확인 외부 CSV 파일을 이동합니다 상기 입력에 기초한 좌석의 이용 가능한 블록.
- 무료 좌석 수를 반환하고 좌석 번호가 또는 인 경우 사용자에게 해당 행에 충분한 공간이 없다고 알립니다.
무료로 사용할 수있는 좌석의 좌석 번호를 검색하는 데 어려움이 있습니다. 내 현재 방법으로 어떤 아이디어? 매우 감사!
import csv
from itertools import groupby
LargeBlock = 0
SpacesReq = int(input("How many spaces do you require? (8 Max.) "))
while SpacesReq > 8:
print("Invalid amount.")
break
SectionReq = input("What row would you like to check between A-E? (Uppercase required) ")
with open('data.csv', 'rt') as file:
open_f = csv.reader(file, delimiter=',')
for line in open_f:
if line[10] == SectionReq:
LargeBlock = max(sum(1 for _ in g) for k, g in groupby(line) if k == '0')
if SpacesReq > LargeBlock:
print('There are only ', LargeBlock, ' seats together, available on row ',SectionReq,'.')
else:
print('There is room for your booking of ',SpacesReq,' seats on row ',SectionReq,'.')
break
CSV 구조
1 0 1 0 0 0 0 0 0 0 E
0 0 0 0 0 0 0 0 0 0 D
0 0 0 0 0 1 0 0 0 0 C
0 0 0 0 0 0 0 0 1 0 B
0 0 0 0 0 1 1 1 1 1 A
충분한 좌석이 있는지 여부를 계산할 때 좌석 위치를 수집 할 수 있습니다 (이 경우 좌석이 충분하지 않은 경우 위치를 "낭비"하고 있음) 또는 일단 자리가 충분하다는 것을 알게되면 위치를 찾을 수 있습니다 (좌석이 충분하면 작업을 두 배로 늘릴 수 있습니다). – selllikesybok