Help with automatic movie scheduler /u/Skoilarr Python Education

I’m making an automatic showtime scheduler for my job at a movie theater. I have been fighting with the scheduling logic and so far have it working almost as intended. The output my code is giving me looks like this:

Auditorium 1: Moana 2

Showtime: 10:00 AM

Showtime: 12:40 PM

Showtime: 03:20 PM

Showtime: 06:00 PM

Auditorium 2: Moana 2

Showtime: 10:45 AM

Showtime: 01:25 PM

Showtime: 04:05 PM

Showtime: 06:45 PM

Showtime: 09:25 PM

Auditorium 3: Moana 2

Showtime: 11:30 AM

Showtime: 02:10 PM

Showtime: 04:50 PM

Showtime: 07:30 PM

Showtime: 10:10 PM

Scheduling complete!

The one problem is that it isn’t scheduling another show in Aud 1 when there is still time. I don’t get how it is able to add the 9:25pm and 10:10pm but not an 8:40pm? Please help!

import datetime class MovieScheduler: def __init__(self): self.opening_time = None self.closing_time = None self.movies = [] self.preshow_time = 30 self.clean_time = 30 # Add movie def add_movie(self, name, runtime, num_prints, auditorium): self.movies.append({ "name": name, "runtime": runtime, "num_prints": num_prints, "auditorium": auditorium }) # Get time input def get_time_input(self, prompt): while True: try: time_input = input(prompt) return datetime.datetime.strptime(time_input, "%I:%M %p").time() except ValueError: print("Invalid time format. Please use 12-hour clock.") # Get movie details def get_movie_details(self): name = input("Enter movie name: ") while True: try: runtime = int(input("Enter movie runtime (in minutes): ")) break except ValueError: print("Invalid runtime. Please enter the runtime in minutes.") while True: try: num_prints = int(input("Enter number of prints: ")) break except ValueError: print("Invalid number of prints. Please enter a number.") auditorium = input("Enter auditorium number(s), seperated by commas: ") self.add_movie(name, runtime, num_prints, auditorium) # Gather inputs def gather_inputs(self): print("Let's set up the movie schedule.") self.opening_time = self.get_time_input("Enter opening time HH:MM AM/PM: ") self.closing_time = self.get_time_input("Enter closing time HH:MM AM/PM: ") while True: self.get_movie_details() more_movies = input("Add another movie? (y/n): ").strip().lower() if more_movies != "y": break self.calculate_showtimes() # Staggered start times def get_staggered_start_times(self, num_prints, total_runtime): stagger_gap = (total_runtime // num_prints) stagger_gap = (int(stagger_gap) + 4) // 5 * 5 start_times = [] for i in range(num_prints): adjusted_start_time = datetime.datetime.combine(datetime.date.today(), self.opening_time) + datetime.timedelta(minutes=i * stagger_gap) start_times.append(adjusted_start_time) return start_times # Calculate showtimes def calculate_showtimes(self): for movie in self.movies: total_runtime = movie["runtime"] + self.preshow_time # Movie runtime + preshow time num_prints = movie["num_prints"] auditoriums = [a.strip() for a in movie['auditorium'].split(',')] # Get staggered start times for each auditorium start_times = self.get_staggered_start_times(num_prints, total_runtime) for i in range(len(auditoriums)): print(f"nAuditorium {auditoriums[i]}: {movie['name']}") next_start_time = start_times[i] while next_start_time < datetime.datetime.combine(datetime.date.today(), self.closing_time): end_time = next_start_time + datetime.timedelta(minutes=total_runtime + self.clean_time) if end_time.time() > self.closing_time: break showtime = next_start_time.strftime("%I:%M %p") print(f" Showtime: {showtime}") next_start_time = end_time next_start_time = next_start_time + datetime.timedelta(minutes=(5 - next_start_time.minute % 5) % 5) # Testing the input gathering scheduler = MovieScheduler() scheduler.gather_inputs() # Print the final message print("nScheduling complete!") 

submitted by /u/Skoilarr
[link] [comments]

