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
Attributes | Datatype |
name | str |
username | str |
password | str |
mobile_number | int |
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.
sir i am getting in this code’
Which type of error?