1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| import pandas as pd
import json
df = pd.read_csv("hotels.csv", dtype={"id": str})
df_cards = pd.read_csv("cards.csv", dtype=str).to_dict()
class Hotel:
def __init__(self, hotel_id):
self.hotel_id = hotel_id
self.name = df.loc[df["id"] == self.hotel_id, "name"].squeeze()
def book(self):
"""book a hotel by changing its availability to no"""
df.loc[df["id"] == self.hotel_id, "available"] = "no"
df.to_csv("hotels.csv", index=False)
def available(self):
"""check if the hotel is available"""
availability = df.loc[df["id"] == self.hotel_id, "available"].squeeze()
if availability == "yes":
return True
else:
return False
class ReservationTicket:
def __init__(self, customer_name, hotel_object):
self.customer_name = customer_name
self.hotel = hotel_object
def generate(self):
content = f"""
Thank you for your reservation !
Here are your booking data
Name: {self.customer_name}
Hotel name : {self.hotel.name}
"""
return content
class CreditCard:
def __init__(self, number):
self.number = number
def validate(self, expiration, holder, cvc):
card_data = {"number": self.number, "expiration": expiration,
"holder": holder, "cvc": cvc}
m_data = frozenset(card_data.items())
if m_data in df_cards:
return True
else:
return False
print(df)
hotel_ID = input("Enter the Id of the hotel :")
hotel = Hotel(hotel_ID)
if hotel.available():
credit_card = CreditCard(number="1234")
if credit_card.validate(expiration="12/26", holder="JOHN SMITH", cvc="123"):
hotel.book()
name = input("Enter your name: ")
reservation_ticket = ReservationTicket(customer_name=name, hotel_object=hotel)
print(reservation_ticket.generate())
else:
print("there was a problem with your payment")
else:
print("Hotel is not free") |
Partager