St. Britto Hr. Sec. School - Madurai
12th Computer Science Weekly Test - 2 ( Python Classes and objects )-Aug 2020
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Write a menu driven program to add or delete stationary items. You should use dictionary to store items and the brand.
-
Write a menu driven program that keeps record of books available in you school library.
-
Program to find total and average marks using class
class Student:
mark1, mark2, mark3 = 45, 91, 71 #class variable
def process(self): #class method
sum = Student.mark1 + Student.mark2 + Student.mark3
avg = sum/3
print("Total Marks = ", sum)
print("Average Marks = ", avg)
return
S=Student()
S.process()
In the above program, after defining the class, an object S is created. The statement S.process( ), calls the function to get the required output.
Note that, we have declared three variables mark1, mark2 and mark3 with the values 45, 91, 71 respectively. We have defined a method named process with self argument, which means, we are not going to pass any value to that method. First, the process method adds the values of the class variables, stores the result in the variable sum, finds the average and displays the result.
Thus the above code will show the following output -
Write a program to check and print if the given number is negative or positive using class.