​r/learnpython I’m making an automatic showtime scheduler for my job at a movie theater. I have been fighting with the scheduling logic and so far have it working almost as intended. The output my code is giving me looks like this: Auditorium 1: Moana 2 Showtime: 10:00 AM Showtime: 12:40 PM Showtime: 03:20 PM Showtime: 06:00 PM Auditorium 2: Moana 2 Showtime: 10:45 AM Showtime: 01:25 PM Showtime: 04:05 PM Showtime: 06:45 PM Showtime: 09:25 PM Auditorium 3: Moana 2 Showtime: 11:30 AM Showtime: 02:10 PM Showtime: 04:50 PM Showtime: 07:30 PM Showtime: 10:10 PM Scheduling complete! The one problem is that it isn’t scheduling another show in Aud 1 when there is still time. I don’t get how it is able to add the 9:25pm and 10:10pm but not an 8:40pm? Please help! import datetime class MovieScheduler: def __init__(self): self.opening_time = None self.closing_time = None self.movies = [] self.preshow_time = 30 self.clean_time = 30 # Add movie def add_movie(self, name, runtime, num_prints, auditorium): self.movies.append({ “name”: name, “runtime”: runtime, “num_prints”: num_prints, “auditorium”: auditorium }) # Get time input def get_time_input(self, prompt): while True: try: time_input = input(prompt) return datetime.datetime.strptime(time_input, “%I:%M %p”).time() except ValueError: print(“Invalid time format. Please use 12-hour clock.”) # Get movie details def get_movie_details(self): name = input(“Enter movie name: “) while True: try: runtime = int(input(“Enter movie runtime (in minutes): “)) break except ValueError: print(“Invalid runtime. Please enter the runtime in minutes.”) while True: try: num_prints = int(input(“Enter number of prints: “)) break except ValueError: print(“Invalid number of prints. Please enter a number.”) auditorium = input(“Enter auditorium number(s), seperated by commas: “) self.add_movie(name, runtime, num_prints, auditorium) # Gather inputs def gather_inputs(self): print(“Let’s set up the movie schedule.”) self.opening_time = self.get_time_input(“Enter opening time HH:MM AM/PM: “) self.closing_time = self.get_time_input(“Enter closing time HH:MM AM/PM: “) while True: self.get_movie_details() more_movies = input(“Add another movie? (y/n): “).strip().lower() if more_movies != “y”: break self.calculate_showtimes() # Staggered start times def get_staggered_start_times(self, num_prints, total_runtime): stagger_gap = (total_runtime // num_prints) stagger_gap = (int(stagger_gap) + 4) // 5 * 5 start_times = [] for i in range(num_prints): adjusted_start_time = datetime.datetime.combine(datetime.date.today(), self.opening_time) + datetime.timedelta(minutes=i * stagger_gap) start_times.append(adjusted_start_time) return start_times # Calculate showtimes def calculate_showtimes(self): for movie in self.movies: total_runtime = movie[“runtime”] + self.preshow_time # Movie runtime + preshow time num_prints = movie[“num_prints”] auditoriums = [a.strip() for a in movie[‘auditorium’].split(‘,’)] # Get staggered start times for each auditorium start_times = self.get_staggered_start_times(num_prints, total_runtime) for i in range(len(auditoriums)): print(f”nAuditorium {auditoriums[i]}: {movie[‘name’]}”) next_start_time = start_times[i] while next_start_time < datetime.datetime.combine(datetime.date.today(), self.closing_time): end_time = next_start_time + datetime.timedelta(minutes=total_runtime + self.clean_time) if end_time.time() > self.closing_time: break showtime = next_start_time.strftime(“%I:%M %p”) print(f” Showtime: {showtime}”) next_start_time = end_time next_start_time = next_start_time + datetime.timedelta(minutes=(5 – next_start_time.minute % 5) % 5) # Testing the input gathering scheduler = MovieScheduler() scheduler.gather_inputs() # Print the final message print(“nScheduling complete!”) submitted by /u/Skoilarr [link] [comments] 

