patternpythonMinor
Project hotel reservation in Python with OOP and multithreading
Viewed 0 times
withreservationhotelprojectpythonandmultithreadingoop
Problem
I have to create a project in Python 3 for a university exam. The project involves the use of object-oriented programming and the use of multithreading. My project is based on the simulation of booking a hotel room. I then created a
rooms.txt:
Single
Double
Triple
Matrimonial
price_rooms.txt:
Single Yes 46.0
Single No 40.0
Double No 70.5
Double Yes 76.5
Triple No 90.0
Triple Yes 96.0
Matrimonial No 65.0
Matrimonial Yes 71.0
I have doubts about the use of object-oriented programming and especially on multithreading. Can you help me regarding a correct use of this?
```
from datetime import datetime, date
from threading import Thread
import threading
class Stay:
'''Classe per la prenotazione di un Stay.'''
def __init__(self, room_type= '', from_date= '00-00-0000', days= 0, breakfast= '', price= 0.0):
self._room_type= room_type
self._from_date= from_date
self._days= days
self._breakfast= breakfast
self._price= price
def __str__(self):
return '\nTipology of room: %s\nDate: %s\nNumbers of days: %s\nTotal price: %d\n' % (self._room_type, self._from_date, self._days, self._price)
def set_room_type (self, room_type):
while True:
try:
try:
rooms= open ('rooms.txt', 'r')
except IOError:
print ('Files for reading the kinds of rooms corrupt or not found\n')
lista= []
for riga in rooms:
room = riga.strip()
lista.append(room)
rooms.close()
print ('\nSelect the type of room that interests:')
room=input('')
Stay class with its instance variables and its methods. For multithreading I tried to implement a competing book, inserting global variables as the number of available rooms by type.rooms.txt:
Single
Double
Triple
Matrimonial
price_rooms.txt:
Single Yes 46.0
Single No 40.0
Double No 70.5
Double Yes 76.5
Triple No 90.0
Triple Yes 96.0
Matrimonial No 65.0
Matrimonial Yes 71.0
I have doubts about the use of object-oriented programming and especially on multithreading. Can you help me regarding a correct use of this?
```
from datetime import datetime, date
from threading import Thread
import threading
class Stay:
'''Classe per la prenotazione di un Stay.'''
def __init__(self, room_type= '', from_date= '00-00-0000', days= 0, breakfast= '', price= 0.0):
self._room_type= room_type
self._from_date= from_date
self._days= days
self._breakfast= breakfast
self._price= price
def __str__(self):
return '\nTipology of room: %s\nDate: %s\nNumbers of days: %s\nTotal price: %d\n' % (self._room_type, self._from_date, self._days, self._price)
def set_room_type (self, room_type):
while True:
try:
try:
rooms= open ('rooms.txt', 'r')
except IOError:
print ('Files for reading the kinds of rooms corrupt or not found\n')
lista= []
for riga in rooms:
room = riga.strip()
lista.append(room)
rooms.close()
print ('\nSelect the type of room that interests:')
room=input('')
Solution
== instead of = "bug"I saw this line in your code:
ndays == 0In Python assignment is done with a singe
=, using double == you are asking Python if the objects are equal and discarding the result of such comparison, there is no crash / unexpected behaviour here because ndays=int(input('')) overwrites ndays shortly thereafter anyway (so setting it to 0 would have been useless too).I suggest removing such a weird "do nothing" line from your code to avoid confusing the readers (and yourself of the future).
Critical UI flaw
You asked for
yes but checked for Si (italian word meaning yes).The user will be unable to proceed in this branch because of this flaw:
print ('If you like our breakfast you type Yes, No otherwise')
first_breakfast= input ('')
if first_breakfast== 'Si':Code Snippets
print ('If you like our breakfast you type Yes, No otherwise')
first_breakfast= input ('')
if first_breakfast== 'Si':Context
StackExchange Code Review Q#132579, answer score: 4
Revisions (0)
No revisions yet.