Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
ESERCIZIO ESAME HOTEL (Da Finire)
ESERCIZIO ESAME HOTEL (Da Finire)
def leggihotel(filename):
infile=open(filename,"r")
elencohotel={}
for line in infile:
hotel={}
fields=line.split(":")
hotel["nome"]=fields[0]
hotel["camere"]=int(fields[2])
hotel["libere"]=int(fields[2])
elencohotel[fields[1].strip()]=hotel
infile.close()
print(elencohotel)
return elencohotel
def stampaalberghi(elencohotel):
print("stato alberghi")
for hotel in elencohotel:
print("hotel", elencohotel[hotel]["nome"],elencohotel[hotel]["camere"] )
def prenota(elenco,filename):
infile=open(filename,"r")
confermate=0
nonconfermate=0
for line in infile:
fields=line.split()
hotel=fields[1].strip()
if hotel in elenco:
camere=int(fields[2])
if elenco[hotel]["libere"]>= camere:
camere=camere+1
elenco[hotel]["libere"]=elenco[hotel]["libere"]-camere
else:
print("prenotazione non confermata")
nonconfermate=nonconfermate+1
def main():
try:
elenco=leggihotel("hotel.txt")
prenota(elenco, "booking.txt")
except IOError:
print("errore nel file")
main()