Python Forum
not finding the resone for the error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
not finding the resone for the error
#1
im currntly lerning about classs and child class and parint


class Car:
	"""a simple attempt to represent a car."""

	def __init__(self,make,model,year):
		self.make = make
		self.model = model
		self.year = year
		self.odometer_reading = 0

	def get_descriptive_name(self):
		long_name = f"{self.year} {self.make} {self.model}"
		return long_name.title()

	def read_odometer(self):
		print(f"this car has {self.odometer_reading} miles on it")

	def update_odometer(self,mileage):
		if mileage >= self.odometer_reading:
			self.odometer_reading = mileage
		else:
			print("you can't roll back an odometer !")

	def increment_odometer(self,miles):
		self.odometer_reading += miles

class ElectricCar(Car):
		"""represent aspects of a car ,specific to electric vehicles"""
	def __init__(self, make, model, year):
           """Initialize attributes of the parent class."""
           super().__init__(make, model, year)



my_tesla = ElectricCar('tesla','model s' , 2019)
print(my_tesla.get_descriptive_name())
Error:
File "C:\Users\alex8\Documents\python\python _work.py\chpter 9\electric_car.py", line 28 def __init__(self, make, model, year): ^ IndentationError: unindent does not match any outer indentation level
tenaks for the help
Reply
#2
The comment on line 27 """represent aspects of a car ,specific to electric vehicles""" is indented 8 spaces, it should be 4 spaces.
Reply
#3
(May-21-2020, 03:30 PM)Yoriz Wrote: The comment on line 27 """represent aspects of a car ,specific to electric vehicles""" is indented 8 spaces, it should be 4 spaces.

cant belive this is the error lol, i was trying to find it for an hour
Reply
#4
Think about replacing get_descriptive_name with __str__. __str__ is what print uses when it converts things to strings for printing.

It is unusual to have a lot of print statements in a class. If someone wants to use your class they don't want to worry about stuff appearing in the console when their code calls update odometer.

If it is illegal to roll back the odometer you should either disallow or raise an exception. Users of your class will not appreciate the disallow and nag approach.

If a subclass doesn't do anything differently in a method it does not have to (should not) implement the method. This is even true for __init__. It is perfectly OK to declare a class that has no methods or no attributes. It is unusual, but some people feel a need to classify things that are essentially the same.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  not finding the resone for the error yukhei 3 1,708 May-22-2020, 03:39 PM
Last Post: deanhystad
  not find the resone it not prints yukhei 3 1,745 May-22-2020, 03:36 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020