12th Standard Syllabus & Materials
12th Standard
TN 12th English Poem - 6 - Incident of the French Camp Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Prose - 6 - On the Rule of the Road Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Prose - 5 - The Chair Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Supplementary - 4 - The Midnight Visitor Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Poem - 4 - Ulysses Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Prose - 4 - The Summit Sample Question Papers Study Material - QB365 Set A

Published on: 14/10/2019
Python Classes and Objects
Download Tamil Nadu 12th Standard Computer Science question papers, model tests, one-mark questions, important questions, and public exam papers in PDF format. Free study materials and answer keys for TN State Board students.
Questions + Answers key
Take MCQ Computer Science Test

1.
How to define constructor and destructor in Python?
2.
What is the output of the following program?
class Greeting:
def __init__(self, name):
self.__name = name
def display(self):
print("Good Morning ", self.__name)
obj=Greeting ('Bindu Madhavan')
obj.display()
3.
Find the error in the following program to get the given output?
class Fruits:
def __init__(self, f1, f2):
self.f1 = f1
self.f2 = f2
def display(self):
print("Fruit 1 = %s, Fruit 2 = %s" %(self.f1, self.f2))
F = Fruits ('Apple', 'Mango')
del F.display
F.display()
Output: Fruit 1 = Apple, Fruit 2 = Mango
4.
Write a class with two private class variables and print the sum using a method.
5.
What are class members? How do you define it?
6.
Write a program to store product and its cost price. Display all the available products and prompt to enter quantity of all the products. Finally generate a bill which displays the total amount to be paid.
7.
Write a program to accept a string and print the number of uppercase, lowercase, vowels, consonants and spaces in the given string.
8.
Write a program to calculate area and circumference of a circle.
9.
Write a program to check and print if the given number is negative or positive using class.
10.
Write a menu driven program to add or delete stationary items. You should use dictionary to store items and the brand.
1.
Constructor :
(i) Constructor is the special function that is created. In Python, there is a special function called "init", which act as a constructor.
(ii) It must begin and end with double underscore.
General format of Constructor :
General format of _init_ method (Constructor function)
def _init_(self, [args .... ]):
<statement>
Destructor :
(ii) In Python,_del_() method is used as destructor.It is just opposite to constructor.
2.
Good Morning Bindu Madhavan.
3.
In line No.8, del F.display will not come.
4.
Code:
class Sample:
def_init_(self, n1, n2):
self._n1=nt
self_n2-n2
def sum(self):
print ("Class Variable 1:" self_n1)
print ("Class Variable 2:", self_n2)
S=Sample (5,10)
S.sum()
Output:
Class Variable 1:5
Class Variable 2: 10
Sum: 15
5.
Variables defined inside a class are called as "Class Variable" and functions are called as "Methods. Class variable and methods are together known as members of the class. The class members should be accessed through objects or instance of class. A class can be defined anywhere in a Python program.
Defining classes: In Python, a class is defined by using the keyword class. Every class has a unique name followed by a colon (:).
Syntax for Defining a Class:
class class_name:
statement_1
statement_2
....................
....................
statement_n
6.
class MyStore:
_prod_code= []
_prod_name= []
_ cost_price= []
_prod_quant= []
def getdata(self):
self.p = int(input("Enter no. of products you need to store: "))
for x in range(self.p):
self._prod_code.
append(int(input("Enter Product Code: ")))
self._prod_name.append(str(input("Enter Product Name: ")))
self._ cost_price.append(int(input("Enter Cost price: ")))
def display(self):
print("Stock in Stores")
print(" ---------------------------------- ")
print("Product Code \t Product Name \t Cost Price")
print(" ------------------------------------- ")
for x in range(self.p):
print(self._prod_code[x], "\t\t", self._prod_name[x], "\t\t", self._cos_ price [x])
print(" ---------------------------------")
def print_bill(self):
total_price = 0
for x in range( self.p):
q=int(input("Enter the quantify for the product code %d : "%self._ prod_code [x]))
self._prod_quant.append(q)
total_price = total_price +self._cost_
price[x]*self._prod_quant[x]
print(" Invoice Receipt ")
print(" --------------------------------------")
print("Product Code\t Product Name\t
Cost Price\t Quantity \t Total Amount")
print(" ------------------------------------ ")
for x in range(self.p):
print(self._prod_code[x], "\t\t", self._prod_name[x], "\t\t",
self._cost_price[x], "\t\t", self._prod_quant[x], "\t\t",
self._pro d_ quan t [x] *self._cost_price [x])
print(" -----------------------------------")
print(" Total Amount = ", total_price)
7.
Class String:
def _init_(self):
self.uppercase=()
self.lowercase=()
self.vowels=()
self.consonants=()
self.spaces=()
self.string= " "
def getstr (self):
self.string=str(input("Enter a String: "))
def count_upper(self):
for ch in self.string:
if (ch.isupper()):
self.uppercase+= 1
def count_Iowert(self):
for ch in self.string:
if (ch.islower()):
self.lowercase+= 1
def count_vowels(self):
for ch in self.string:
if (ch in ('A', 'a', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U')):
self.vowels+=1
def count_consonants(self):
for ch in self.string:
if (ch not in ('A', 'a', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U')):
self.consonants+= 1
def count_space(self):
for ch in self.string:
if (ch==" ''):
self.spaces+= 1
def execute(self):
self.count_upper()
self.count_lower ()
self.count_vowels ()
self.count_consonants()
self.count_space()
def display(self):
print("The given string contains ...")
print("%d Uppercase letters"%self. uppercase)
print("%d Lowercase letters"%self. lowercase)
print("%d Vowels"%self.vowels)
print("%d Consonants"%self.consonants)
print("%d Spaces"%self.spaces)
S = String()
S.getstr()
S.execute()
S.display()
Output:
Enter a string: Welcome To Learn Computer Science
The given string contains...
5 Uppercase letters
24 Lowercase letters
13 vowels
20 consonants
4 Spaces
8.
class Circle:
pi=3.14
def _init_(self.radius):
self.radius=radius
def area(self):
return Circle. pi*(self.radius**2)
def circumference(self):
return 2*Circle.pi*self.radius
r=int(input("Enter Radius: "))
Ce=Circle(r)
print("The Area =",C.area())
print("The Circumference =", Cxircumferencet())
9.
class test;
def check (self, num)
if num> 0:
print (num, "is positive number")
else:
print (num, "is negative number")
n = test ()
x = int (input("Enter the number"))
n. check (x)
10.
class Mystore:
_prod_code = [ ]
_prod_name = [ ]
_cost price = [ ]
_prod quant = [ ]
def getdata(self):
selt.p= int (input ("Enter no. of products you need to store:"))
for x in range (self.p):
self._prod_code. append (int (input ("Enter Product Code:")))
self._prod_name. append (str (input ("Enter Product Name:"))
self._ cost_price. append (int (input ("Enter cost price:"))
def display (self):
print ("stock in stores")
print ("---------------------")
print ("Product Code\t Product name\t cost price")
print ("------------------")
for x in range (self.p):
print (self._prod_code [x], "\t\t", self._prod_name [x], "It \t", self._cost price [x])
print ("------------------------------")
def print_bill (self):
total_price =0
for x in range (self.p):
q= int(input("Enter the quantity for the product code %d:" %self._prod_code [x]))
self. Prod_quant.append (q)
total_price = total_price + self. _cost_price|x]* self._prod_quant [x]
print ("Invoice Receipt")
print ("---------------")
print ("Product Code\t Product Name\t Cost Price\t Quantity\t Total Amount")
print ("----------------")
for x in range (self.p):
print (self._Prod_code [x), "\t \t", self_prod-name[x], "\t \t",
self._cost_price[x], "\t \t", self._prod-quant [x], "\t \t",
self._prod_quant[x]*self._cost price [x])
print ("-------------------")
print ("Total Amount =", total_price")
S=Mystore ()
S.getdata ()
S.display ()
S.print_bill ()
Output:
Enter no. of products you need to store: 5
Enter Product code: 101
Enter Product Name: Notebook
Enter cost price: 25
Enter Product code: 201
Enter Product Name: pencil
Enter cost price: 35
Enter Product code: 301
Enter Product Name: Pen
Enter cost price: 35
Enter Product code: 401
Enter Product Name: Colour Pencils
Enter cost price: 50
Enter Product code: 501
Enter Product Name: Sketches
Enter cost price: 120
Stock in stores
| Product Code | Product Name | Cost Price |
| 101 | Notebook | 25 |
| 201 | Pencil | 35 |
| 301 | Pen | 35 |
| 401 | Colour pencils | 50 |
| 501 | Sketches | 120 |
Enter the quantity for the product code 101:10
Enter the quantity for the product code 201:15
Enter the quantity for the product code 301:10
Enter the quantity for the product code 401:20
Enter the quantity for the product code 501:10
Invoice Receipt
| Product Code | Product Name | Cost Price | Quantity | Total Amount |
| 101 | Notebook | 25 | 10 | 250 |
| 201 | Pencil | 35 | 15 | 525 |
| 301 | Pen | 35 | 10 | 350 |
| 401 | Colour pencils | 50 | 20 | 1000 |
| 501 | Sketches | 120 | 10 | 1200 |
| Total amount = 3325 |
12th Standard Syllabus & Materials
12th Standard
TN 12th English Supplementary - 3 - The Hour of Truth (Play) Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Poem - 3 - All the World’s a Stage Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Prose - 3 - In Celebration of Being Alive Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th English Supplementary - 2 - Life of Pi Sample Question Papers Study Material - QB365 Set A
Tamilnadu Stateboard 12th Standard Subjects

Maths

Chemistry

Physics

Biology

Computer Science

Business Maths and Statistics

Economics

Commerce

Accountancy

History

Computer Applications

Biology

Computer Technology

Computer Applications

Computer Science

Business Maths and Statistics

Commerce

Economics

Maths

Chemistry

Physics

Computer Technology

History

Accountancy

Tamil

English

French
Tamilnadu Stateboard Standards