Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please show and explain how to write these codes... Python3. There are examples.

ID: 3827355 • Letter: P

Question

Please show and explain how to write these codes... Python3. There are examples. Thanks!!

TraincapacityException class: By specifying the parent class Exception as in the example below, objects (values) of this class can be raised and caught. class TrainCapacityException (Exception) Instance variables: number int tt how many people can't fit or be unloaded from the train issue string should be either "full" or empty "full" indicates that the train was full tt "empty" indicate the error was due to the train being empty

Explanation / Answer

import math

class TrainCapacityException(Exception):
def __init__(self, number, issue="full"):
self.number = number
self.issue = issue
def __str__(self):
if self.issue == "full":
return str(self.number) + " passengers cannot be loaded because the train is full!"
else:
return str(self.number) + " passengers cannot be unloaded because the train is empty!"

class City:
def __init__(self, name, loc_x, loc_y, stop_time):
self.name = name
self.loc_x = loc_x
self.loc_y = loc_y
self.stop_time = stop_time
def __str__(self):
result = self.name + " (" + str(self.loc_x) + "," + str(self.loc_y) + "). "
minutes = self.stop_time/60.0
result += "Exchange time: " + "{0:.2f}".format(minutes) + " minutes"
return result
  
def __eq__(self, other):
return (self.loc_x == other.loc_x) and (self.loc_y == other.loc_y)
  
def distance_to_city(self, city):
distance = math.sqrt((self.loc_x - city.loc_x)**2 + (self.loc_y - city.loc_y)**2)
return distance

# pastebin code link: https://pastebin.com/9Jc87CiY

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote