Jan-26-2018, 08:03 AM
Hi.
I'm new to programming and Python, but I do enjoy learning as much as I can.
I started play around with classes in Python and get the most basic stuff.
But I would like some help to get the code even better. And more readable.
Most variables and words are in swedish.
My code first creates vehicles and one motorcycle.
Then I can do stuff to theese class objects.
I can get the miltal (mileage), inköpspris (buy-price).
I can also calculate the säljpris (sell-price) and service (repairs) in separate functions.
I'm new to programming and Python, but I do enjoy learning as much as I can.
I started play around with classes in Python and get the most basic stuff.
But I would like some help to get the code even better. And more readable.
Most variables and words are in swedish.
My code first creates vehicles and one motorcycle.
Then I can do stuff to theese class objects.
I can get the miltal (mileage), inköpspris (buy-price).
I can also calculate the säljpris (sell-price) and service (repairs) in separate functions.
class fordon(): hjul = 2 #Standardvariabel def __init__(self, märke, modell, inköpspris, miltal): self.märke = märke self.modell = modell self.inköpspris = inköpspris self.miltal = miltal class bil(fordon): hjul = 4 def spec(self, doors, hp): self.doors = doors self.hp = hp class mc(fordon): def spec(self, hp): self.hp = hp #Funktion som räknar ut säljpris def sälj(object): if object.miltal > 3000: return object.inköpspris * 1.10 else: return object.inköpspris * 1.20 def service(object): if object.miltal > 12000: return '{} {}{}'.format(object.märke, object.modell, " behöver service") else: return '{} {}{}'.format(object.märke, object.modell, " behöver inte service än") bil_1 = bil("Audi", "A8", 10000, 4000) mc_1 = mc("Yamaha", "R1", 10000, 2000) bil_2 = bil("Volvo", "XC70", 20000, 3342)All the help I can get would be worth alot.
