#from book_shop import BookShop # THE ERRORS ARE MARKED NOT SURE HOW TO CORRECT THEM WITH THE CORRECT WORDING # ITS CODE FOR A CAR HIRE AND RENTAL COMAPANY LOOKING TO RENT OUT CARS TO PEOPLE. #Books to load from a file filename="carstxt.rtf" #Task1 Complete the Book class with attributes : title,author,publisher class CarHireRent: def __init__ (self, type, model, rating, hire, rent): self.type=type self.model=model self.rating=rating self.rent=rent self.hire=hire def description(self): return "Type: {} Model: {} Rating: {} Hire: {} Rent: {}".format(self.type,self.model,self.rating, self.hire, self.rent) class CarHireRent: def __init__(self): self.collection=[] #Task 2: load Cars from file def load_cars(self): file = open("carstxt.rtf", "r") self.collection.clear() for line in file: type, model, rating, hire, rent=line.split(",") # split the line by commas: Type,Model,Rating,hire-rate,rental-rate. self.add_cars(type, model, rating, hire, rent) file.close() # Task 3 create a car object & add car object to collection def add_car(type,model,rating,hire,rent): car=Car(type, model, rating, hire, rent) self.collection.append(car) #Task 4: # Display books in shop's collection def display_cars(self): for car in self.collection: print(car.description()) #Task 5: # Search for cars by model and display the cars list # Display (No Books by author) if there are no books matching the author def search_by_model(self,name): count=0 for cars in collection: if (cars.model == name): print(cars.description()) count+=1 if (count ==0): print("No cars by {name}") #------------------------------------------------------------------------------ def main(): print("---- Cars for Hire or Rent ----") shop=CarHireRent() shop.load_cars() #load from file print("Cars list:") shop.display_cars() print("\nSearch cars by model") name=input("\tEnter model name:") shop.search_by_cars(name) #Calling main main()
Coding error- Not sure where I have put error markers against the code that is wrong
Coding error- Not sure where I have put error markers against the code that is wrong
|
Sep-28-2020, 07:57 AM
post the full traceback you get - in error tags
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs |
|
Users browsing this thread: 1 Guest(s)