-
Notifications
You must be signed in to change notification settings - Fork 0
Update sal_json.py #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
| self.emp_id = emp_id # Error: Wrong attribute name (self.emp_id should be self.employee_id) | ||
|
Comment on lines
+6
to
+7
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggested comment: |
||
| position=row['position'], | ||
| salary=float(row['salary']) | ||
|
|
@@ -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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggested comment: SyntaxError: expected an indented block |
||
| output_file = 'employees.json' # Error: Incorrect indentation | ||
|
Comment on lines
+48
to
+49
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
|
||
There was a problem hiding this comment.
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