11) What ten values would be printed if the following code was run?
write your answer in the correct order 11a to 11j
class Pat():
def__init__(self, name, age):
self._name = name
self._age = age
def __str__(self):
return "Pet: +self._name+ " "+str(self._age)
def getName(self):
return self._name
def getAge(self):
return self._age
def setName(self,newName):
self._age =newAge
def incrementAge(self):
self._age = self._age +1
pet1 = Pet ("Fluffy" ,5)
pet2 = Pet ("Spot", 2)
print (pet1)
print (Pet.__doc__)
pet2.setName("Dot")
print(pet2.getAge())
pet1.incrementAge()
print(pet1.getAge())
pet2.setAge(4)
print(Pet.getName.__doc__)
f = open("test.dat","w")
f.write("Winter\nis almost\nover at\nlast !\n")
f.close()
f = open("test.dat" ,"r")
string = f.readline()
str1 = string.strip()
print(srt1)
string =f. readline()
str2 = string.strip()
print(str2)
str3 = str1 +" "+f.read(3)
print (str3)
string = f.readline()
str4 = string.strip()
print(str4)
f.read(1)
string = f.readline()
str4 = string.strip()
print(str4.upper())
# do comment if any problem arises
# Code has been corrected and explained in comments
class Pet():
def __init__(self, name, age):
self._name = name
self._age = age
def __str__(self):
return "Pet: "+self._name + " " + str(self._age)
def getName(self):
return self._name
def getAge(self):
return self._age
def setName(self, newName):
self._name = newName
def setAge(self, newage):
self._age = newage
def incrementAge(self):
self._age = self._age + 1
pet1 = Pet("Fluffy", 5)
pet2 = Pet("Spot", 2)
# prints Fluffy 5
print(pet1)
# prints None as no docstring is set
print(Pet.__doc__)
pet2.setName("Dot")
# prints 2 age of pet2
print(pet2.getAge())
pet1.incrementAge()
# prints 6 age of pet1
print(pet1.getAge())
pet2.setAge(4)
# prints None as no docstring is set
print(Pet.getName.__doc__)
f = open("test.dat", "w")
f.write("Winter\nis almost\nover at\nlast !\n")
f.close()
f = open("test.dat", "r")
string = f.readline()
str1 = string.strip()
# prints Winter first line of test.dat
print(str1)
string = f. readline()
str2 = string.strip()
# prints is almost second line of test.dat
print(str2)
str3 = str1 + " "+f.read(3)
# prints Winter ove
print(str3)
string = f.readline()
str4 = string.strip()
# prints r at
print(str4)
f.read(1)
string = f.readline()
str4 = string.strip()
# prints AST !
print(str4.upper())
Screenshot:


Output:

11) What ten values would be printed if the following code was run? write your answer...