Q12Numerical3 Marks22 Dec 2024
employees.csv is a CSV file that has the following contents:
EmpID,Name,Department,Salary,Years
1,John Doe,Engineering,75000,5
2,Jane Smith,Marketing,80000,3
3,Emily Johnson,Engineering,80000,7
4,Michael Brown,Sales,72000,4
5,Lisa Davis,Marketing,83000,2
6,James Wilson,Sales,74000,8
7,Alice Lee,Engineering,77000,4
8,Bob White,Sales,69000,5
9,Carol Black,Marketing,71000,6
10,David Green,Engineering,72000,3
What is the output of the following snippet of code? Enter an integer as your answer.
```
def do_something(filename, department):
file = open(filename, 'r')
file.readline()
val, count = 0, 0
for line in file:
empid, name, dept, salary, years = line.strip().split(',')
salary = float(salary)
if department == dept:
val += salary
count += 1
file.close()
return int(val / count)
print(int(do_something('employees.csv', 'Engineering')))
```
Press Enter to check.