[Solved] Student Details Problem with Python

Veena is a clerk in a college. She keeps the records of all the student details in her system. She is finding it difficult to manage the records manually so she contacts her friend Tina a software Engineer, to help her by writing a code that takes all the student details and displays in the ordered manner. Tina wanted to help Veena but she is not so confident in coding. Help Tina in writing code as required by Veena.   

Write a program to display the details of the Student by overriding the __str__() Method.

Create a class named Student with the following private attributes.

Data TypeVariable Name
int__id
str__username
str__password
str__name
str__address
str__city
int__pincode
int__contact_number
str__email


Use __init__() constructor to initialize the attributes with respect to class.


And this class includes the following member function. 

NoMethod NameMethod Description
1__str__()    This method, returns the student details of the current object.


Input Format:  
The first input corresponds to the student’s id.
The second input corresponds to the student’s username.
The third input corresponds to the student’s password.
The fourth input corresponds to the student’s name.
The fifth input corresponds to the student’s address.
The sixth input corresponds to the student’s city.
The seventh input corresponds to the student’s address Pincode.
The eighth input corresponds to the student’s contact number.
The ninth input corresponds to the student’s email id.

Output Format:  
All the user entered details will be displayed one by one(newline).
The details are printed inside the __str__() method.

Refer to sample input and output for formatting specifications.

[All text in bold corresponds to input and the rest corresponds to output.]
Sample input and output: 

Enter the student id

1

Enter the  student's username

nicky

Enter the password

nicky

Enter the name of the student

nicky

Enter the address

nantoor

Enter the city

mysuru

Enter the pincode

123456

Enter the contact number

1234567890

Enter the email id

nicky@gmail.com

Id :  1
User Name :  nicky
Password :  nicky
Name :  nicky
Address :  nantoor
city :  mysuru
Pincode :  123456
Contact Number :  1234567890
email :  nicky@gmail.com

Solution

class Student:
    #fill your code
    def __init__(self, id, username, password, name, address, city, pincode, contact_number, email):
        self.id = id
        self.username = username
        self.password = password
        self.name = name
        self.address = address
        self.city = city
        self.pincode = pincode
        self.contact_number = contact_number
        self.email = email


    def __str__(self):
        #fill your code
        return "Id : {}\nUser Name : {}\nPassword : {}\nName : {}\nAddress : {}\ncity : {}\nPincode : {}\nContact Number : {}\nemail : {}\n".format(self.id, self.username, self.password, self.name, self.address, self.city, self.pincode, self.contact_number, self.email)


id = input("Enter the student id\n")
usn = raw_input("Enter the student's username\n")
pa = raw_input("Enter the password\n")
na = raw_input("Enter the name of the student\n")
ad = raw_input("Enter the address\n")
ci = raw_input("Enter the city\n")
pin = input("Enter the pincode\n")
con = input("Enter the contact number\n")
ema = raw_input("Enter the email id\n")
#fill your code
s = Student(id, usn, pa, na, ad, ci, pin, con, ema)
print(s)

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saransh Saurav

Saransh Saurav

Articles: 67

Leave a Reply

Your email address will not be published. Required fields are marked *