[Solved] Duplicate User Problem with Python

Duplicate User: Tina works in a consultancy, and she was currently associated with the task where she had to remove the duplicate users from the list by comparing the phone numbers of the users. She thought writing code as per the requirement would make her work easier. So she asks one of her friends, to write a code for her. Imagine you are Tina’s friend, help her by writing the code as it is required. 

Write a Python code to check duplicate user details. There can be only one user with a specific mobile number. If two users exist with the same mobile number they are duplicate. Check whether user information is the same or not by overriding the equals method.

Create a User class with the following attributes 

AttributesDatatype
namestr
usernamestr
passwordstr
mobile_numberint

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

Override __eq__() method that compares mobile_number of the two objects.

Input format :

Input consists of 2 userโ€™s details, which contains (name, username, password, mobile_number).

Output format :

The output is a string value, denoting whether the users were same or not by comparing the mobile number of the user.

[All Texts in bold corresponds to the input and rest are output] 

Sample Input and Output – 1:
Enter the details of User 1
Name :
Meena
Username :
Meena2020
Password :
Basic
Mobile Number :
1234567890
Enter the details of User 2
Name :
Meena
Username :
Meena1010
Password :
Probob
Mobile Number :
0987654321
User 1 and User 2 are not equal

Sample Input and Output – 2:
Enter the details of User 1
Name :
Vasu
Username :
Va450
Password :
particles
Mobile Number :
9894098490
Enter the details of User 2
Name :
Vasu
Username :
Vasavi
Password :
500
Mobile Number :
9894098490
User 1 and User 2 are equal

Solution

class Test(object): 
 
    #fill your code 
    def __init__(self, n1, un1, p1, mn1): 
        self.name=name 
        self.user_name=user_name 
        self.password=password 
        self.number=number 
 
    def __eq__(self, other):  
        #fill your code 
        return (self.number)==(other.number) 
  
 
#Main        
print"Enter the details of User 1" 
n1=raw_input("Name :\n") 
un1=raw_input("Username :\n") 
p1=raw_input("Password :\n") 
mn1=input("Mobile Number :\n") 
 
print"Enter the details of User 2" 
n2=raw_input("Name :\n") 
un2=raw_input("Username :\n") 
p2=raw_input("Password :\n") 
mn2=input("Mobile Number :\n") 
 
#fill your code 
if n1==n1 and mn1==mn2: 
    print("User 1 and User 2 are equal") 
else: 
    print("User 1 and User 2 are not equal")

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

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

๐Ÿ“Œ Nodejs and Android ๐Ÿ˜Ž
๐Ÿ“Œ Java

Articles: 444

2 Comments

Leave a Reply

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