Name Comparision: Ram works in sales department where he has to check the items and vendors names and make a list of same items and different items. He thought doing it manually doing it will consume more time and energy. So he asks Chandan, his friend who works as software engineer to write a code that compares the names of the items and tell whether they are same or different. Chandan starts writing the code but he needs help to code. Help Chandan to write a python code as Ram requires.
Create Item class in ‘Item.py’ with following attributes
Attributes Datatype name str vendor str
Override equals method eq() in Item class and compare Item name(ignore case)
Get the Inputs in and print the output in ‘Main.py’.
Name Comparision Problem
Input format:
Input consists of 4 strings indicating Item-1 and its vendor, Item-2 and its vendor. Create two different objects for Item and comapre the Item’s name.
Output format:
The output displays "Both Items are same" if the item names are same. And displays"Items are different" if they are different
Print the output statement in Main class ‘Main.py’.
Refer Sample input and output for better understanding.
All text in Bold refers to input and rest correspond to output.
Sample Input/Output-1:
Enter item 1 Item name: Wallet Vendor name: PaulRaj Enter item 2 Item name: Wallet Vendor name: paulraj Both items are same
Sample Input/Output-2:
Enter item 1 Item name: Helmet Vendor name: karthi Enter item 2 Item name: milk Vendor name: velmurugan Items are different
Solution
class Item:
def __init__(self, name, vendor):
self.name = name
self.vendor = vendor
def __eq__(self, other):
return self.name.lower() == other.name.lower()
# sauravhathi
from Item import Item
item1 = Item(input("Enter item 1\nItem name: "), input("Vendor name: "))
item2 = Item(input("Enter item 2\nItem name: "), input("Vendor name: "))
if item1 == item2:
print("Both items are same")
else:
print("Items are different")
Happy Learning – If you require any further information, feel free to contact me.
Can u plZ help me this code I need item.py and main.py program
Code updated.
Item.py and Main.py
sir i am getting error can i get ur whatsapp number
https://t.me/sauravhathi_yt_discussion
sir i am getting error
sir give me ur whatsapp number
https://t.me/sauravhathi_yt_discussion