MatteB_01

posti teatro

Dec 4th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.21 KB | None | 0 0
  1. colonne = ["A", "B", "C", "D", "E","F","G", "H", "I","J"]
  2. righe = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
  3. schemaPosti = [
  4.     [" ", "A ", "B ", "C ", "D ", "E ", "F ", "G ", "H ", "I ", "J "],
  5.     ["1", 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
  6.     ["2", 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
  7.     ["3", 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
  8.     ["5", 10, 10, 20, 20, 20, 20, 20, 20, 10, 10],
  9.     ["6", 10, 10, 20, 20, 20, 20, 20, 20, 10, 10],
  10.     ["7", 20, 20, 30, 30, 40, 40, 30, 30, 20, 20],
  11.     ["8", 20, 30, 30, 40, 50, 50, 40, 30, 30, 20],
  12.     ["9", 30, 40, 50, 50, 50, 50, 50, 50, 40, 30]
  13.  
  14. ]
  15. def posti(schemaPosti):
  16.     print("------------POSTI DISPONIBILI---------------")
  17.     for i in range(len(schemaPosti)):
  18.         for j in schemaPosti[i]:
  19.             print(j, end="  ")
  20.         print()
  21.     print("--------------------------------------------")
  22.  
  23.  
  24. def sceltaposto(schemaPosti, righe, colonne):
  25.     ok = False
  26.     while not ok:
  27.         posto = input("inserisci il posto che preferisci  specificando prima il numero e poi la lettera (es. 1A): ")
  28.         posto = posto.upper()
  29.         riga = posto[0]
  30.         colonna = posto[1]
  31.         costo = schemaPosti[righe.index(riga) + 1][colonne.index(colonna) + 1]
  32.  
  33.  
  34.         if riga in righe and colonna in colonne and costo != "XX":
  35.             print(f"hai prenotato con successo il posto {posto} per un importo di {costo} euro")
  36.             schemaPosti[righe.index(riga) + 1][colonne.index(colonna) + 1] = "XX"
  37.             ok = True
  38.         elif costo == "XX":
  39.             print(f"il posto {posto} è già stato prenotato")
  40.         else:
  41.             print("posto non valido")
  42.  
  43. def sceltaprezzo(schemaPosti, righe, colonne):
  44.     ok = False
  45.     while not ok:
  46.         prezzo = input("inserisci il costo scelto: ")
  47.         if prezzo.isnumeric():
  48.             prezzo=int(prezzo)
  49.  
  50.             for i in range(1, len(schemaPosti)):
  51.                 for j in range(1, len(schemaPosti[i])):
  52.                     if schemaPosti[i][j] == prezzo:
  53.                         posto = righe[i - 1] + colonne[j - 1]
  54.                         schemaPosti[i][j] = "XX"
  55.                         print(f"le è stato assegnato il posto {posto}")
  56.                         return
  57.             print("non è disponibile alcun posto con quel prezzo")
  58.  
  59.         else:
  60.             print("inserisci un numero valido")
  61.  
  62. def disponibile(schemaPosti):
  63.     for i in range(1, len(schemaPosti)):
  64.         for j in range(1, len(schemaPosti[i])):
  65.             prezzo = str(schemaPosti[i][j])
  66.             if prezzo.isnumeric():
  67.                 return True
  68.     return False
  69. #-------------------------------------------------------------------------------------------------------------
  70.  
  71. while disponibile(schemaPosti):
  72.     posti(schemaPosti)
  73.     ok = False
  74.     while not ok:
  75.         scelta = input(
  76.             "inserisi 'posto' se vuoi selezionare il posto, inserisci 'prezzo' se vuoi sceglierne uno in base al prezzo: ")
  77.         if scelta.lower() == "prezzo":
  78.             sceltaprezzo(schemaPosti, righe, colonne)
  79.             ok = True
  80.         elif scelta.lower() == "posto":
  81.             sceltaposto(schemaPosti, righe, colonne)
  82.             ok = True
  83.         else:
  84.             print("non ho capito")
Advertisement
Add Comment
Please, Sign In to add comment