Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions sal_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import json
import csv

class Employee:
def __init__(self, employee_id, name, position, salary):
self.employee_id = employee_id
class Emplyee: # Error: Typo in class name
def __init__(self, emp_id, name, position, salary): # Error: Wrong parameter name (emp_id should be employee_id)
Comment on lines +5 to +6

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment:
Input: def give_rais(self in 5

self.emp_id = emp_id # Error: Wrong attribute name (self.emp_id should be self.employee_id)
Comment on lines +6 to +7

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: self.employee_id = emp_id in 6

self.name = name
Comment on lines +7 to 8

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: self.employee_id = emp_id in 7

self.position = position
self.salary = salary
Expand All @@ -14,7 +14,7 @@ def give_raise(self, amount):

def to_dict(self):
return {
'employee_id': self.employee_id,
'employee_id': self.emp_id, # Error: Wrong attribute name (self.emp_id should be self.employee_id)
'name': self.name,
Comment on lines +17 to 18

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: 'employee_id': self.employee_ in 17

'position': self.position,
'salary': self.salary
Expand All @@ -29,8 +29,8 @@ def read_employees_from_csv(file_path):
reader = csv.DictReader(file)
for row in reader:
try:
employee = Employee(
employee_id=row['employee_id'],
employee = Emplyee( # Error: Typo in class name
emp_id=row['employee_id'], # Error: Wrong parameter name (emp_id should be employee_id)
Comment on lines +32 to +33

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: NameError: name 'Emplyee' is in 32

name=row['name'],
Comment on lines +33 to 34

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment:
Input: name=row['name'], in 33

position=row['position'],
salary=float(row['salary'])
Expand All @@ -44,18 +44,19 @@ def save_employees_to_json(employees, output_file):
with open(output_file, 'w') as file:
json.dump([employee.to_dict() for employee in employees], file, indent=4)

def main():
input_file = 'employees.csv'
output_file = 'employees.json'
def main(): # Error: Missing indentation for this function
input_file = 'employees.csv' # Error: Incorrect indentation
Comment on lines +47 to +48

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: SyntaxError: expected an indented block
Input in 47

output_file = 'employees.json' # Error: Incorrect indentation
Comment on lines +48 to +49

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: IndentationError: expected an indented block in 48


Comment on lines +49 to 50

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: IndentationError: expected an indented block in 49

try:
employees = read_employees_from_csv(input_file)
employees = read_employees_from_csv(input_file) # Error: Incorrect indentation
for employee in employees:
Comment on lines +52 to 53

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: employees = read_employees_from_csv in 52

employee.give_raise(5000) # Give each employee a raise
save_employees_to_json(employees, output_file)
print(f"Employee data has been saved to {output_file}")
employee.give_raise(5000) # Error: Incorrect indentation
save_employees_to_json(employees, output_file) # Error: Incorrect indentation
Comment on lines +54 to +55

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: employee.give_raise(500 in 54

print(f"Employee data has been saved to {output_file}") # Error: Incorrect indentation
Comment on lines +55 to +56

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: save_employees_to_json(employees in 55

except Exception as e:
Comment on lines +56 to 57

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: print(f"Employee data has been saved in 56

print(f"An error occurred: {e}")
print(f"An error occurred: {e}") # Error: Incorrect indentation

Comment on lines +58 to 59

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: An error occurred: {e} # Error in 58

if __name__ == "__main__":
main()