Python Pass Control Script [closed]

3

What would be the most appropriate solution to this problem?

The purpose of this script in Python is to process the possible sales of tickets, analyzing each one of them, indicating if it is possible to SELL or NOT TO SELL.

The requirements for the script are:

4 cities (A, B, C and D) with ticket sales points.

The bus runs from A to D, passing B and C and has 45 accents.

The script consists of input, processing, and output.

Entry data (100 attempts to purchase tickets):

  X> Y, X> Y, X> Y, X> Y, X> Y, X> Y, X> Y Y Y < , X > Y, X > Y, ...

Where X and Y indicate, respectively, Source City and Destination City.

tentativas = ['A>C','A>C','A>C','B>D','B>D','B>D','B>D','B>D','A>B',
              'A>B','A>B','A>B','B>C','B>C','B>C','B>C','B>C','A>D',
              'A>D','A>D','A>D','A>D','A>D','A>D','A>D','A>D','C>D',
              'C>D','C>D','C>D','C>D','C>D','C>D','C>D','B>D','B>D',
              'B>D','B>D','B>C','B>C','B>C','A>C','A>B','A>B','B>C',
              'B>C','B>C','A>C','C>D','C>D','C>D','C>D','C>D','C>D',
              'C>D','B>D','B>D','B>D','B>D','A>B','A>B','A>B','A>B',
              'A>B','A>B','A>B','A>B','A>B','A>B','A>B','A>C','A>C',
              'A>C','A>C','A>C','A>C','A>C','A>C','A>C','A>C','A>D',
              'C>D','C>D','C>D','C>D','B>D','B>D','B>D','B>D','B>D',
              'A>B','A>B','A>C','A>C','A>C','C>D','C>D','A>B','A>B',
              'A>D']


ab = []
bc = []
cd = []

poltronas = 45

i = 0

for tentativa in tentativas:
    i = i + 1

    if (tentativa == 'A>B' and len(ab) < poltronas): 
        ab += [i]

    if (tentativa == 'A>C' and len(ab) < poltronas and len(bc) < poltronas):
        ab += [i]
        bc += [i]

    if (tentativa == 'A>D' and len(ab) < poltronas and len(bc) < poltronas and len(cd) < poltronas):
        ab += [i] 
        bc += [i]
        cd += [i]

    if (tentativa == 'B>C' and len(bc) < poltronas):
        bc += [i]

    if (tentativa == 'B>D' and len(bc) < poltronas and len(cd) < poltronas):
        bc += [i]
        cd += [i]

    if (tentativa == 'C>D' and len(cd) < poltronas):
        cd += [i]

    if (i in ab or i in bc or i in cd):
        print (i , ' - ', tentativa , ' - VENDER')
    else:
        print (i , ' - ', tentativa , ' - NAO VENDER')
    
asked by anonymous 23.08.2016 / 03:51

0 answers