Wednesday, February 21, 2018

Program Classes and Objects

Tags

Write a program by creating objects to display student information


Code:

class Student:
    def __init__(self,name,c,rollno,phone,address):
        self.name=name
        self.c=c
        self.rollno=rollno
        self.phone=phone
        self.address=address

    def display(self):
        print('Name : ',self.name)
        print('Class : ',self.c)
        print('Roll No : ',self.rollno)
        print('Phone : ',self.phone)
        print('Address : ',self.address)
        print()


def main():
    john=Student('John','D3CSEA1',1507567,9023074222,'Ludhiana')
    john.display()
    print('********************','\n')
    jennie=Student('Jennie','D3CSEA2',1507542,8725053420,'Patiala')
    jennie.display()


main()

Output: