Python question A physical book tittle String the title of a

Python question

A physical book tittle. String, the title of a book author. String, the author of a book year. Positive integer, the year of publication of a book Two strings and a positive integer representing a year A new object or type Book is created. The value arg 1 assorted to the state variable title, the value arg2 is assigned to the state variable author, and the value arg3 is assigned to the state variable year. That newly created Book object. getTitle String, the value of the state variable tittle get Author String, the value of the state variable author getYear Positive integer, the value of the state variable year setYear Positive integer representing a year. The state variable year is assigned the value arg1 Positive integer, the new value of year. book1 = Book(\'War and Peace\', Leo Tolstoy\', 1869) book2 = Book(\'The Wealth of Nations\', \'Adam Smith\', 1778) book1. getTittle () rightarrow \'War and Peace\' book2. get Author()rightarrow \'Adam Smith\' book2.getYear ()rightarrow 1778 book2.setYear (1776)rightarrow 1776 book2.getYear()rightarrow 1776

Solution


class Book:
title=\"\"
autor=\"\"
year=0

def __init__(self, title, autor,year):
self.title = title
self.autor = autor
self.year=year


def getTitle(self):
return self.title

def getAuthor(self):
return self.autor


def getYear(self):
return self.year


def setYear(self,y):

self.year=y

book1=Book(\"War and Peace\",\"Leo Tolstay\",1869)
book2=Book(\"The wealth of nation\",\"Adam smith\",1778)
print book1.getTitle()
print book2.getAuthor()
print book2.getYear()
book2.setYear(1776)
print book2.getYear()

==============================================================

Comment about work

Python question A physical book tittle. String, the title of a book author. String, the author of a book year. Positive integer, the year of publication of a bo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site