Python Forum
University Assignment Help needed
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
University Assignment Help needed
#2
The error is because when you are trying to create your bookObj:
bookObj=book(p,t,pr,i,a)
you are giving it too many arguments, but based on your init method it has only 1 argument 'self'
class book(publication):
    def __init__(self):
        publication.__init__(self)
Also In your assingment it is stated, that your init() methods should initialize string member variables to empty strings and numeric values to 0, and your Book class should also have overriding populate() and display() methods which you are missing. So together with everything else I got something like this(Hopefuly you are working with python 3.6, otherwise the print statements in display() methods are not going to working for you):
class Publication:
    def __init__(self):
        self.publisher = ''
        self.title = ''
        self.price = 0

    def populate(self, publisher, title, price):
        self.publisher = publisher
        self.title = title
        self.price = price

    def display(self):
        print(f'Publisher: {self.publisher}')
        print(f'Title: {self.title}')
        print(f'Price: R{self.price:.2f}') # formatted to display 2 decimals


class Book(Publication):
    def __init__(self):
        Publication.__init__(self)
        self.ISBN = 0
        self.authorname = ''

    def populate(self, publisher, title, price, ISBN, authorname):
        Publication.populate(self, publisher, title, price)
        self.ISBN = ISBN
        self.authorname = authorname

    def display(self):
        Publication.display(self)
        print(f'ISBN: {self.ISBN}')
        print(f'Authorname: {self.authorname}')


publisher = input('Enter Publisher Name: ')
title = input('Enter Title: ')
price = int(input('Enter Price: '))
isbn = int(input('Enter ISBN number: '))
author = input('Enter Author Name: ')

bookObj = Book()  # here you create Book object -> initialise the variables either as empty string or 0
bookObj.populate(publisher, title, price, isbn, author) # here you rewrite these empty strings and 0 to values from the inputs

print('The Details Of The Book Are:')
bookObj.display() # and this method displays all the values
Reply


Messages In This Thread
University Assignment Help needed - by Diovanno - Apr-10-2018, 11:58 AM
RE: University Assignment Help needed - by mlieqo - Apr-10-2018, 02:24 PM
RE: University Assignment Help needed - by Larz60+ - Apr-10-2018, 02:36 PM
RE: University Assignment Help needed - by Diovanno - Apr-10-2018, 02:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] University Assignment Help needed Nomathemba 4 4,145 Apr-20-2024, 12:24 PM
Last Post: jas31
Lightbulb Python University Laboratory - Help camibaldessini 3 1,487 Nov-03-2023, 01:28 PM
Last Post: Garrypyton
  Help with university work - reading and writing files MrKnd94 3 1,393 Nov-01-2022, 08:29 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