Advertisement
informaticage

Esercizio Francesco

Mar 25th, 2021 (edited)
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.11 KB | None | 0 0
  1. # 13 file
  2. # 6 sedili per fila
  3. # File 1 e 2 First class
  4. # 3 a 7 business
  5. # 8 a 13 economy
  6.  
  7. # Input: tipo di biglietto ( first, business, economy )
  8. # Posto desiderato (finestrino, centrale, corridoio)
  9.  
  10. # Row i con 1 < i < 13
  11. # Column A... F
  12. # Dove M[r][c] = * se r c è libero X altrimenti
  13.  
  14. def print_posti_sedere(posti_sedere):
  15.     numero_posto = 1
  16.     print("        A B C D E F")
  17.     for row in posti_sedere:
  18.         print("Row ", numero_posto, end=" ")
  19.         if(numero_posto < 10):
  20.             print(" ", end="")
  21.         for col in row:
  22.             print(col, end=" ")
  23.         print()
  24.         numero_posto += 1
  25.  
  26.  
  27. def assegna_posto(posti_sedere, classe_posto, posto_desiderato):
  28.     mappa_posti = {}
  29.     if(classe_posto == 'first'):
  30.         mappa_posti = {
  31.             'finestrino': [(0, 0), (0, 5), (1, 0), (1, 5)],
  32.             'centrale': [(0, 2), (0, 3), (1, 2), (1, 3)],
  33.             'corridoio': [(0, 1), (0, 4), (1, 1), (1, 4)]
  34.         }
  35.  
  36.     if(classe_posto == 'business'):
  37.         mappa_posti = {
  38.             'finestrino': [(2, 0), (2, 5), (3, 0), (3, 5), (4, 0), (4, 5), (5, 0), (5, 5), (6, 0), (6, 5)],
  39.             'centrale':   [(2, 2), (2, 3), (3, 2), (3, 3), (4, 2), (4, 3), (5, 2), (5, 3), (6, 2), (6, 3)],
  40.             'corridoio':  [(2, 1), (2, 4), (3, 1), (3, 4), (4, 1), (4, 4), (5, 1), (5, 4), (6, 1), (6, 4)]
  41.         }
  42.  
  43.     if(classe_posto == 'economy'):
  44.         mappa_posti = {
  45.             '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)],
  46.             '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)],
  47.             '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)]
  48.         }
  49.  
  50.     posti_disponibili = mappa_posti[posto_desiderato]
  51.     # print(posti_disponibili)
  52.     for posto in posti_disponibili:
  53.         # print(posto[0], posto[1], posti_sedere[posto[0]][posto[1]])
  54.         if(posti_sedere[posto[0]][posto[1]] == '*'):
  55.             posti_sedere[posto[0]][posto[1]] = 'X'
  56.             # Un posto c'è
  57.             return True
  58.     # Ho provato tutti i posti ma non ne ho trovato nesssuno
  59.     return False
  60.  
  61.  
  62. posti_sedere = [
  63.     ['*' for x in range(6)] for y in range(13)
  64. ]
  65.  
  66. while True:
  67.     scelta = ""
  68.     print("1 Per prenotare un posto")
  69.     print("2 Per mostrare posti disponibili")
  70.     print("3 Per uscire")
  71.  
  72.     scelta = input("Comando: ")
  73.     if(scelta == "1"):
  74.         classe = ""
  75.         print("Scelta classe: ")
  76.         classe = input("[business, economy, first]: ")
  77.         print("Scelta posto: ")
  78.         posto = input("[finestrino, centrale, corridoio]: ")
  79.  
  80.         if(assegna_posto(posti_sedere, classe, posto)):
  81.             print("Il tuo posto è stato assegnato!")
  82.         else:
  83.             print("Non esiste un posto che soddisfa le tue preferenze :(")
  84.  
  85.     if(scelta == "2"):
  86.         print_posti_sedere(
  87.             posti_sedere
  88.         )
  89.  
  90.     if(scelta == "3"):
  91.         print("Grazie per aver utilizzato il programma!")
  92.         quit()
  93.  
  94.     print("\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement