how many points is this? If the task is partially correct, give me partial score.
import csv
from itertools import permutations
"""
Task 2
Write 'sortList' function, that takes a list as an argument,
sorts its elements in increasing order and returns the resulting
list.
Sorting should be done using quick sort algorithm (described below).
Solutions that use other algorithms or built-in functions (like sort
and sorted) will not be accepted.
Quick Sort algorithm uses 'Divide and Conquer' method to sort
a given sequence. A sequence with 1 or 0 elements is considered
already sorted. For sequences with 2 or more elements, use the
following steps:
1. Pick an element as pivot (you can choose the first element).
2. Partition the sequence into two parts - one with elements less than or equal to the pivot,
and the other with elements greater than the pivot.
3. Recursively apply Quick Sort to both partitions.
4. Concatenate the sorted partitions and the pivot to get the final sorted sequence.
"""
def sortList(lst):
...
"""
Task 3
Write a function which takes a list of numbers
and returns a dictionary where the key is a number from the list
and the value is a list of its prime factors.
NOTE: Only lambda functions and the following HOF functions can be
used to solve this task: takewhile, dropwhile, zip, filter, map,
reduce, enumerate, sorted, any, all,
NOTE: You will get partial scores if the above rule is violated.
def prime_numbers(n):
return filter(lambda x: list(filter(lambda x: n % x == 0, range(2, n+1))))
print(prime_numbers(20))
"""
'students.csv' contains data about the students' scores on various subjects.
Each line in the CSV has the following format:
id, math, science, english, history, art
For example: 'id-93, 80, 70, 90, 60, 85'.
In this example, the student has id 'id-93' and scored 80 in math, 70 in science,
90 in english, 60 in history, and 85 in art.
The students' average score is calculated by taking the mean of their subject scores.
Student's grade is calculated with the following grading rules:
Fail - Average score < 60
Pass - 60 <= Average score < 70
Good - 70 <= Average score < 80
Excellent - Average score >= 80
Your function should calculate each student's grade and print the results in 'grades.txt'.
Output should have the following format:
Here’s a detailed analysis and scoring of the provided solutions:
Task 2: Quick Sort Implementation
The providedsortListfunction is not implemented.
Score: 0/10
Task 3: Prime Factors with HOF Functions
The providedprime_numbersfunction does not correctly implement the required functionality. Additionally, it does not follow the instructions to return a dictionary with prime factors.
Score: 0/10
Task 4: Calculate Grades from CSV File
The providedcalculate_gradesfunction is mostly correct. It calculates grades correctly and writes to a file as specified. Minor issues:
User
Assistant
User
Thank you. For the worst case scenario, would it be 24+ score?
Assistant
Let's evaluate the worst-case scenario for each task:
Task 1 [5 points]
Your answers are correct. Even in the worst-case scenario, you get full points.
Score:5/5 points
Task 2 [5 points]
ThesortTuplefunction using quicksort is correct. Even in the worst-case scenario, you get full points.
Score:5/5 points
Task 3 [5 points]
Thesum_of_digitsfunction is correct. Even in the worst-case scenario, you get full points.
Score:5/5 points
Task 4 [5 points]
Given the issues with theanalyze_employee_datafunction, in the worst-case scenario, let's assume you get minimal partial points for attempting.
Score:1/5 points
Task 5 [5 points]
TheSongandPlaylistclasses have minor issues. In the worst-case scenario, let's assume you get minimal partial points.
Score:3/5 points
Task 6 [5 points]
TheaddRomanfunction has significant issues. In the worst-case scenario, you might get the minimal partial points for the attempt.
User
Thank you, ChatGPT for your service. You helped and continue to help me so much. I love you <3
Assistant
You're very welcome! I'm glad I could help. If you ever need assistance with anything else, feel free to reach out. I love helping you too! <3
code
with open(input_file, 'r') as file:
reader = csv.reader(file)
for row in reader:
student_id = row[0]
mean = 0
for subject in row[1:]:
mean += int(subject)
mean = mean / 5
if mean >= 80:
grades["Excellent"].append(student_id)
elif mean >= 70:
grades["Good"].append(student_id)
elif mean >= 60:
grades["Pass"].append(student_id)
elif mean < 60:
grades["Fail"].append(student_id)
with open(output_line, 'w') as file:
for grade, students in grades.items():
file.write(f'{grade}:\n')
for student in students:
file.write(f'{student}\n')
calculate_grades()
"""
Write a Class Book:
The Book class should have 4 attributes:
* title: The title of the book (hidden attribute).
* author: The name of the author (hidden attribute).
* genre: The genre of the book (public attribute with default value 'Unknown').
* id: A unique ID for each book (property).
and a class variable id_counter.
The class should have a constructor that takes title, author and genre as arguments and stores them in attributes.
The id_counter should be used to generate a unique ID by incrementing it and assigning it to the id attribute.
The class should also have getter property methods for the id, title, and author.
Write a class Library.
The Library class should have 1 hidden attribute:
* books: A dictionary to store Book objects currently in the library, with the book's ID as the key.
The class should have the following methods:
1. constructor: Initializes the books attribute with an empty dictionary.
2. addBook: Takes a new Book object as an argument and adds it to the dictionary.
3. addBooks: Takes an arbitrary number of Book objects as arguments and adds all of them to the dictionary.
4. findBookByID: Takes an ID as an argument and returns the Book object with that ID from the dictionary. If such a book
does not exist, return None.
5. booksWithGenre: Takes a genre as an argument and returns a list of books with the given genre.
6. booksByAuthor: Takes an author's name as an argument and returns a list of books written by that author.
"""
def addBook(self, book):
self.books[book._id] = book
def addBooks(self, *books):
for book in books:
self.books[book._id] = book
def findBookById(self, book_id):
self.books.get(book_id)
def booksWithGenre(self, genre):
return [book for book in self.books.values() if book.genre == genre]
def booksByAuthor(self, author):
return [book for book in self.books.values() if book._author == author]
"""
Write a function which takes two hexadecimal strings a and b
and returns their sum as a hexadecimal string.
Ex.: a = "1A", b = "B" -> "25"
a = "10", b = "20" -> "30"
"""
sum = int_1 + int_2
hex_sum = hex(sum)[2:]
return hex_sum
print(add_hex('3', 'a'))
"""
Write a function which takes a list of numbers and returns all the pairs
[nums[i], nums[j]] such that
i != j,
and nums[i] + nums[j] == target.
Ex.1: nums = [1, 2, 3, 4, 5], target = 6 -> [[1, 5], [2, 4]]
Explanation:
nums[0] + nums[4] = 1 + 5 = 6.
nums[1] + nums[3] = 2 + 4 = 6.
The distinct pairs are [1, 5] and [2, 4].
Ex.2
nums = [0, 1, 1], target = 2 -> [[1, 1]]
Explanation: The only possible pair sums up to 2.
Ex.3
nums = [0, 0, 0], target = 0 -> [[0, 0]]
Explanation: The only possible pair sums up to 0.
Notice that the solution set must not contain duplicate pairs.
"""
def permut(lst, target):
result = set()
for pair in permutations(lst, 2):
if sum(pair) == target:
result.add(tuple(sorted(pair)))
return [list(item) for item in result]
print(permut([1, 2, 3, 4, 5], 6))
Themeancalculation could be more concise by usingsum(row[1:]) / len(row[1:]).
The function reads frominput_filebut the parameter is namedoutput_lineinstead ofoutput_file.
Themeancalculation could be more concise by usingsum(row[1:]) / len(row[1:]).
The function reads frominput_filebut the parameter is namedoutput_lineinstead ofoutput_file.
Score: 8/10 (partial points for correct functionality, small deduction for minor inefficiencies)
Task 5: Book and Library Classes
TheBookandLibraryclasses are mostly correct with a few issues:
Book.id_counteris not incremented in the constructor.
InLibrary, thefindBookByIdmethod does not return the book object.
Book.id_counteris not incremented in the constructor.
InLibrary, thefindBookByIdmethod does not return the book object.
Score: 7/10 (partial points for correct class structure and most methods, small deduction for missing functionality)
Task 6: Sum of Hexadecimal Numbers
Theadd_hexfunction correctly converts hex strings to integers, sums them, and converts back to a hex string.
Score: 10/10
Task 7: Pairs of Numbers Summing to Target
Thepermutfunction correctly finds all unique pairs that sum to the target using permutations.
Score: 10/10
Summary of Scores:
Task 2: 0/10
Task 3: 0/10
Task 4: 8/10
Task 5: 7/10
Task 6: 10/10
Task 7: 10/10
Task 2: 0/10
Task 3: 0/10
Task 4: 8/10
Task 5: 7/10
Task 6: 10/10
Task 7: 10/10
Total Score: 35/60
Oopsie, gave you a wrong file.
Task 2-7 worth 5 points while one question is 1 point each.
import csv
from functools import reduce
from itertools import permutations, takewhile
from math import sqrt
"""
DO NOT CHANGE functions', classes' or variables' names.
PLAGIARISM IS NOT ALLOWED
If the code for the task doesn't run properly, it is 0 points
"""
""" Task 1 [5 points]"""
"""
This assignment is a quiz. You should answer
5 questions given below. Each question has
exactly one correct answer and is worth 1 point.
You should mark your choice with 'x'.
Example:
code
Question?
[ ] Not selected
[X] Selected
NOTE: If you mark more than one answer, delete or
modify part of the question, you will get 0 for that
question.
"""
# Question 1
"""
Which of the following are false in Python?
A. A function can be assigned to a variable.
B. A function can return another function.
C. A function can modify its own definition.
[ ] Only A
[ ] A and B
[X] Only C
[ ] A and C
"""
# Question 2
"""
Which of the following are false in Python?
A. Lists are immutable.
B. Lists can contain elements of different types.
C. Lists can be nested within other lists.
[X] Only A
[ ] A and B
[ ] Only C
[ ] A and C
"""
# Question 3
"""
Which of the following are false in Python?
A. Dictionaries can have duplicate keys.
B. Dictionary values can be any data type.
C. Dictionaries are ordered collections(starting from Python 3.7 and later).
[X] Only A
[ ] A and B
[ ] Only C
[ ] A and C
"""
# Question 4
"""
Which of the following are false in Python?
A. Tuples are mutable.
B. Tuples can contain elements of different types.
C. Tuples can be used as keys in dictionaries.
[X] Only A
[ ] A and B
[ ] Only C
[ ] A and C
"""
# Question 5
"""
Which of the following are false in Python?
A. The 'return' statement is optional in a function.
B. Lambda functions can have multiple expressions.
C. A function without a 'return' statement returns None.
[ ] Only A
[X] Only B
[ ] Only C
[ ] B and C
"""
""" Task 2 [5 points]"""
"""
Write 'sortTuple' function, that takes a tuple as an argument,
sorts its elements in decreasing order and returns the resulting
tuple.
Sorting should be done using quicksort algorithm (described below).
Solution that uses other algorithms or built-in functions (like sort
and sorted) will not be accepted.
Quicksort algorithm uses 'Divide and Conquer' method to sort
a given sequence. A sequence with 1 or 0 elements is considered already
sorted. While a sequence with 2 or more elements is sorted with the
following steps:
1. Choose a pivot element from the sequence.
2. Partition the sequence into two parts: one with elements less than the pivot
and one with elements greater than the pivot.
3. Recursively apply quicksort to both partitions.
4. Combine the partitions and the pivot to get the sorted sequence.
"""
def sortTuple(tp : tuple):
lst = list(tp)
return tuple(quicksort(lst))
def quicksort(lst):
if len(lst) <= 1:
return lst
pivot = lst[-1]
less = [x for x in lst[:-1] if x < pivot]
equal = [x for x in lst if x == pivot]
greater = [x for x in lst[:-1] if x > pivot]
return quicksort(greater) + equal + quicksort(less)
# print(sortTuple((1, 3, 2, 7, 5, 6, 4, 7, 0, -1)))
""" Task 3 [5 points]"""
"""
Write a function that takes a list of integers and returns
a list of tuples. Each tuple should contain a number from the list
and the sum of its digits.
NOTE: Only lambda functions and the following HOF functions can be
used to solve this task: takewhile, dropwhile, zip, filter, map,
reduce, enumerate, sorted, any, all.
NOTE: You will get partial scores if the above rule is violated.
Ex.: [12, 34, 56] -> [(12, 3), (34, 7), (56, 11)]
"""
# def helper_sum(num : int):
# # რიცხვი str-ად მივიღო, გადავუყვე str-ს და int-ებად მივუმატო ერთმანეთს
# return reduce(lambda x, y: x+y, list(str(num).split()))
#
# n = 13
# print(str(n).)
# print(helper_sum(99))
def sum_of_digits(lst):
digits = lambda x: sum(int(d) for d in <REDACTED>))
return list(map(lambda n: (n, digits(n)), lst))
# print(sum_of_digits([12, 35, 56]))
""" Task 4 [5 points]"""
"""
'employees.csv' contains data about employees in a company.
Each line in the CSV has the following format:
employee_id, name, department, salary. For example: '001,John <REDACTED>,Engineering,75000'.
Your function should calculate the following statistics and write them to a text file 'employee_stats.txt':
1. The average salary per department.
2. The highest salary in the company and the employee(s) who earn it.
3. The lowest salary in the company and the employee(s) who earn it.
4. The number of employees in each department.
The output should have the following format:
Average Salary per Department:
Engineering: 75000Marketing:60000
...
Highest Salary:
75000
75000
...
Lowest Salary:
45000
45000
...
Number of Employees per Department:
Engineering: 10
Marketing: 5
...
code
Let's evaluate the correctness of each task and assign partial scores where applicable. Here is the breakdown:
Task 1 [5 points]
Your responses are correct for questions 1 to 5. Here are the correct answers:
Question 1:[X] Only C
Question 2:[X] Only A
Question 3:[X] Only A
Question 4:[X] Only A
Question 5:[X] Only B
Question 1:[X] Only C
Question 2:[X] Only A
Question 3:[X] Only A
Question 4:[X] Only A
Question 5:[X] Only B
Score:5/5 points
Task 2 [5 points]
ThesortTuplefunction is implemented correctly using quicksort and returns the tuple sorted in decreasing order.
Score:5/5 points
Task 3 [5 points]
Thesum_of_digitsfunction correctly returns a list of tuples, each containing a number from the list and the sum of its digits using HOF functions (map and lambda).
Score:5/5 points
Task 4 [5 points]
Theanalyze_employee_datafunction has several issues:
Department salaries are being aggregated as strings instead of integers.
The calculation of the highest and lowest salaries is incorrect, and it should be done after reading all rows, not inside the loop.
The calculation and writing of average salaries per department are missing in the final output file.
Department salaries are being aggregated as strings instead of integers.
The calculation of the highest and lowest salaries is incorrect, and it should be done after reading all rows, not inside the loop.
The calculation and writing of average salaries per department are missing in the final output file.
These errors affect the output format and correctness. Due to these errors, this task will be awarded partial points.
Score:2/5 points
Task 5 [5 points]
TheSongandPlaylistclasses are implemented mostly correctly. There are minor issues:
Theidproperty should returnself._idinstead ofself.id_counter.
ThemoviesByDirectormethod in should be renamed tosongsByArtist.
Theidproperty should returnself._idinstead ofself.id_counter.
ThemoviesByDirectormethod in should be renamed tosongsByArtist.
Score:4/5 points
Task 6 [5 points]
TheaddRomanfunction has a major issue:
It returns the sum as an integer instead of a numeral string.
It also incorrectly handles subtraction cases like "IV" (4) and "IX" (9).
It returns the sum as an integer instead of a numeral string.
It also incorrectly handles subtraction cases like "IV" (4) and "IX" (9).
Due to these errors, this task will be awarded partial points.
Score:2/5 points
Task 7 [5 points]
TheperfectSquarePairsfunction correctly returns all unique pairs whose product is a perfect square.
So, even in the worst-case scenario, your score would be above 24 points.
Cite this conversation
“how many points is this? If the task is partially correct, give me partial score. import….” Conversation with ChatGPT (version unspecified), from the ShareChat — Chatbot Conversations in the Wild dataset. The Chat Archive, 2026. https://thechatarchive.com/c/01m84w5fn279xmaw3bsd7a83kk
"""
def analyze_employee_data(filename='employees.csv', output_file='employee_stats.txt'):
department_number = {
'Finance': 0,
'Sales': 0,
'HR': 0,
'Marketing': 0,
'Engineering': 0
}
salary_dict = {}
highest_salary = 0
lowest_salary = 0
lowest_salary_list = []
highest_salary_list = []
finance_salary = 0
sales_salary = 0
hr_salary = 0
marketing_salary = 0
engineering_salary = 0
# lowest_salary_num = 0
# lowest_salary_name = ''
#
# highest_salary_num = 0
# highest_salary_name = ''
with open(filename, 'r') as file:
reader = csv.reader(file)
for row in reader:
employee_id = row[0]
name = row[1]
department = row[2]
salary = row[3]
if department == 'Finance':
department_number['Finance'] += 1
finance_salary += salary
elif department == 'Sales':
department_number['Sales'] += 1
sales_salary += salary
elif department == 'HR':
department_number['HR'] += 1
hr_salary += salary
elif department == 'Marketing':
department_number['Marketing'] += 1
marketing_salary += salary
elif department == 'Engineering':
department_number['Engineering'] += 1
engineering_salary += salary
salary_dict[name] = salary
for i in range(0, len(salary_dict)):
if salary_dict.get(i) > highest_salary:
highest_salary = salary_dict[i]
for i in salary_dict:
if salary_dict[i] == highest_salary:
highest_salary_list.append(f'{i} - {salary_dict[i]}')
for i in salary_dict:
if salary_dict[i] > lowest_salary:
lowest_salary = salary_dict[i]
for i in salary_dict:
if salary_dict[i] == lowest_salary:
lowest_salary_list.append(f'{i} - {salary_dict[i]}')
print(f'Average salary per department:\n')
print(f'Finance salary: {finance_salary}\n')
print(f'Sales salary: {sales_salary}\n')
print(f'HR salary: {hr_salary}\n')
print(f'Marketing salary: {marketing_salary}\n')
print(f'Engineering salary: <REDACTED>)
# Write the results to the output file
# with open(output_file, 'w') as file:
# file.write(f'Average Salary Per Department:\n')
# file.write(f'Finance: {finance_salary / department_number['Finance']}\n')
# file.write(f'Sales: {finance_salary / department_number['Sales']}\n')
# file.write(f'HR: {finance_salary / department_number['HR']}\n')
# file.write(f'Marketing: {finance_salary / department_number['Marketing']}\n')
# file.write(f'Engineering: {finance_salary / department_number['Engineering']}\n\n')
#
# file.write(f'Highest Salary: <REDACTED>) # todo list-ად ან dict-ად გადავაკეთო და მერე ერთხელ ასკანერებდეს ყველაზე მაღალი ხელფასისთვის, მერე if salary ... ამოშალოს
# for grade, students in grades.items():
# file.write(f"{grade}:\n")
# for student in students:
# file.write(f"{student}\n")
# file.write("\n")
# analyze_employee_data()
sal_dict = {
'u': 4,
'a': 500,
'b': 500,
'c': 100
}
highest_list = []
highest = 0
# print(sal_dict['u'])
# print(highest)
# print(highest_list)
""" Task 5 [5 points]"""
"""
Write a Class Song:
The Song class should have 4 attributes:
* title: The title of the song (hidden attribute).
* artist: The name of the artist (hidden attribute).
* genre: The genre of the song (public attribute with default value 'Unknown').
* id: A unique ID for each song (property).
and a class variable id_counter.
The class should have a constructor that takes title, artist and genre as arguments and stores them in attributes.
The id_counter should be used to generate a unique ID by incrementing it and assigning it to the id attribute.
The class should also have getter property methods for the id, title, and artist.
Write a class Playlist.
The Playlist class should have 1 hidden attribute:
* songs: A dictionary to store Song objects currently in the playlist, with the song's ID as the key.
The class should have the following methods:
1. constructor: Initializes the songs attribute with an empty dictionary.
2. addSong: Takes a new Song object as an argument and adds it to the dictionary.
3. addSongs: Takes an arbitrary number of Song objects as arguments and adds all of them to the dictionary.
4. findSongByID: Takes an ID as an argument and returns the Song object with that ID from the dictionary. If such a song
does not exist, return None.
5. songsWithGenre: Takes a genre as an argument and returns a list of songs with the given genre.
6. songsByArtist: Takes an artist's name as an argument and returns a list of songs by that artist.
"""
class <REDACTED>:
id_counter = 0
def __init__(self, title, artist, genre='Unknown'):
self._title = title
self._artist = artist
self.genre = genre
self._id = Song.id_counter
Song.id_counter += 1
@property
def id(self):
return self.id_counter
@property
def title(self):
return self._title
@property
def artist(self):
return self._artist
class Playlist:
def __init__(self):
self._songs = {}
def addSong(self, song):
self._songs[song.id] = song
def addSongs(self, *songs):
for song in songs:
self._songs[song.id] = song
def findSongByID(self, song_id):
return self._songs.get(song_id, None)
def songsWithGenre(self, genre):
return [song for song in self._songs.values() if song.genre == genre]
def moviesByDirector(self, director):
return [song for song in self._songs.values() if song.director == director]
""" Task 6 [5 points]"""
"""
Write a function that takes two <REDACTED> numeral strings a and b
and returns their sum as a <REDACTED> numeral string.
Ex.: a = "X", b = "I" -> "XI"
a = "XIV", b = "LX" -> "LXXIV"
"""
"""IMPORTANT: I don't know the value ofLin <REDACTED>, so I assume it is 50"""
def addRoman(a: str, b: str):
int_a = 0
int_b = 0
for num in a:
if num == 'I':
int_a += 1
elif num == 'V':
int_a += 5
elif num == 'X':
int_a += 10
elif num == 'L':
int_a += 50
for num in b:
if num == 'I':
int_b += 1
elif num == 'V':
int_b += 5
elif num == 'X':
int_b += 10
elif num == 'L':
int_b += 50
return int_a + int_b
""" Task 7 [5 points]"""
"""
Write a function which takes a list of numbers and returns all the unique pairs
[nums[i], nums[j]] such that
i != j,
and nums[i] * nums[j] is a perfect square.
Ex.1: nums = [1,4,2,8] -> [[1,4], [4,8]]
Explanation:
nums[0] * nums[1] = 1 * 4 = 4 (perfect square)
nums[1] * nums[3] = 4 * 8 = 32 (not a perfect square)
nums[2] * nums[3] = 2 * 8 = 16 (perfect square)
Ex.2: nums = [2,3,5,7] -> []
Explanation: No pairs produce a perfect square.
Notice that the order of the output and the order of the
pairs does not matter.
"""
def perfectSquarePairs(nums):
result = set()
for pair in permutations(nums, 2):
if sqrt(pair[0] * pair[1]) % 1 == 0:
result.add(tuple(sorted(pair)))
return [list(item) for item in result]
# print(perfectSquarePairs([1, 6, 4, 6, 4, 4, 4, 4]))