from student_kit import student_kit class student_kit():
now=200 # Numbe of working days, class attribute
def __init__(self,name,section):
self.name=name
self.section=section
def marksheet(self,mark1,mark2,mark3):
self.mark1=mark1
self.mark2=mark2
self.mark3=mark3
self.sum_marks=self.mark1 + self.mark2 + self.mark3
return mark1+mark2+mark3
def attendance(self,nop):
self.percentage_of_attendace=(nop/student_kit.now)*100
print("Name of student is {}".format(self.name))
print("No of days {} was absent is {}".format(self.name,student_kit.now-nop))
print("percentage of attendance {}".format(self.percentage_of_attendace))
def certificate(self):
print("\n\n#### Certificate #####\n")
print("Total marks obtained by",self.name, " is : ",self.sum_marks)
print(" Attendance ",self.percentage_of_attendace,"%") #access data from other methods
kalu=student_kit("Kalu","A") #object kalu is created
print("Student Name:",kalu.name," of Section :",kalu.section)
a=int(input("\n Enter maths marks: "))
b=int(input("Enter physics marks: "))
c=int(input("Enter Chemistry marks: "))
p=int(input("Enter no of days present: "))
kalu.attendance(p)
print("Total Mark ",kalu.marksheet(a,b,c))
kalu.certificate()
Keep your student_kit class in a separate file ( student_kit.py ) . Create a new file using the above code for creating three student inputs. Call the class student_kit from your new file and use the methods to show mark sheet , certificate , attendance etc for each student.Use this code in your new file to link the class.
# Create the dictionary with three students
# For each student take marks in three subjects and attendance
# For each student display certificate using student_kit.
from student_kit import student_kit
my_dict={}
for i in range(0,3):
n=input("Student Name : ")
a=int(input("\n Enter maths marks: "))
b=int(input("Enter physics marks: "))
c=int(input("Enter Chemistry marks: "))
p=int(input("Enter no of days present: "))
my_dict.update({n:[a,b,c,p]})
print(my_dict)
for i in my_dict:
obj=student_kit(i,"A") #object is created
obj.attendance(my_dict[i][3])
print("Total Mark ",obj.marksheet(my_dict[i][0],my_dict[i][1],my_dict[i][2]))
obj.certificate()
student_kit.py
class student_kit():
now=200 # Number of working days, class attribute
def __init__(self,name,section):
self.name=name
self.section=section
def marksheet(self,mark1,mark2,mark3):
self.mark1=mark1
self.mark2=mark2
self.mark3=mark3
self.sum_marks=self.mark1 + self.mark2 + self.mark3
return mark1+mark2+mark3
def attendance(self,nop):
self.percentage_of_attendace=(nop/student_kit.now)*100
print("Name of student is {}".format(self.name))
print("No of days {} was absent is {}".format(self.name,student_kit.now-nop))
print("percentage of attendance {}".format(self.percentage_of_attendace))
def certificate(self):
print("\n\n#### Certificate #####\n")
print("Total marks obtaind by",self.name, " is : ",self.sum_marks)
print(" Attendace ",self.percentage_of_attendace,"%") #access data from other methods
Tutorial on Class Object & Method
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.