Hey everyone, I needed some slight help with this the first two images are examples/general ideas of what my professor wants. I have trouble with OOP sometimes. Right now I think I have some attributes set up and a class. I really want to make a train with attributes and to make inputs like in the examples. Im just a tad bit confused and I just need some slight guidance. - Thanks
#OOP help
49 messages · Page 1 of 1 (latest)
Looks like you're on the right track
(pun not intended)
Think about what actions your train can take (i.e. the methods of the train)
and try implement those
It's simple really
I also want to be able to add an input that lets you add the conductor name, train model, passenger count, speed and color
wdym?
Adding methods
I know but I can't call them when I try
You will need to create an object
Example?
Something like
class Train:
def __init__(self, name, destination, num_cars, speed):
self.name = name
self.destination = destination
self.num_cars = num_cars
self.speed = speed
def accelerate(self, amount):
self.speed += amount
def decelerate(self, amount):
self.speed -= amount
def display_info(self):
print("Train Name:", self.name)
print("Destination:", self.destination)
print("Number of Cars:", self.num_cars)
print("Speed:", self.speed)
my_train = Train("Express", "Chicago", 10, 50)
my_train.accelerate(10)
my_train.display_info()
Speed should be kept as floats or integers
Ohhh as a f string type deal
How do I get the said info to lineup?
Good news is that I got it all to line up pretty well
Im just wondering how I can start the accelerating and decelerating part of it
You could do it that way
Kinda minor update
I got a hypothetical where it goes to the main place
Also a if derailment and stop with a break
@shadow kayak
You guys can mess with it and see what I can add to make it look and work kinda better
If you want
I want it to look a bit better ig
That depends on you and how you want to print the stuff out
Its hard to explain my idea
@shadow kayak
You look at it and see what I can change
I guess im looking for critique functionally as well @weak cosmos
@weak cosmos well?
It's not too bad
A little bit badly formatted but functionally it should still run correctly
Just make sure it satisfies your requirements
How should I format it better?
I do ask though @weak cosmos
If I wanted to format it to use user_inputs for the attributes, how would I do that?
I referred to formatting as in following PEP8