-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport_code.txt
41 lines (21 loc) · 2.63 KB
/
report_code.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# FILE: /report_code.txt
#1: Here, each element of 'cls.category' (which contains the category names) is passed as an argument to create a new object of 'CategoryModel' class. Each category read from the file will be used to instantiate a 'CategoryModel' object, which will be stored in the cat list.
#2: I decided to replace it with 'for' loops as usual, eliminating as many built-in functions as possible.
#3: Remember that 'items_sold' is of the 'ProductModel' class type, which has 'name', 'price' and 'category'.
#4: Response: ['Fruits', 'Vegetables', 'Legumes'].
#5: Response: ['bean|7|Legumes|Edson|Théo|3|14/12/2024'].
#6: Response: [['bean', '7', 'Legumes', 'Edson', 'Théo', '3', '14/12/2024']].
#7: Response: Théo.
#8: Response: bean.
#9: Response: 7.0.
#10: Response: Category registered successfully.
#11: Here, 'i' is an object of 'CategoryModel' class, which was created inside the read method of the 'CategoryDao' class. When the code gets to the line of 'if i.category == newcategory', it is accessing the category attribute of that 'CategoryModel' instance.
#12: I had to use '-1, -1, -1' to make the iteration start backwards, as I was getting an error. This occurred when I tried to access an index that is outside the range of the list. In this case, the error is happening inside the removal loop. This is probably because I removed elements from the list while iterating through it, which changes the access indexes, causing the code to try to access an invalid index after removing an item.
#13: If the product exists but there is not enough quantity.
#14: If the product exists. Yes or not.
#15: If 'quantity_stock' is False, it means that either the product was not found or the available quantity is not sufficient for sale. The 'elif not quantity_stock': line will be executed only if 'quantity_stock is False', that is, if the quantity was not sufficient for sale.
#16: If the product is not in the list ('size' is empty), the product is added to the 'product' list with the name and the initial quantity.
#17: if not False = True. If not True = False.
#18: The use of 'i4+1' in the second loop is to avoid repeated comparisons. 'i4 + 1': This causes the second loop (for j4 in range(i4 + 1, len(ordered))) to start one index after i4. This is done to ensure that the code compares each element with the elements that come after it, and not with the ones that have already been compared.
#19: If the quantity at index 'i4' is less than the quantity at index 'j4', they are swapped. This is a simple implementation of an exchange sort algorithm, also known as 'bubble sort'.
#20: In this code block i can request the 'dao.py' file to save.