无法调试语法错误并需要一些asisstance

时间:2018-02-03 20:57:11

标签: python-3.6

我正在学习Python3.6并花了很长时间查看这段代码来调试allcoate_seat函数中发生的语法错误,位置"如果行不在行中:"并想分享这个并找出原因。我仍在构建代码并坚持这个位置。

代码段:

class Flight:
    def __init__(self, fnumber, aircraft):
                if not fnumber[:2].isalpha():
            raise ValueError ("No airline code in {}".format(fnumber))
        if not fnumber[:2].isupper():
            raise ValueError ("Invalid airline code in {}".format(fnumber))
        if not (fnumber[2:].isdigit() and int(fnumber[2:]))<9999:
            raise ValueError ("Invalid route in {}".format(fnumber))

        self.fnumber=fnumber
        self.aircraft=aircraft

        rows, seats = aircraft.seating_plan()
        self.seating=[None] + [{letter:None for letter in seats} for _ in rows]

    def fnumber (self):
        return self.fnumber

    def airline(self):
        return self.fnumber[:2]

    def aircraft_model(self):
        return self.aircraft.model()

    def allcoate_seat(self, seat, passenger):
        rows, seat_letters=self._aircraft.seating_plan()
        letter=seat[-1]

        if letter not in seat_letters:
            raise ValueError ('Invalid seat letters {}'.format(letter))
        row_text=seat[:-1]
        try:
            row=int(row_text)
        except ValueError:
            raise ValueError('Invalid seat row {}'.format(row_text)

        if row not in rows:
            raise ValueError ('Invalid row  number {}'.format(row))

        if self._seating[row][letter] is not None:
            raise ValueError ('Seat already allocated {}'.format(seat))

        self._seating[row][letter]=passenger

class Aircraft:
    def __init__(self, registration, model, num_rows, num_seats_per_row):
        self._registration=registration
        self._model=model
        self._num_rows=num_rows
        self._num_seats_per_row=num_seats_per_row

    def registration(self):
        return self._registration

    def model(self):
        return self._model

    def seating_plan(self):
        return(range(1,self._num_rows+1),'ABCDEFGHJ'[:self._num_seats_per_row])

    f1= Flight('TA098', Aircraft('TA008','AirbusA380',10,5))
print(f1.fnumber, f1.aircraft_model(), f1.airline(), pp(f1.seating))

0 个答案:

没有答案