Project 2: Travel Agency
Implement a program that manages the data of a travel agency. The agency manages the list of hotels that accommodate tourists. For each hotel the agency has the following data: name, address, city, country, number of starts, price per night and a list of facilities. The data are stored into a json file. The application should manage the following characteristics: add a new hotel , remove existing hotel (identified by name) , show hotels of a specific city or country, show hotels that provide a specific facility (e.g., free wifi)
Changes need to be stored back in the file. The above functionalities are implemented through methods of a class named TravelAgency. The application interacts with the user through a menu where the user is asked for the next action to undertake (e.g., 1 -Add new hotel, 2- Remove existing hotel, etc.) Put comments on your code.
import json
with open('hotels.json') as json_file:
hotels = json.load(json_file)
while True:
print('(1) Add')
print('(2) Delete')
print('(3) Exit')
i = int(input())
if i == 1:
hotels.append({
"name": input('Name: '),
"address": input('Address: '),
"city": input('City: '),
"country": input('Country: '),
"number": input('Number: '),
"price": input('Price per night: ')
});
if i == 2:
j = int(input('Enter idx of item: '))
if j < len(hotels):
del hotels[j]
if i == 3:
break;
with open('hotels.json', 'w') as outfile:
json.dump(hotels, outfile)
Comments
Leave a comment