I’m making an automatic showtime scheduler for my job at a movie theater. I have been fighting with the scheduling logic and so far have it working almost as intended. The output my code is giving me looks like this:

Auditorium 1: Moana 2

Showtime: 10:00 AM

Showtime: 12:40 PM

Showtime: 03:20 PM

Showtime: 06:00 PM

Auditorium 2: Moana 2

Showtime: 10:45 AM

Showtime: 01:25 PM

Showtime: 04:05 PM

Showtime: 06:45 PM

Showtime: 09:25 PM

Auditorium 3: Moana 2

Showtime: 11:30 AM

Showtime: 02:10 PM

Showtime: 04:50 PM

Showtime: 07:30 PM

Showtime: 10:10 PM

Scheduling complete!

The one problem is that it isn’t scheduling another show in Aud 1 when there is still time. I don’t get how it is able to add the 9:25pm and 10:10pm but not an 8:40pm? Please help!

import datetime class MovieScheduler: def __init__(self): self.opening_time = None self.closing_time = None self.movies = [] self.preshow_time = 30 self.clean_time = 30 # Add movie def add_movie(self, name, runtime, num_prints, auditorium): self.movies.append({ "name": name, "runtime": runtime, "num_prints": num_prints, "auditorium": auditorium }) # Get time input def get_time_input(self, prompt): while True: try: time_input = input(prompt) return datetime.datetime.strptime(time_input, "%I:%M %p").time() except ValueError: print("Invalid time format. Please use 12-hour clock.") # Get movie details def get_movie_details(self): name = input("Enter movie name: ") while True: try: runtime = int(input("Enter movie runtime (in minutes): ")) break except ValueError: print("Invalid runtime. Please enter the runtime in minutes.") while True: try: num_prints = int(input("Enter number of prints: ")) break except ValueError: print("Invalid number of prints. Please enter a number.") auditorium = input("Enter auditorium number(s), seperated by commas: ") self.add_movie(name, runtime, num_prints, auditorium) # Gather inputs def gather_inputs(self): print("Let's set up the movie schedule.") self.opening_time = self.get_time_input("Enter opening time HH:MM AM/PM: ") self.closing_time = self.get_time_input("Enter closing time HH:MM AM/PM: ") while True: self.get_movie_details() more_movies = input("Add another movie? (y/n): ").strip().lower() if more_movies != "y": break self.calculate_showtimes() # Staggered start times def get_staggered_start_times(self, num_prints, total_runtime): stagger_gap = (total_runtime // num_prints) stagger_gap = (int(stagger_gap) + 4) // 5 * 5 start_times = [] for i in range(num_prints): adjusted_start_time = datetime.datetime.combine(datetime.date.today(), self.opening_time) + datetime.timedelta(minutes=i * stagger_gap) start_times.append(adjusted_start_time) return start_times # Calculate showtimes def calculate_showtimes(self): for movie in self.movies: total_runtime = movie["runtime"] + self.preshow_time # Movie runtime + preshow time num_prints = movie["num_prints"] auditoriums = [a.strip() for a in movie['auditorium'].split(',')] # Get staggered start times for each auditorium start_times = self.get_staggered_start_times(num_prints, total_runtime) for i in range(len(auditoriums)): print(f"nAuditorium {auditoriums[i]}: {movie['name']}") next_start_time = start_times[i] while next_start_time < datetime.datetime.combine(datetime.date.today(), self.closing_time): end_time = next_start_time + datetime.timedelta(minutes=total_runtime + self.clean_time) if end_time.time() > self.closing_time: break showtime = next_start_time.strftime("%I:%M %p") print(f" Showtime: {showtime}") next_start_time = end_time next_start_time = next_start_time + datetime.timedelta(minutes=(5 - next_start_time.minute % 5) % 5) # Testing the input gathering scheduler = MovieScheduler() scheduler.gather_inputs() # Print the final message print("nScheduling complete!") 

submitted by /u/Skoilarr
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *