[Solved] Event Details write using Python

Event Details write: Create Event class with following attribute.

AttrDataType
namestr
hall_namestr
contactstr
costint
leaderstr

Use __init__() method for initializing the above class attributes.

Create following methods inside Event class.

MethodDescription
display()This method is used to print the details of the event.

Event Details write

 
Input Filename : event.txt

EXAMPLE:
Details are stored as comma separated values(name,detail,contact,leader,cost) in event.txt file.
Write a program to read the input file and get the number of events to be added, then write the details in the input file after getting from the user by seeking the file.Display the added event details along with the details in that input file, in console.
 
Sample Input:
Enter the number of event to be added
1
Project Success party,Family get together,8097654321,Shashi,55000.00
 

 
Sample Output:

Enter the number events to be added
Event:Birthday party 
Hall booked:Ashoka hotel 
Lead:Shashi 
Cost:25000.00 

Event:Marraige 
Hall booked:Chandra mahal 
Lead:Prasanna 
Cost:75000.00 

Event:Promotion party 
Hall booked:Aliya convention hall 
Lead:prasad 
Cost:60000.00 

Event:Engagement 
Hall booked:Ramakrishna Gruha 
Lead:Siddu 
Cost:40000.00 

Event:Project Success party 
Hall booked:Family get together 
Lead:Lakshmi 
Cost:55000.00

Solution:

class Event:
    def __init__(self,name,hall_name,contact,leader,cost):
        self.name=name
        self.hall_name=hall_name
        self.contact=contact
        self.leader=leader
        self.cost=cost

    def display(self):
        print("Event:",self.name)
        print("Hall booked:",self.hall_name)
        print("Contact:",self.contact)
        print("Leader:",self.leader)
        print("Cost:",self.cost)
from Event import Event

n = int(input())
val = input().split(',')
e = Event(val[0],val[1],val[2],val[3],val[4])
print()

with open("event.txt","a") as f:
    f.write(str(e.name)+","+str(e.hall_name)+","+str(e.contact)+","+str(e.leader)+","+str(e.cost)+"\n")
print("Enter the number events to be added")
with open("event.txt", "r") as f:
    for line in f:
        line = line.strip()
        line = line.split(",")
        event = Event(line[0], line[1], line[2], line[3], line[4])
        event.display()
        print()

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 *