[Solved] CSV Format Problem with Python

CSV Format: Sanvi is a data analyst. She is currently associated with a task where she has to display the item details in an ordered manner. All the details are in the CSV format which she to convert into the format given below in Sample Output. Help Sanvi by writing a code that takes the item details (Name, Deposit, and cost per day) in the CSV format and displays them accordingly.

   Create a class ItemType with following attributes, 

AttributesDatatype
nameString
depositInteger
costPerDayInteger

Include the methods in ItemType class

MethodDescription
display()should print the Item details as specified

   Note: Input in CSV format: (name,deposit,costPerDay)

Refer to sample input/output for other further details and format of the output.

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

Sample Input/Output 1:

Enter the details of the Item type:

Furniture,1000,200

The entered item type is:

Name : Furniture

Deposit : 1000

Cost per day: 200.0

Sample Input/Output 2:

Enter the details of the Item type:

Lights,500,25

The entered item type is:

Name : Lights

Deposit : 500

Cost per day: 25

Solution

class ItemType:
    # fill your code
    def __init__(self, name, deposit, costPerDay):
        self.name = name
        self.deposit = deposit
        self.costPerDay = costPerDay
#sauravhathi
    def display(self):
        # fill your code
        print("The entered item type is:")
        print("Name : {}".format(self.name))
        print("Deposit : {}".format(self.deposit))
        print("Cost per day: {:.0f}".format(self.costPerDay))

        #Main
details = raw_input("Enter the details of the Item type:\n")
# fill your code
details = details.split(",")
item = ItemType(details[0], int(details[1]), float(details[2]))
item.display()

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

Leave a Reply

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