Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 13 file
- # 6 sedili per fila
- # File 1 e 2 First class
- # 3 a 7 business
- # 8 a 13 economy
- # Input: tipo di biglietto ( first, business, economy )
- # Posto desiderato (finestrino, centrale, corridoio)
- # Row i con 1 < i < 13
- # Column A... F
- # Dove M[r][c] = * se r c è libero X altrimenti
- def print_posti_sedere(posti_sedere):
- numero_posto = 1
- print(" A B C D E F")
- for row in posti_sedere:
- print("Row ", numero_posto, end=" ")
- if(numero_posto < 10):
- print(" ", end="")
- for col in row:
- print(col, end=" ")
- print()
- numero_posto += 1
- def assegna_posto(posti_sedere, classe_posto, posto_desiderato):
- mappa_posti = {}
- if(classe_posto == 'first'):
- mappa_posti = {
- 'finestrino': [(0, 0), (0, 5), (1, 0), (1, 5)],
- 'centrale': [(0, 2), (0, 3), (1, 2), (1, 3)],
- 'corridoio': [(0, 1), (0, 4), (1, 1), (1, 4)]
- }
- if(classe_posto == 'business'):
- mappa_posti = {
- 'finestrino': [(2, 0), (2, 5), (3, 0), (3, 5), (4, 0), (4, 5), (5, 0), (5, 5), (6, 0), (6, 5)],
- 'centrale': [(2, 2), (2, 3), (3, 2), (3, 3), (4, 2), (4, 3), (5, 2), (5, 3), (6, 2), (6, 3)],
- 'corridoio': [(2, 1), (2, 4), (3, 1), (3, 4), (4, 1), (4, 4), (5, 1), (5, 4), (6, 1), (6, 4)]
- }
- if(classe_posto == 'economy'):
- mappa_posti = {
- 'finestrino': [(7, 0), (7, 5), (8, 0), (8, 5), (9, 0), (9, 5), (10, 0), (10, 5), (11, 0), (11, 5), (12, 0), (12, 5)],
- 'centrale': [(7, 2), (7, 3), (8, 2), (8, 3), (9, 2), (9, 3), (10, 2), (10, 3), (11, 2), (11, 3), (12, 2), (12, 3)],
- 'corridoio': [(7, 1), (7, 4), (8, 1), (8, 4), (9, 1), (9, 4), (10, 1), (10, 4), (11, 1), (11, 4), (12, 1), (12, 4)]
- }
- posti_disponibili = mappa_posti[posto_desiderato]
- # print(posti_disponibili)
- for posto in posti_disponibili:
- # print(posto[0], posto[1], posti_sedere[posto[0]][posto[1]])
- if(posti_sedere[posto[0]][posto[1]] == '*'):
- posti_sedere[posto[0]][posto[1]] = 'X'
- # Un posto c'è
- return True
- # Ho provato tutti i posti ma non ne ho trovato nesssuno
- return False
- posti_sedere = [
- ['*' for x in range(6)] for y in range(13)
- ]
- while True:
- scelta = ""
- print("1 Per prenotare un posto")
- print("2 Per mostrare posti disponibili")
- print("3 Per uscire")
- scelta = input("Comando: ")
- if(scelta == "1"):
- classe = ""
- print("Scelta classe: ")
- classe = input("[business, economy, first]: ")
- print("Scelta posto: ")
- posto = input("[finestrino, centrale, corridoio]: ")
- if(assegna_posto(posti_sedere, classe, posto)):
- print("Il tuo posto è stato assegnato!")
- else:
- print("Non esiste un posto che soddisfa le tue preferenze :(")
- if(scelta == "2"):
- print_posti_sedere(
- posti_sedere
- )
- if(scelta == "3"):
- print("Grazie per aver utilizzato il programma!")
- quit()
- print("\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement