r/pythonhelp • • Jun 01 '22

HOMEWORK University Coursework

Hello all, is anyone able to help me with my python programming coursework. It is based off booking a seat at a theatre and involves creating functions and tables which I am lost on. Would anybody be willing to lend a hand it would be greatly appreciated?

0 Upvotes

3 comments sorted by

1

u/a_idanwalton Jun 01 '22

What year are you in? Is it for a database module or is it purely the programming?

1

u/Jonah9377 Jun 03 '22

I am in foundation year doing mechanical engineering however we have to pass this one module to progress which I am struggling on. It is purely programming that, I have attempted what I can but I am unable to get it working properly

1

u/a_idanwalton Jun 03 '22

What I would suggest is:

First make a class for a seat which holds the number and row.

class Seat:
    
    def __init__(self, number=1, row="A"):
        self.number = number
        self.row = row

If you're required to get information about who's booked it, i.e. name, number etc. Then make another class called Person and another class called Booking.

class Person:
    
    def __init__(self, name="", phoneNumber="" ...):
        self.name = name
        self.phoneNumber = phoneNumber
        etc

class Booking:
    
    def __init__(self, ID=int(-1), seat=None, person=None):
        self.ID = ID
        self.seat = seat
        self.person

Then make a class for the theatre - to hold all the seats and bookings it has.

class Theatre: 
    
    def __init__(self, seats=[], bookings=[]): 
        self.ID = 1
        self.seats = seats
        self.bookings = bookings

This class then needs to have a method (function) which can create a new booking instance.

    def book(self, seat, person):
        self.bookings.append(Booking(ID=self.ID, seat=seat, person=person))
        self.ID += 1

This should hopefully help. If you've never used classes before then I'm happy to answer any questions or offer more explanation on what is happening at each step if you need.

Edit: There are also some extra things I would suggest adding in the book method, such as, checking if the seat exists in the theatre and if the seat is already booked.