0

How do i create 'Employee.csv' file with following value eno, ename, department, salary.

A program with two functions, the 1st wf that will create a csv file and next function RF(N) with salary as argument. Count employees with salary more than 50000 with their names.

1st Aug 2022, 1:42 PM
Karthik Chavan
Karthik Chavan - avatar
5 Answers
+ 5
Karthik Chavan , can you show your attempt please?
1st Aug 2022, 1:53 PM
Lothar
Lothar - avatar
+ 4
Karthik Chavan , there are some issues in the code. see the attached file with your code and my comments. code is ready to run. https://code.sololearn.com/clFxw0gLKSe5/?ref=app
2nd Aug 2022, 6:14 PM
Lothar
Lothar - avatar
+ 4
Karthik Chavan , the code is ok. please make sure that you input all required data before the code is executed. 1 bob finance 20000 y 2 anne accounting 18000 n then press submit
6th Aug 2022, 7:03 PM
Lothar
Lothar - avatar
+ 1
Lothar thanks a lot. but when i ran this code, i'm not getting the desired output it's it's just returning this when finished** \myfile.py", line 21, in <module> if int(r[3]) >= 10_000: # needs to be index [3] not [2] IndexError: list index out of range what should i do??
6th Aug 2022, 12:31 AM
Karthik Chavan
Karthik Chavan - avatar
0
import csv with open("mycsv.csv", "w") as F: mywriter = csv.writer(F,delimiter = ',') ans = "y" while ans.lower() == 'y': eno = int(input("Number : ")) name = input("Name : ") dept = input("Enter department : ") salary = int(input("Salary : ")) L = [eno, name, dept, salary] mywriter.writerow(L) F.write("\n") ans = input("Add more? : ") F.close() with open ("Employee.csv", "r", newline = '') as file: ER = csv.reader(file, delimiter = ',') c = 0 for r in ER: if r[2] == 50000: c = c+1 print("Employees having more than 50000", c) else: break
1st Aug 2022, 2:13 PM
Karthik Chavan
Karthik Chavan - avatar