1.

Write a program using class to store name and marks of students in list and print total marks?

Answer»

class stud:

def_init_(self):

self.name= ” ”

self.m1=0

self.m2=0

self.tot=0

def gdata(self):

self.name = input(“Enter your name”)

self.m1 = int(input(“Enter marks 1”))

self.m2 = int(input(“Enter marks2”))

self, tot = self.m1+self.m2

def disp(self):

print(self.name)

print(self.m1)

print(self.m2)

print(self.tot)

mlist = [ ]

st = stud( )

st.gdata( )

mlist. append(st)

for x in mlist:

x.disp( )

Output:

Enter your name Ram

Enter marks 1 100

Enter marks2 100

Ram 100 100 200



Discussion

No Comment Found