Python Program 14 to 22
Python Program 14 to 22
(Fileformat: Employee No, name, deptno, basic, DA, HRA, Conveyance) should perform
below operations.
a) Print Salary Slip for given Employee Number
b) Print Employee List for Given Department Number
def print_salary_slip(employee_no):
with open("employee_data.txt", "r") as f:
for line in f:
details = line.strip().split(',')
if details[0] == str(employee_no):
print(f"Salary Slip for {details[1]}:")
total_salary = float(details[3]) + float(details[4]) + float(details[5]) + float(details[6])
print(f"Total Salary = {total_salary}")
return
print("Employee not found")
print_salary_slip(102)
Output : -
15) Write a program in python to implement Railway Reservation System using file
handling technique. System should perform below operations.
a)Reserve a ticket for a passenger.
b) List information all reservations done for today’s trains.
Output : -
pg. 8
16) Write a Python program to implement module.
# module.py :
def greet(name):
return f"Hello, {name}!"
# main.py :
import Program_16_module
print(Program_16_module.greet("Divyesh"))
Output : -
17) Write a program which will implement decorators for functions and methods in
python.
def decorator(func):
def wrapper():
print("Before function")
func()
print("After function")
return wrapper
@decorator
def say_hello():
print("Hello!")
say_hello()
Output : -
18) Write a program to read CSV file and generate output using HTML table.
import csv
html_output = "<table>"
pg. 9
for row in rows:
html_output += f"<tr><td>{row[0]}</td><td>{row[1]}</td></tr>"
html_output += "</table>"
print(html_output)
Output : -
import csv
Output : -
xml_data = "<person><name>Alice</name><age>25</age></person>"
root = ET.fromstring(xml_data)
print(root.find('name').text)
Output : -
pg. 10
21) Create Web Database Application “Address Book” with options to
a) add/ insert a record
b) modify a record
c) display a record
d) delete a record
app = Flask(__name__)
address_book = {}
@app.route('/display')
def display():
return render_template('display.html', address_book=address_book)
if __name__ == '__main__':
app.run()
Output : -
pg. 11
22) Create Web Database Application “Event Registration” with options to
a) Event Registration
b) Cancel Registration
c) display a record
app = Flask(__name__)
registrations = {}
@app.route('/')
def home():
return render_template('register.html')
@app.route('/register', methods=['POST'])
def register():
event = request.form['event']
participant = request.form['participant']
registrations[participant] = event
print(f"Registration successful for {participant} for {event}")
return f"Registration successful for {participant} for {event}"
if __name__ == '__main__':
app.run(debug=True)
Output : -
pg. 12