Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- HOTEL = "hotels.txt"
- PRENOTAZIONI = "booking.txt"
- #--------------MEMORIZZO LA LISTA DEGLI HOTEL IN UN DIZIONARIO nome-[ID , NUMERO CAMERE, NUMERO POSTI RIMANENTI]-----------
- try:
- with open(HOTEL, "r") as file:
- hotel = {}
- for line in file:
- info = line.strip().split(":")
- #riordino i valori della lista e duplico il numero di camere
- temp = info[0]
- info[0] = info[1]
- info[1] = temp
- info[2] = int(info[2])
- info[3] = info[2]
- hotel[info[0]] = info[1:]
- except IOError:
- print("il file contenente l' elenco degli hotel è inesistente o il suo nome è errato")
- exit()
- #--------------MEMORIZZO I BOOKING IN UNA TABELLA------------------------------
- try:
- with open(PRENOTAZIONI, "r") as file:
- prenotazioni = []
- for line in file:
- info = line.strip().split(" ")
- info[2] = int(info[2])
- prenotazioni.append(info)
- except IOError:
- print("il file contenente l' elenco delle prenotazioni è inesistente o il suo nome è errato")
- exit()
- #------------CICLO SUI BOOKING RIDUCENDO IL NUMERO DI CAMERE DALL' ELEMENTO CORRISPONDENTE DEL DIZIONARIO QUALORA POSSIBILE----
- confermate , respinte = controlloBooking(prenotazioni, hotel)
- print(f"prenotazioni confermate: {confermate} , prenotazioni respinte: {respinte}")
- #--------------STAMPO A SCHERMO GLI HOTEL CON RELATIVE CAMERE E POSTI LIBERI E NE VALUTO QUELLO CON PIU POSTI LIBERI CICLANDO-------------
- migliorNumero = 0
- migliore = ""
- for albergo in hotel.keys():
- print(f"{hotel[albergo][0]}: {hotel[albergo][1]} camere ({hotel[albergo][2]} libere)")
- if hotel[albergo][2]> migliorNumero:
- migliorNumero = hotel[albergo][2]
- migliore = hotel[albergo][0]
- print(f"hotel con più camere libere: {migliore}")
- #------------------------FUNZIONI----------------------------------------------
- def controlloBooking(prenotazioni, hotel):
- confermate = 0
- respinte = 0
- for booking in prenotazioni:
- posti = booking[2]
- luogo = booking[1]
- if hotel[luogo][2] >= posti:
- confermate +=1
- hotel[luogo][2] -= posti
- else:
- respinte += 1
- print(f"Richiesta non confermata: {booking[0]}")
- return confermate, respinte
- #-------------------------------------------------------------------------
- main()
Advertisement
Add Comment
Please, Sign In to add comment