Page 1

Student ID: 279, P-Value: 3.18e-05

Nearest Neighbor ID: 172

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle():n2class Circle:
3    def __init__(self, radius):3    def __init__(self):
4        self.radius = radius4        self.radius=radius
5    def area(self):5    def area(self):
n6        return math.pi * self.radius**2n6        return math.pi*(self.radius**2)
7    def perimeter(self):7    def perimeter(self):
8        return 2*math.pi*self.radius8        return 2*math.pi*self.radius
n9if __name__ == '__main__':n9if __name__=='__main__':
10    x = int(input())10   x = int(input())
11    NewCircle = Circle(x)11   NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12   print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))13   print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14class ItemToPurchase:
15   def __init__(self, name='none', price=0, quantity=0, description='none'):14   def __init__(self, name='none', price=0, quantity=0, description='none'):
16       self.item_name=name15       self.item_name=name
17       self.item_description=description16       self.item_description=description
18       self.item_price=price17       self.item_price=price
19       self.item_quantity=quantity18       self.item_quantity=quantity
20   def print_item_description(self):19   def print_item_description(self):
21       print('%s: %s' % (self.item_name, self.item_description))20       print('%s: %s' % (self.item_name, self.item_description))
22class ShoppingCart:21class ShoppingCart:
23   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
24       self.customer_name = customer_name23       self.customer_name = customer_name
25       self.current_date = current_date24       self.current_date = current_date
26       self.cart_items = cart_items  25       self.cart_items = cart_items  
27   def add_item(self, itemToPurchase):26   def add_item(self, itemToPurchase):
28       self.cart_items.append(itemToPurchase)  27       self.cart_items.append(itemToPurchase)  
29   def remove_item(self, itemName):28   def remove_item(self, itemName):
30       tremove_item = False29       tremove_item = False
31       for item in self.cart_items:30       for item in self.cart_items:
32           if item.item_name == itemName:31           if item.item_name == itemName:
33               self.cart_items.remove(item)32               self.cart_items.remove(item)
34               tremove_item = True33               tremove_item = True
35               break34               break
36       if not tremove_item:          35       if not tremove_item:          
37           print('Item not found in the cart. Nothing removed')36           print('Item not found in the cart. Nothing removed')
38   def modify_item(self, itemToPurchase):  37   def modify_item(self, itemToPurchase):  
39       tmodify_item = False38       tmodify_item = False
40       for i in range(len(self.cart_items)):39       for i in range(len(self.cart_items)):
41           if self.cart_items[i].item_name == itemToPurchase.item_name:40           if self.cart_items[i].item_name == itemToPurchase.item_name:
42               tmodify_item = True41               tmodify_item = True
43               self.cart_items[i].item_quantity = itemToPurchase.item_quantity42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
44               break43               break
45       if not tmodify_item:      44       if not tmodify_item:      
46           print('Item not found in the cart. Nothing modified')  45           print('Item not found in the cart. Nothing modified')  
47   def get_num_items_in_cart(self):46   def get_num_items_in_cart(self):
48       num_items = 047       num_items = 0
49       for item in self.cart_items:48       for item in self.cart_items:
50           num_items = num_items + item.item_quantity49           num_items = num_items + item.item_quantity
51       return num_items50       return num_items
52   def get_cost_of_cart(self):51   def get_cost_of_cart(self):
53       total_cost = 052       total_cost = 0
54       cost = 053       cost = 0
55       for item in self.cart_items:54       for item in self.cart_items:
56           cost = (item.item_quantity * item.item_price)55           cost = (item.item_quantity * item.item_price)
57           total_cost += cost56           total_cost += cost
58       return total_cost57       return total_cost
59   def print_total(self):58   def print_total(self):
60       total_cost = self.get_cost_of_cart()59       total_cost = self.get_cost_of_cart()
61       if (total_cost == 0):60       if (total_cost == 0):
62           print('SHOPPING CART IS EMPTY')61           print('SHOPPING CART IS EMPTY')
63       else:62       else:
64           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
65           print('Number of Items: %d\n' %self.get_num_items_in_cart())64           print('Number of Items: %d\n' %self.get_num_items_in_cart())
66           for item in self.cart_items:65           for item in self.cart_items:
67               total = item.item_price * item.item_quantity66               total = item.item_price * item.item_quantity
68               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
69           print('\nTotal: $%d' %(total_cost))68           print('\nTotal: $%d' %(total_cost))
70   def print_descriptions(self):69   def print_descriptions(self):
71       if len(self.cart_items) == 0:70       if len(self.cart_items) == 0:
72           print('SHOPPING CART IS EMPTY')71           print('SHOPPING CART IS EMPTY')
73       else:  72       else:  
74           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
75           print('\nItem Descriptions')74           print('\nItem Descriptions')
76           for item in self.cart_items:75           for item in self.cart_items:
77               item.print_item_description()  76               item.print_item_description()  
78def print_menu(newCart):77def print_menu(newCart):
79   customer_Cart = newCart78   customer_Cart = newCart
80   menu = ('\nMENU\n'79   menu = ('\nMENU\n'
81       'a - Add item to cart\n'80       'a - Add item to cart\n'
82       'r - Remove item from the cart\n'81       'r - Remove item from the cart\n'
83       'c - Change item quantity\n'82       'c - Change item quantity\n'
84       "i - Output item's descriptions\n"83       "i - Output item's descriptions\n"
85       'o - Output shopping cart\n'84       'o - Output shopping cart\n'
86       'q - Quit\n')85       'q - Quit\n')
87   command = ''86   command = ''
88   while(command != 'q'):87   while(command != 'q'):
89       print(menu)88       print(menu)
90       command = input('Choose an option:')89       command = input('Choose an option:')
91       while(command != 'a' and command != 'o' and command != 'i' and command !=90       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
92           command = input('Choose an option:\n')91           command = input('Choose an option:\n')
93       if(command == 'a'):92       if(command == 'a'):
94           print("\nADD ITEM TO CART")93           print("\nADD ITEM TO CART")
95           item_name = input('Enter the item name:\n')94           item_name = input('Enter the item name:\n')
96           item_description = input('Enter the item description:\n')95           item_description = input('Enter the item description:\n')
97           item_price = int(input('Enter the item price:\n'))96           item_price = int(input('Enter the item price:\n'))
98           item_quantity = int(input('Enter the item quantity:\n'))97           item_quantity = int(input('Enter the item quantity:\n'))
99           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
100           customer_Cart.add_item(itemtoPurchase)99           customer_Cart.add_item(itemtoPurchase)
101       elif(command == 'o'):100       elif(command == 'o'):
102           print('\nOUTPUT SHOPPING CART')101           print('\nOUTPUT SHOPPING CART')
103           customer_Cart.print_total()  102           customer_Cart.print_total()  
104       elif(command == 'i'):103       elif(command == 'i'):
105           print('\nOUTPUT ITEMS\' DESCRIPTIONS')104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
106           customer_Cart.print_descriptions()105           customer_Cart.print_descriptions()
107       elif(command == 'r'):106       elif(command == 'r'):
108           print('REMOVE ITEM FROM CART')107           print('REMOVE ITEM FROM CART')
109           itemName = input('Enter the name of the item to remove :\n')108           itemName = input('Enter the name of the item to remove :\n')
110           customer_Cart.remove_item(itemName)109           customer_Cart.remove_item(itemName)
111       elif(command == 'c'):110       elif(command == 'c'):
112           print('\nCHANGE ITEM QUANTITY')111           print('\nCHANGE ITEM QUANTITY')
113           itemName = input('Enter the name of the item :\n')112           itemName = input('Enter the name of the item :\n')
114           qty = int(input('Enter the new quantity :\n'))113           qty = int(input('Enter the new quantity :\n'))
115           itemToPurchase = ItemToPurchase(itemName,0,qty)114           itemToPurchase = ItemToPurchase(itemName,0,qty)
116           customer_Cart.modify_item(itemToPurchase)115           customer_Cart.modify_item(itemToPurchase)
117if __name__ == "__main__":116if __name__ == "__main__":
118   customer_name = input("Enter customer's name:\n")117   customer_name = input("Enter customer's name:\n")
119   current_date = input("Enter today's date:\n")118   current_date = input("Enter today's date:\n")
120   print("\nCustomer name: %s" %customer_name)119   print("\nCustomer name: %s" %customer_name)
121   print("Today's date: %s" %current_date)120   print("Today's date: %s" %current_date)
122   newCart = ShoppingCart(customer_name, current_date)121   newCart = ShoppingCart(customer_name, current_date)
t123   print_menu(newCart)from math import sqrtt122   print_menu(newCart)from math import sqrt 
124class pt3d:123class pt3d:
125    def __init__(self, x, y, z):124    def __init__(self, x, y, z):
126        self.x = x125        self.x = x
127        self.y = y126        self.y = y
128        self.z = z127        self.z = z
129    def __add__(self, other):128    def __add__(self, other):
130        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)129        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
131    def __sub__(self, other):130    def __sub__(self, other):
132        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot131        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>her.z)**2)>her.z)**2)
133    def __eq__(self, other):132    def __eq__(self, other):
134        return self.x == other.x & self.y == other.y & self.z == other.z133        return self.x == other.x & self.y == other.y & self.z == other.z
135    def __str__(self):134    def __str__(self):
136        return '<{}, {}, {}>'.format(self.x, self.y, self.z)135        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
137p1 = pt3d(1, 1, 1)136p1 = pt3d(1, 1, 1)
138p2 = pt3d(2, 2, 2)137p2 = pt3d(2, 2, 2)
139print(p1 + p2)138print(p1 + p2)
140print(p1 - p2)139print(p1 - p2)
141print(p1 == p2)140print(p1 == p2)
142print(p1+p1 == p2)141print(p1+p1 == p2)
143print(p1==p2+pt3d(-1, -1, -1))142print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 2

Student ID: 172, P-Value: 3.18e-05

Nearest Neighbor ID: 279

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle:n2class Circle():
3    def __init__(self):3    def __init__(self, radius):
4        self.radius=radius4        self.radius = radius
5    def area(self):5    def area(self):
n6        return math.pi*(self.radius**2)n6        return math.pi * self.radius**2
7    def perimeter(self):7    def perimeter(self):
8        return 2*math.pi*self.radius8        return 2*math.pi*self.radius
n9if __name__=='__main__':n9if __name__ == '__main__':
10   x = int(input())10    x = int(input())
11   NewCircle = Circle(x)11    NewCircle = Circle(x)
12   print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
13   print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))
14class ItemToPurchase:
14   def __init__(self, name='none', price=0, quantity=0, description='none'):15   def __init__(self, name='none', price=0, quantity=0, description='none'):
15       self.item_name=name16       self.item_name=name
16       self.item_description=description17       self.item_description=description
17       self.item_price=price18       self.item_price=price
18       self.item_quantity=quantity19       self.item_quantity=quantity
19   def print_item_description(self):20   def print_item_description(self):
20       print('%s: %s' % (self.item_name, self.item_description))21       print('%s: %s' % (self.item_name, self.item_description))
21class ShoppingCart:22class ShoppingCart:
22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 23   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
23       self.customer_name = customer_name24       self.customer_name = customer_name
24       self.current_date = current_date25       self.current_date = current_date
25       self.cart_items = cart_items  26       self.cart_items = cart_items  
26   def add_item(self, itemToPurchase):27   def add_item(self, itemToPurchase):
27       self.cart_items.append(itemToPurchase)  28       self.cart_items.append(itemToPurchase)  
28   def remove_item(self, itemName):29   def remove_item(self, itemName):
29       tremove_item = False30       tremove_item = False
30       for item in self.cart_items:31       for item in self.cart_items:
31           if item.item_name == itemName:32           if item.item_name == itemName:
32               self.cart_items.remove(item)33               self.cart_items.remove(item)
33               tremove_item = True34               tremove_item = True
34               break35               break
35       if not tremove_item:          36       if not tremove_item:          
36           print('Item not found in the cart. Nothing removed')37           print('Item not found in the cart. Nothing removed')
37   def modify_item(self, itemToPurchase):  38   def modify_item(self, itemToPurchase):  
38       tmodify_item = False39       tmodify_item = False
39       for i in range(len(self.cart_items)):40       for i in range(len(self.cart_items)):
40           if self.cart_items[i].item_name == itemToPurchase.item_name:41           if self.cart_items[i].item_name == itemToPurchase.item_name:
41               tmodify_item = True42               tmodify_item = True
42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity43               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43               break44               break
44       if not tmodify_item:      45       if not tmodify_item:      
45           print('Item not found in the cart. Nothing modified')  46           print('Item not found in the cart. Nothing modified')  
46   def get_num_items_in_cart(self):47   def get_num_items_in_cart(self):
47       num_items = 048       num_items = 0
48       for item in self.cart_items:49       for item in self.cart_items:
49           num_items = num_items + item.item_quantity50           num_items = num_items + item.item_quantity
50       return num_items51       return num_items
51   def get_cost_of_cart(self):52   def get_cost_of_cart(self):
52       total_cost = 053       total_cost = 0
53       cost = 054       cost = 0
54       for item in self.cart_items:55       for item in self.cart_items:
55           cost = (item.item_quantity * item.item_price)56           cost = (item.item_quantity * item.item_price)
56           total_cost += cost57           total_cost += cost
57       return total_cost58       return total_cost
58   def print_total(self):59   def print_total(self):
59       total_cost = self.get_cost_of_cart()60       total_cost = self.get_cost_of_cart()
60       if (total_cost == 0):61       if (total_cost == 0):
61           print('SHOPPING CART IS EMPTY')62           print('SHOPPING CART IS EMPTY')
62       else:63       else:
63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr64           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
64           print('Number of Items: %d\n' %self.get_num_items_in_cart())65           print('Number of Items: %d\n' %self.get_num_items_in_cart())
65           for item in self.cart_items:66           for item in self.cart_items:
66               total = item.item_price * item.item_quantity67               total = item.item_price * item.item_quantity
67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 68               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
68           print('\nTotal: $%d' %(total_cost))69           print('\nTotal: $%d' %(total_cost))
69   def print_descriptions(self):70   def print_descriptions(self):
70       if len(self.cart_items) == 0:71       if len(self.cart_items) == 0:
71           print('SHOPPING CART IS EMPTY')72           print('SHOPPING CART IS EMPTY')
72       else:  73       else:  
73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr74           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
74           print('\nItem Descriptions')75           print('\nItem Descriptions')
75           for item in self.cart_items:76           for item in self.cart_items:
76               item.print_item_description()  77               item.print_item_description()  
77def print_menu(newCart):78def print_menu(newCart):
78   customer_Cart = newCart79   customer_Cart = newCart
79   menu = ('\nMENU\n'80   menu = ('\nMENU\n'
80       'a - Add item to cart\n'81       'a - Add item to cart\n'
81       'r - Remove item from the cart\n'82       'r - Remove item from the cart\n'
82       'c - Change item quantity\n'83       'c - Change item quantity\n'
83       "i - Output item's descriptions\n"84       "i - Output item's descriptions\n"
84       'o - Output shopping cart\n'85       'o - Output shopping cart\n'
85       'q - Quit\n')86       'q - Quit\n')
86   command = ''87   command = ''
87   while(command != 'q'):88   while(command != 'q'):
88       print(menu)89       print(menu)
89       command = input('Choose an option:')90       command = input('Choose an option:')
90       while(command != 'a' and command != 'o' and command != 'i' and command !=91       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
91           command = input('Choose an option:\n')92           command = input('Choose an option:\n')
92       if(command == 'a'):93       if(command == 'a'):
93           print("\nADD ITEM TO CART")94           print("\nADD ITEM TO CART")
94           item_name = input('Enter the item name:\n')95           item_name = input('Enter the item name:\n')
95           item_description = input('Enter the item description:\n')96           item_description = input('Enter the item description:\n')
96           item_price = int(input('Enter the item price:\n'))97           item_price = int(input('Enter the item price:\n'))
97           item_quantity = int(input('Enter the item quantity:\n'))98           item_quantity = int(input('Enter the item quantity:\n'))
98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,99           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
99           customer_Cart.add_item(itemtoPurchase)100           customer_Cart.add_item(itemtoPurchase)
100       elif(command == 'o'):101       elif(command == 'o'):
101           print('\nOUTPUT SHOPPING CART')102           print('\nOUTPUT SHOPPING CART')
102           customer_Cart.print_total()  103           customer_Cart.print_total()  
103       elif(command == 'i'):104       elif(command == 'i'):
104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')105           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
105           customer_Cart.print_descriptions()106           customer_Cart.print_descriptions()
106       elif(command == 'r'):107       elif(command == 'r'):
107           print('REMOVE ITEM FROM CART')108           print('REMOVE ITEM FROM CART')
108           itemName = input('Enter the name of the item to remove :\n')109           itemName = input('Enter the name of the item to remove :\n')
109           customer_Cart.remove_item(itemName)110           customer_Cart.remove_item(itemName)
110       elif(command == 'c'):111       elif(command == 'c'):
111           print('\nCHANGE ITEM QUANTITY')112           print('\nCHANGE ITEM QUANTITY')
112           itemName = input('Enter the name of the item :\n')113           itemName = input('Enter the name of the item :\n')
113           qty = int(input('Enter the new quantity :\n'))114           qty = int(input('Enter the new quantity :\n'))
114           itemToPurchase = ItemToPurchase(itemName,0,qty)115           itemToPurchase = ItemToPurchase(itemName,0,qty)
115           customer_Cart.modify_item(itemToPurchase)116           customer_Cart.modify_item(itemToPurchase)
116if __name__ == "__main__":117if __name__ == "__main__":
117   customer_name = input("Enter customer's name:\n")118   customer_name = input("Enter customer's name:\n")
118   current_date = input("Enter today's date:\n")119   current_date = input("Enter today's date:\n")
119   print("\nCustomer name: %s" %customer_name)120   print("\nCustomer name: %s" %customer_name)
120   print("Today's date: %s" %current_date)121   print("Today's date: %s" %current_date)
121   newCart = ShoppingCart(customer_name, current_date)122   newCart = ShoppingCart(customer_name, current_date)
t122   print_menu(newCart)from math import sqrt t123   print_menu(newCart)from math import sqrt
123class pt3d:124class pt3d:
124    def __init__(self, x, y, z):125    def __init__(self, x, y, z):
125        self.x = x126        self.x = x
126        self.y = y127        self.y = y
127        self.z = z128        self.z = z
128    def __add__(self, other):129    def __add__(self, other):
129        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)130        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
130    def __sub__(self, other):131    def __sub__(self, other):
131        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot132        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>her.z)**2)>her.z)**2)
132    def __eq__(self, other):133    def __eq__(self, other):
133        return self.x == other.x & self.y == other.y & self.z == other.z134        return self.x == other.x & self.y == other.y & self.z == other.z
134    def __str__(self):135    def __str__(self):
135        return '<{}, {}, {}>'.format(self.x, self.y, self.z)136        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
136p1 = pt3d(1, 1, 1)137p1 = pt3d(1, 1, 1)
137p2 = pt3d(2, 2, 2)138p2 = pt3d(2, 2, 2)
138print(p1 + p2)139print(p1 + p2)
139print(p1 - p2)140print(p1 - p2)
140print(p1 == p2)141print(p1 == p2)
141print(p1+p1 == p2)142print(p1+p1 == p2)
142print(p1==p2+pt3d(-1, -1, -1))143print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 3

Student ID: 345, P-Value: 3.32e-05

Nearest Neighbor ID: 488

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self, r):n3    def __init__(self,r):
4        self.radius = r4        self.radius = r
5    def area(self):5    def area(self):
n6        return (self.radius**2)*(math.pi)n6       return (self.radius**2)*(math.pi)
7    def perimeter(self):7    def perimeter(self):
n8        return 2*(math.pi)*(self.radius)        n8        return 2*(math.pi)*(self.radius) 
9if __name__=='__main__':9if __name__=='__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14    def __init__(self, item_name = "none", item_price = 0, item_quantity = 0, it14    def __init__(self, item_name = "none", item_price = 0, item_quantity = 0, it
>em_description = "none"):>em_description = "none"):
15        self.item_name = item_name15        self.item_name = item_name
16        self.item_price = item_price16        self.item_price = item_price
17        self.item_quantity = item_quantity17        self.item_quantity = item_quantity
18        self.item_description = item_description18        self.item_description = item_description
19    def print_item_cost(self):19    def print_item_cost(self):
20        print(self.item_name + " " + str(self.item_quantity) + " @ $" + str(self20        print(self.item_name + " " + str(self.item_quantity) + " @ $" + str(self
>.item_price) + " = $" +>.item_price) + " = $" +
21              str(self.item_price * self.item_quantity))21              str(self.item_price * self.item_quantity))
22    def print_item_description(self):22    def print_item_description(self):
23        print(self.item_name + ": " + str(self.item_description))23        print(self.item_name + ": " + str(self.item_description))
24class ShoppingCart:24class ShoppingCart:
25    def __init__(self, customer_name='none', current_date='January 1, 2016'):25    def __init__(self, customer_name='none', current_date='January 1, 2016'):
26        self.customer_name = customer_name26        self.customer_name = customer_name
27        self.current_date = current_date27        self.current_date = current_date
28        self.cart_items = []28        self.cart_items = []
29    def add_item(self, ItemToPurchase):29    def add_item(self, ItemToPurchase):
30        self.cart_items.append(ItemToPurchase)30        self.cart_items.append(ItemToPurchase)
31    def remove_item(self, itemName):31    def remove_item(self, itemName):
32        RemoveIt = False32        RemoveIt = False
33        for item in self.cart_items:33        for item in self.cart_items:
34            if item.item_name == itemName:34            if item.item_name == itemName:
35                self.cart_items.remove(item)35                self.cart_items.remove(item)
36                RemoveIt = True36                RemoveIt = True
37                break37                break
38        if not RemoveIt:38        if not RemoveIt:
39            print('Item not found in cart. Nothing removed.')39            print('Item not found in cart. Nothing removed.')
40    def modify_item(self, itemToPurchase):40    def modify_item(self, itemToPurchase):
n41        ModifyIt = Falsen41        Modify_It = False
42        for i in range(len(self.cart_items)):42        for i in range(len(self.cart_items)):
43            if self.cart_items[i].item_name == itemToPurchase.item_name:43            if self.cart_items[i].item_name == itemToPurchase.item_name:
n44                ModifyIt = Truen44                Modify_It = True
45                if (45                if (
46                        itemToPurchase.item_price == 0 and itemToPurchase.item_q46                        itemToPurchase.item_price == 0 and itemToPurchase.item_q
>uantity == 0 and itemToPurchase.item_description == 'none'):>uantity == 0 and itemToPurchase.item_description == 'none'):
47                    break47                    break
48                else:48                else:
49                    if (itemToPurchase.item_price != 0):49                    if (itemToPurchase.item_price != 0):
50                        self.cart_items[i].item_price = itemToPurchase.item_pric50                        self.cart_items[i].item_price = itemToPurchase.item_pric
>e>e
51                    if (itemToPurchase.item_quantity != 0):51                    if (itemToPurchase.item_quantity != 0):
52                        self.cart_items[i].item_quantity = itemToPurchase.item_q52                        self.cart_items[i].item_quantity = itemToPurchase.item_q
>uantity>uantity
53                    if (itemToPurchase.item_description != 'none'):53                    if (itemToPurchase.item_description != 'none'):
54                        self.cart_items[i].item_description = itemToPurchase.ite54                        self.cart_items[i].item_description = itemToPurchase.ite
>m_description>m_description
55                    break55                    break
n56        if not ModifyIt:n56        if not Modify_It:
57            print('Item not found in cart. Nothing modified.')57            print('Item not found in cart. Nothing modified.')
58    def get_num_items_in_cart(self):58    def get_num_items_in_cart(self):
59        num_items = 059        num_items = 0
60        for item in self.cart_items:60        for item in self.cart_items:
61            num_items = num_items + item.item_quantity61            num_items = num_items + item.item_quantity
62        return num_items62        return num_items
63    def get_cost_of_cart(self):63    def get_cost_of_cart(self):
64        total_cost = 064        total_cost = 0
65        cost = 065        cost = 0
66        for item in self.cart_items:66        for item in self.cart_items:
67            cost = (item.item_quantity * item.item_price)67            cost = (item.item_quantity * item.item_price)
68            total_cost += cost68            total_cost += cost
69        return total_cost69        return total_cost
70    def print_total(self):70    def print_total(self):
71        total_cost = self.get_cost_of_cart()71        total_cost = self.get_cost_of_cart()
72        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current72        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date))>_date))
73        print('Number of Items: %d\n' % self.get_num_items_in_cart())73        print('Number of Items: %d\n' % self.get_num_items_in_cart())
74        for item in self.cart_items:74        for item in self.cart_items:
75            item.print_item_cost()75            item.print_item_cost()
76        if (total_cost == 0):76        if (total_cost == 0):
77            print('SHOPPING CART IS EMPTY')77            print('SHOPPING CART IS EMPTY')
78        print('\nTotal: $%d' % (total_cost))78        print('\nTotal: $%d' % (total_cost))
79    def print_descriptions(self):79    def print_descriptions(self):
80        if len(self.cart_items) == 0:80        if len(self.cart_items) == 0:
81            print('SHOPPING CART IS EMPTY')81            print('SHOPPING CART IS EMPTY')
82        else:82        else:
83            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur83            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur
>rent_date))>rent_date))
84            print('\nItem Descriptions')84            print('\nItem Descriptions')
85            for item in self.cart_items:85            for item in self.cart_items:
86                item.print_item_description()86                item.print_item_description()
87def print_menu():87def print_menu():
88    print('MENU\n'88    print('MENU\n'
89            'a - Add item to cart\n'89            'a - Add item to cart\n'
90            'r - Remove item from cart\n'90            'r - Remove item from cart\n'
91            'c - Change item quantity\n'91            'c - Change item quantity\n'
92            "i - Output items' descriptions\n"92            "i - Output items' descriptions\n"
93            'o - Output shopping cart\n'93            'o - Output shopping cart\n'
94            'q - Quit\n')94            'q - Quit\n')
95def execute_menu(command, my_cart):95def execute_menu(command, my_cart):
96    customer_Cart = my_cart96    customer_Cart = my_cart
97    if command == 'a':97    if command == 'a':
98        print("\nADD ITEM TO CART")98        print("\nADD ITEM TO CART")
99        item_name = input('Enter the item name:\n')99        item_name = input('Enter the item name:\n')
100        item_description = input('Enter the item description:\n')100        item_description = input('Enter the item description:\n')
101        item_price = int(input('Enter the item price:\n'))101        item_price = int(input('Enter the item price:\n'))
102        item_quantity = int(input('Enter the item quantity:\n'))102        item_quantity = int(input('Enter the item quantity:\n'))
103        itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity, it103        itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity, it
>em_description)>em_description)
104        customer_Cart.add_item(itemtoPurchase)104        customer_Cart.add_item(itemtoPurchase)
105    elif command == 'o':105    elif command == 'o':
106        print('OUTPUT SHOPPING CART')106        print('OUTPUT SHOPPING CART')
107        customer_Cart.print_total()107        customer_Cart.print_total()
108    elif command == 'i':108    elif command == 'i':
109        print('\nOUTPUT ITEMS\' DESCRIPTIONS')109        print('\nOUTPUT ITEMS\' DESCRIPTIONS')
110        customer_Cart.print_descriptions()110        customer_Cart.print_descriptions()
111    elif command == 'r':111    elif command == 'r':
112        print('REMOVE ITEM FROM CART')112        print('REMOVE ITEM FROM CART')
113        itemName = input('Enter name of item to remove:\n')113        itemName = input('Enter name of item to remove:\n')
114        customer_Cart.remove_item(itemName)114        customer_Cart.remove_item(itemName)
115    elif command == 'c':115    elif command == 'c':
116        print('\nCHANGE ITEM QUANTITY')116        print('\nCHANGE ITEM QUANTITY')
117        itemName = input('Enter the item name:\n')117        itemName = input('Enter the item name:\n')
118        qty = int(input('Enter the new quantity:\n'))118        qty = int(input('Enter the new quantity:\n'))
119        itemToPurchase = ItemToPurchase(itemName, 0, qty)119        itemToPurchase = ItemToPurchase(itemName, 0, qty)
120        customer_Cart.modify_item(itemToPurchase)120        customer_Cart.modify_item(itemToPurchase)
121if __name__ == "__main__":121if __name__ == "__main__":
122    customer_name = input("Enter customer's name:\n")122    customer_name = input("Enter customer's name:\n")
123    current_date = input("Enter today's date:\n")123    current_date = input("Enter today's date:\n")
124    print("\nCustomer name: %s" % customer_name)124    print("\nCustomer name: %s" % customer_name)
125    print("Today's date: %s" % current_date)125    print("Today's date: %s" % current_date)
126    newCart = ShoppingCart(customer_name, current_date)126    newCart = ShoppingCart(customer_name, current_date)
127    command = ''127    command = ''
128    while command != 'q':128    while command != 'q':
129        print()129        print()
130        print_menu()130        print_menu()
131        command = input('Choose an option:\n')131        command = input('Choose an option:\n')
132        while command != 'a' and command != 'o' and command != 'i' and command !132        while command != 'a' and command != 'o' and command != 'i' and command !
>= 'q' and command != 'r' and command != 'c':>= 'q' and command != 'r' and command != 'c':
133            command = input('Choose an option:\n')133            command = input('Choose an option:\n')
134        execute_menu(command, newCart)import math134        execute_menu(command, newCart)import math
135class pt3d:135class pt3d:
136    def __init__(self,x=0,y=0,z=0):136    def __init__(self,x=0,y=0,z=0):
137        self.x= x137        self.x= x
138        self.y= y138        self.y= y
139        self.z= z139        self.z= z
140    def __add__(self, other):140    def __add__(self, other):
141        x = self.x + other.x141        x = self.x + other.x
142        y = self.y + other.y142        y = self.y + other.y
143        z = self.z + other.z143        z = self.z + other.z
144        return pt3d(x, y,z)144        return pt3d(x, y,z)
145    def __sub__(self, other):145    def __sub__(self, other):
146        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 146        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>2)+math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
147    def __eq__(self, other):147    def __eq__(self, other):
148        return other.x==self.x and other.y==self.y and other.z==self.z148        return other.x==self.x and other.y==self.y and other.z==self.z
149    def __str__(self):149    def __str__(self):
150        return "<{0},{1},{2}>".format(self.x, self.y, self.z)150        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
151if __name__ == '__main__':151if __name__ == '__main__':
t152    p1 = pt3d(1, 1, 1)t152    p_1 = pt3d(1, 1, 1)
153    p2 = pt3d(2, 2, 2)153    p_2 = pt3d(2, 2, 2)
154    print(p1+p2)154    print(p_1+p_2)
155    print(p1-p2)155    print(p_1-p_2)
156    print(p1==p2)156    print(p_1==p_2)
157    print(p1+p1==p2)157    print(p_1+p_1==p_2)
158    print(p1==p2+pt3d(-1,-1,-1))158    print(p_1==p_2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 4

Student ID: 488, P-Value: 3.32e-05

Nearest Neighbor ID: 345

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self,r):n3    def __init__(self, r):
4        self.radius = r4        self.radius = r
5    def area(self):5    def area(self):
n6       return (self.radius**2)*(math.pi)n6        return (self.radius**2)*(math.pi)
7    def perimeter(self):7    def perimeter(self):
n8        return 2*(math.pi)*(self.radius) n8        return 2*(math.pi)*(self.radius)        
9if __name__=='__main__':9if __name__=='__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14    def __init__(self, item_name = "none", item_price = 0, item_quantity = 0, it14    def __init__(self, item_name = "none", item_price = 0, item_quantity = 0, it
>em_description = "none"):>em_description = "none"):
15        self.item_name = item_name15        self.item_name = item_name
16        self.item_price = item_price16        self.item_price = item_price
17        self.item_quantity = item_quantity17        self.item_quantity = item_quantity
18        self.item_description = item_description18        self.item_description = item_description
19    def print_item_cost(self):19    def print_item_cost(self):
20        print(self.item_name + " " + str(self.item_quantity) + " @ $" + str(self20        print(self.item_name + " " + str(self.item_quantity) + " @ $" + str(self
>.item_price) + " = $" +>.item_price) + " = $" +
21              str(self.item_price * self.item_quantity))21              str(self.item_price * self.item_quantity))
22    def print_item_description(self):22    def print_item_description(self):
23        print(self.item_name + ": " + str(self.item_description))23        print(self.item_name + ": " + str(self.item_description))
24class ShoppingCart:24class ShoppingCart:
25    def __init__(self, customer_name='none', current_date='January 1, 2016'):25    def __init__(self, customer_name='none', current_date='January 1, 2016'):
26        self.customer_name = customer_name26        self.customer_name = customer_name
27        self.current_date = current_date27        self.current_date = current_date
28        self.cart_items = []28        self.cart_items = []
29    def add_item(self, ItemToPurchase):29    def add_item(self, ItemToPurchase):
30        self.cart_items.append(ItemToPurchase)30        self.cart_items.append(ItemToPurchase)
31    def remove_item(self, itemName):31    def remove_item(self, itemName):
32        RemoveIt = False32        RemoveIt = False
33        for item in self.cart_items:33        for item in self.cart_items:
34            if item.item_name == itemName:34            if item.item_name == itemName:
35                self.cart_items.remove(item)35                self.cart_items.remove(item)
36                RemoveIt = True36                RemoveIt = True
37                break37                break
38        if not RemoveIt:38        if not RemoveIt:
39            print('Item not found in cart. Nothing removed.')39            print('Item not found in cart. Nothing removed.')
40    def modify_item(self, itemToPurchase):40    def modify_item(self, itemToPurchase):
n41        Modify_It = Falsen41        ModifyIt = False
42        for i in range(len(self.cart_items)):42        for i in range(len(self.cart_items)):
43            if self.cart_items[i].item_name == itemToPurchase.item_name:43            if self.cart_items[i].item_name == itemToPurchase.item_name:
n44                Modify_It = Truen44                ModifyIt = True
45                if (45                if (
46                        itemToPurchase.item_price == 0 and itemToPurchase.item_q46                        itemToPurchase.item_price == 0 and itemToPurchase.item_q
>uantity == 0 and itemToPurchase.item_description == 'none'):>uantity == 0 and itemToPurchase.item_description == 'none'):
47                    break47                    break
48                else:48                else:
49                    if (itemToPurchase.item_price != 0):49                    if (itemToPurchase.item_price != 0):
50                        self.cart_items[i].item_price = itemToPurchase.item_pric50                        self.cart_items[i].item_price = itemToPurchase.item_pric
>e>e
51                    if (itemToPurchase.item_quantity != 0):51                    if (itemToPurchase.item_quantity != 0):
52                        self.cart_items[i].item_quantity = itemToPurchase.item_q52                        self.cart_items[i].item_quantity = itemToPurchase.item_q
>uantity>uantity
53                    if (itemToPurchase.item_description != 'none'):53                    if (itemToPurchase.item_description != 'none'):
54                        self.cart_items[i].item_description = itemToPurchase.ite54                        self.cart_items[i].item_description = itemToPurchase.ite
>m_description>m_description
55                    break55                    break
n56        if not Modify_It:n56        if not ModifyIt:
57            print('Item not found in cart. Nothing modified.')57            print('Item not found in cart. Nothing modified.')
58    def get_num_items_in_cart(self):58    def get_num_items_in_cart(self):
59        num_items = 059        num_items = 0
60        for item in self.cart_items:60        for item in self.cart_items:
61            num_items = num_items + item.item_quantity61            num_items = num_items + item.item_quantity
62        return num_items62        return num_items
63    def get_cost_of_cart(self):63    def get_cost_of_cart(self):
64        total_cost = 064        total_cost = 0
65        cost = 065        cost = 0
66        for item in self.cart_items:66        for item in self.cart_items:
67            cost = (item.item_quantity * item.item_price)67            cost = (item.item_quantity * item.item_price)
68            total_cost += cost68            total_cost += cost
69        return total_cost69        return total_cost
70    def print_total(self):70    def print_total(self):
71        total_cost = self.get_cost_of_cart()71        total_cost = self.get_cost_of_cart()
72        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current72        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date))>_date))
73        print('Number of Items: %d\n' % self.get_num_items_in_cart())73        print('Number of Items: %d\n' % self.get_num_items_in_cart())
74        for item in self.cart_items:74        for item in self.cart_items:
75            item.print_item_cost()75            item.print_item_cost()
76        if (total_cost == 0):76        if (total_cost == 0):
77            print('SHOPPING CART IS EMPTY')77            print('SHOPPING CART IS EMPTY')
78        print('\nTotal: $%d' % (total_cost))78        print('\nTotal: $%d' % (total_cost))
79    def print_descriptions(self):79    def print_descriptions(self):
80        if len(self.cart_items) == 0:80        if len(self.cart_items) == 0:
81            print('SHOPPING CART IS EMPTY')81            print('SHOPPING CART IS EMPTY')
82        else:82        else:
83            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur83            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur
>rent_date))>rent_date))
84            print('\nItem Descriptions')84            print('\nItem Descriptions')
85            for item in self.cart_items:85            for item in self.cart_items:
86                item.print_item_description()86                item.print_item_description()
87def print_menu():87def print_menu():
88    print('MENU\n'88    print('MENU\n'
89            'a - Add item to cart\n'89            'a - Add item to cart\n'
90            'r - Remove item from cart\n'90            'r - Remove item from cart\n'
91            'c - Change item quantity\n'91            'c - Change item quantity\n'
92            "i - Output items' descriptions\n"92            "i - Output items' descriptions\n"
93            'o - Output shopping cart\n'93            'o - Output shopping cart\n'
94            'q - Quit\n')94            'q - Quit\n')
95def execute_menu(command, my_cart):95def execute_menu(command, my_cart):
96    customer_Cart = my_cart96    customer_Cart = my_cart
97    if command == 'a':97    if command == 'a':
98        print("\nADD ITEM TO CART")98        print("\nADD ITEM TO CART")
99        item_name = input('Enter the item name:\n')99        item_name = input('Enter the item name:\n')
100        item_description = input('Enter the item description:\n')100        item_description = input('Enter the item description:\n')
101        item_price = int(input('Enter the item price:\n'))101        item_price = int(input('Enter the item price:\n'))
102        item_quantity = int(input('Enter the item quantity:\n'))102        item_quantity = int(input('Enter the item quantity:\n'))
103        itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity, it103        itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity, it
>em_description)>em_description)
104        customer_Cart.add_item(itemtoPurchase)104        customer_Cart.add_item(itemtoPurchase)
105    elif command == 'o':105    elif command == 'o':
106        print('OUTPUT SHOPPING CART')106        print('OUTPUT SHOPPING CART')
107        customer_Cart.print_total()107        customer_Cart.print_total()
108    elif command == 'i':108    elif command == 'i':
109        print('\nOUTPUT ITEMS\' DESCRIPTIONS')109        print('\nOUTPUT ITEMS\' DESCRIPTIONS')
110        customer_Cart.print_descriptions()110        customer_Cart.print_descriptions()
111    elif command == 'r':111    elif command == 'r':
112        print('REMOVE ITEM FROM CART')112        print('REMOVE ITEM FROM CART')
113        itemName = input('Enter name of item to remove:\n')113        itemName = input('Enter name of item to remove:\n')
114        customer_Cart.remove_item(itemName)114        customer_Cart.remove_item(itemName)
115    elif command == 'c':115    elif command == 'c':
116        print('\nCHANGE ITEM QUANTITY')116        print('\nCHANGE ITEM QUANTITY')
117        itemName = input('Enter the item name:\n')117        itemName = input('Enter the item name:\n')
118        qty = int(input('Enter the new quantity:\n'))118        qty = int(input('Enter the new quantity:\n'))
119        itemToPurchase = ItemToPurchase(itemName, 0, qty)119        itemToPurchase = ItemToPurchase(itemName, 0, qty)
120        customer_Cart.modify_item(itemToPurchase)120        customer_Cart.modify_item(itemToPurchase)
121if __name__ == "__main__":121if __name__ == "__main__":
122    customer_name = input("Enter customer's name:\n")122    customer_name = input("Enter customer's name:\n")
123    current_date = input("Enter today's date:\n")123    current_date = input("Enter today's date:\n")
124    print("\nCustomer name: %s" % customer_name)124    print("\nCustomer name: %s" % customer_name)
125    print("Today's date: %s" % current_date)125    print("Today's date: %s" % current_date)
126    newCart = ShoppingCart(customer_name, current_date)126    newCart = ShoppingCart(customer_name, current_date)
127    command = ''127    command = ''
128    while command != 'q':128    while command != 'q':
129        print()129        print()
130        print_menu()130        print_menu()
131        command = input('Choose an option:\n')131        command = input('Choose an option:\n')
132        while command != 'a' and command != 'o' and command != 'i' and command !132        while command != 'a' and command != 'o' and command != 'i' and command !
>= 'q' and command != 'r' and command != 'c':>= 'q' and command != 'r' and command != 'c':
133            command = input('Choose an option:\n')133            command = input('Choose an option:\n')
134        execute_menu(command, newCart)import math134        execute_menu(command, newCart)import math
135class pt3d:135class pt3d:
136    def __init__(self,x=0,y=0,z=0):136    def __init__(self,x=0,y=0,z=0):
137        self.x= x137        self.x= x
138        self.y= y138        self.y= y
139        self.z= z139        self.z= z
140    def __add__(self, other):140    def __add__(self, other):
141        x = self.x + other.x141        x = self.x + other.x
142        y = self.y + other.y142        y = self.y + other.y
143        z = self.z + other.z143        z = self.z + other.z
144        return pt3d(x, y,z)144        return pt3d(x, y,z)
145    def __sub__(self, other):145    def __sub__(self, other):
146        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 146        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>2)+math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
147    def __eq__(self, other):147    def __eq__(self, other):
148        return other.x==self.x and other.y==self.y and other.z==self.z148        return other.x==self.x and other.y==self.y and other.z==self.z
149    def __str__(self):149    def __str__(self):
150        return "<{0},{1},{2}>".format(self.x, self.y, self.z)150        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
151if __name__ == '__main__':151if __name__ == '__main__':
t152    p_1 = pt3d(1, 1, 1)t152    p1 = pt3d(1, 1, 1)
153    p_2 = pt3d(2, 2, 2)153    p2 = pt3d(2, 2, 2)
154    print(p_1+p_2)154    print(p1+p2)
155    print(p_1-p_2)155    print(p1-p2)
156    print(p_1==p_2)156    print(p1==p2)
157    print(p_1+p_1==p_2)157    print(p1+p1==p2)
158    print(p_1==p_2+pt3d(-1,-1,-1))158    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 5

Student ID: 88, P-Value: 3.62e-05

Nearest Neighbor ID: 279

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle:n2class Circle():
3    def __init__(self, radius):3    def __init__(self, radius):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
n6        return math.pi*(self.radius**2)n6        return math.pi * self.radius**2
7    def perimeter(self):7    def perimeter(self):
8        return 2*math.pi*self.radius8        return 2*math.pi*self.radius
n9if __name__=='__main__':n9if __name__ == '__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
n13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:n13    print('{:.5f}'.format(NewCircle.perimeter()))
14class ItemToPurchase:
14   def __init__(self, name='none', price=0, quantity=0, description='none'):15   def __init__(self, name='none', price=0, quantity=0, description='none'):
15       self.item_name=name16       self.item_name=name
16       self.item_description=description17       self.item_description=description
17       self.item_price=price18       self.item_price=price
18       self.item_quantity=quantity19       self.item_quantity=quantity
19   def print_item_description(self):20   def print_item_description(self):
20       print('%s: %s' % (self.item_name, self.item_description))21       print('%s: %s' % (self.item_name, self.item_description))
21class ShoppingCart:22class ShoppingCart:
22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 23   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
23       self.customer_name = customer_name24       self.customer_name = customer_name
24       self.current_date = current_date25       self.current_date = current_date
25       self.cart_items = cart_items  26       self.cart_items = cart_items  
26   def add_item(self, itemToPurchase):27   def add_item(self, itemToPurchase):
27       self.cart_items.append(itemToPurchase)  28       self.cart_items.append(itemToPurchase)  
28   def remove_item(self, itemName):29   def remove_item(self, itemName):
29       tremove_item = False30       tremove_item = False
30       for item in self.cart_items:31       for item in self.cart_items:
31           if item.item_name == itemName:32           if item.item_name == itemName:
32               self.cart_items.remove(item)33               self.cart_items.remove(item)
33               tremove_item = True34               tremove_item = True
34               break35               break
35       if not tremove_item:          36       if not tremove_item:          
n36           print('Item not found in the cart. Nothing removed.')n37           print('Item not found in the cart. Nothing removed')
37   def modify_item(self, itemToPurchase):  38   def modify_item(self, itemToPurchase):  
38       tmodify_item = False39       tmodify_item = False
39       for i in range(len(self.cart_items)):40       for i in range(len(self.cart_items)):
40           if self.cart_items[i].item_name == itemToPurchase.item_name:41           if self.cart_items[i].item_name == itemToPurchase.item_name:
41               tmodify_item = True42               tmodify_item = True
42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity43               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43               break44               break
44       if not tmodify_item:      45       if not tmodify_item:      
n45           print('Item not found in the cart. Nothing modified.')  n46           print('Item not found in the cart. Nothing modified')  
46   def get_num_items_in_cart(self):47   def get_num_items_in_cart(self):
47       num_items = 048       num_items = 0
48       for item in self.cart_items:49       for item in self.cart_items:
49           num_items = num_items + item.item_quantity50           num_items = num_items + item.item_quantity
50       return num_items51       return num_items
51   def get_cost_of_cart(self):52   def get_cost_of_cart(self):
52       total_cost = 053       total_cost = 0
53       cost = 054       cost = 0
54       for item in self.cart_items:55       for item in self.cart_items:
55           cost = (item.item_quantity * item.item_price)56           cost = (item.item_quantity * item.item_price)
56           total_cost += cost57           total_cost += cost
57       return total_cost58       return total_cost
58   def print_total(self):59   def print_total(self):
59       total_cost = self.get_cost_of_cart()60       total_cost = self.get_cost_of_cart()
60       if (total_cost == 0):61       if (total_cost == 0):
61           print('SHOPPING CART IS EMPTY')62           print('SHOPPING CART IS EMPTY')
62       else:63       else:
63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr64           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
64           print('Number of Items: %d\n' %self.get_num_items_in_cart())65           print('Number of Items: %d\n' %self.get_num_items_in_cart())
65           for item in self.cart_items:66           for item in self.cart_items:
66               total = item.item_price * item.item_quantity67               total = item.item_price * item.item_quantity
67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 68               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
68           print('\nTotal: $%d' %(total_cost))69           print('\nTotal: $%d' %(total_cost))
69   def print_descriptions(self):70   def print_descriptions(self):
70       if len(self.cart_items) == 0:71       if len(self.cart_items) == 0:
71           print('SHOPPING CART IS EMPTY')72           print('SHOPPING CART IS EMPTY')
72       else:  73       else:  
73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr74           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
74           print('\nItem Descriptions')75           print('\nItem Descriptions')
75           for item in self.cart_items:76           for item in self.cart_items:
76               item.print_item_description()  77               item.print_item_description()  
77def print_menu(newCart):78def print_menu(newCart):
78   customer_Cart = newCart79   customer_Cart = newCart
79   menu = ('\nMENU\n'80   menu = ('\nMENU\n'
80       'a - Add item to cart\n'81       'a - Add item to cart\n'
n81       'r - Remove item from cart\n'n82       'r - Remove item from the cart\n'
82       'c - Change item quantity\n'83       'c - Change item quantity\n'
n83       "i - Output items' descriptions\n"n84       "i - Output item's descriptions\n"
84       'o - Output shopping cart\n'85       'o - Output shopping cart\n'
85       'q - Quit\n')86       'q - Quit\n')
86   command = ''87   command = ''
87   while(command != 'q'):88   while(command != 'q'):
88       print(menu)89       print(menu)
n89       command = input('Choose an option:\n')n90       command = input('Choose an option:')
90       while(command != 'a' and command != 'o' and command != 'i' and command !=91       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
91           command = input('Choose an option:\n')92           command = input('Choose an option:\n')
92       if(command == 'a'):93       if(command == 'a'):
93           print("\nADD ITEM TO CART")94           print("\nADD ITEM TO CART")
94           item_name = input('Enter the item name:\n')95           item_name = input('Enter the item name:\n')
95           item_description = input('Enter the item description:\n')96           item_description = input('Enter the item description:\n')
96           item_price = int(input('Enter the item price:\n'))97           item_price = int(input('Enter the item price:\n'))
97           item_quantity = int(input('Enter the item quantity:\n'))98           item_quantity = int(input('Enter the item quantity:\n'))
98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,99           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
99           customer_Cart.add_item(itemtoPurchase)100           customer_Cart.add_item(itemtoPurchase)
100       elif(command == 'o'):101       elif(command == 'o'):
101           print('\nOUTPUT SHOPPING CART')102           print('\nOUTPUT SHOPPING CART')
102           customer_Cart.print_total()  103           customer_Cart.print_total()  
103       elif(command == 'i'):104       elif(command == 'i'):
104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')105           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
105           customer_Cart.print_descriptions()106           customer_Cart.print_descriptions()
106       elif(command == 'r'):107       elif(command == 'r'):
107           print('REMOVE ITEM FROM CART')108           print('REMOVE ITEM FROM CART')
n108           itemName = input('Enter name of item to remove :\n')n109           itemName = input('Enter the name of the item to remove :\n')
109           customer_Cart.remove_item(itemName)110           customer_Cart.remove_item(itemName)
110       elif(command == 'c'):111       elif(command == 'c'):
111           print('\nCHANGE ITEM QUANTITY')112           print('\nCHANGE ITEM QUANTITY')
n112           itemName = input('Enter name of item :\n')n113           itemName = input('Enter the name of the item :\n')
113           qty = int(input('Enter the new quantity :\n'))114           qty = int(input('Enter the new quantity :\n'))
114           itemToPurchase = ItemToPurchase(itemName,0,qty)115           itemToPurchase = ItemToPurchase(itemName,0,qty)
115           customer_Cart.modify_item(itemToPurchase)116           customer_Cart.modify_item(itemToPurchase)
116if __name__ == "__main__":117if __name__ == "__main__":
117   customer_name = input("Enter customer's name:\n")118   customer_name = input("Enter customer's name:\n")
118   current_date = input("Enter today's date:\n")119   current_date = input("Enter today's date:\n")
119   print("\nCustomer name: %s" %customer_name)120   print("\nCustomer name: %s" %customer_name)
120   print("Today's date: %s" %current_date)121   print("Today's date: %s" %current_date)
121   newCart = ShoppingCart(customer_name, current_date)122   newCart = ShoppingCart(customer_name, current_date)
122   print_menu(newCart)from math import sqrt123   print_menu(newCart)from math import sqrt
123class pt3d:124class pt3d:
124    def __init__(self, x, y, z):125    def __init__(self, x, y, z):
125        self.x = x126        self.x = x
126        self.y = y127        self.y = y
127        self.z = z128        self.z = z
128    def __add__(self, other):129    def __add__(self, other):
129        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)130        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
130    def __sub__(self, other):131    def __sub__(self, other):
131        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot132        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>her.z)**2)>her.z)**2)
132    def __eq__(self, other):133    def __eq__(self, other):
t133        return self.x == other.x and self.y == other.y and self.z == other.zt134        return self.x == other.x & self.y == other.y & self.z == other.z
134    def __str__(self):135    def __str__(self):
135        return '<{}, {}, {}>'.format(self.x, self.y, self.z)136        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
136p1 = pt3d(1, 1, 1)137p1 = pt3d(1, 1, 1)
137p2 = pt3d(2, 2, 2)138p2 = pt3d(2, 2, 2)
138print(p1 + p2)139print(p1 + p2)
139print(p1 - p2)140print(p1 - p2)
140print(p1 == p2)141print(p1 == p2)
141print(p1+p1 == p2)142print(p1+p1 == p2)
142print(p1==p2+pt3d(-1, -1, -1))143print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 6

Student ID: 492, P-Value: 4.30e-05

Nearest Neighbor ID: 278

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
3    def __init__(self, rad):3    def __init__(self, rad):
n4        self.radius = radn4        self.r = rad
5    def area(self):5    def area(self):
n6        return (self.radius**2)*math.pin6        return (self.r**2)*math.pi
7    def perimeter(self):7    def perimeter(self):
n8        return self.radius*2*math.pin8        return self.r*2*math.pi
9if __name__ == '__main__':9if __name__ == '__main__':
t10    x = int(input(""))t10    i = int(input(""))
11    NewCircle = circle(x)11    NewCircle = Circle(i)
12    print(NewCircle.area())12    print(NewCircle.area())
13    print(NewCircle.perimeter())class ItemToPurchase:13    print(NewCircle.perimeter())class ItemToPurchase:
14   def __init__(self, name='none', price=0, quantity=0, description='none'):14   def __init__(self, name='none', price=0, quantity=0, description='none'):
15       self.item_name=name15       self.item_name=name
16       self.item_description=description16       self.item_description=description
17       self.item_price=price17       self.item_price=price
18       self.item_quantity=quantity18       self.item_quantity=quantity
19   def print_item_description(self):19   def print_item_description(self):
20       print('%s: %s' % (self.item_name, self.item_description))20       print('%s: %s' % (self.item_name, self.item_description))
21class ShoppingCart:21class ShoppingCart:
22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
23       self.customer_name = customer_name23       self.customer_name = customer_name
24       self.current_date = current_date24       self.current_date = current_date
25       self.cart_items = cart_items  25       self.cart_items = cart_items  
26   def add_item(self, itemToPurchase):26   def add_item(self, itemToPurchase):
27       self.cart_items.append(itemToPurchase)  27       self.cart_items.append(itemToPurchase)  
28   def remove_item(self, itemName):28   def remove_item(self, itemName):
29       tremove_item = False29       tremove_item = False
30       for item in self.cart_items:30       for item in self.cart_items:
31           if item.item_name == itemName:31           if item.item_name == itemName:
32               self.cart_items.remove(item)32               self.cart_items.remove(item)
33               tremove_item = True33               tremove_item = True
34               break34               break
35       if not tremove_item:          35       if not tremove_item:          
36           print('Item not found in cart. Nothing removed.')36           print('Item not found in cart. Nothing removed.')
37   def modify_item(self, itemToPurchase):  37   def modify_item(self, itemToPurchase):  
38       tmodify_item = False38       tmodify_item = False
39       for i in range(len(self.cart_items)):39       for i in range(len(self.cart_items)):
40           if self.cart_items[i].item_name == itemToPurchase.item_name:40           if self.cart_items[i].item_name == itemToPurchase.item_name:
41               tmodify_item = True41               tmodify_item = True
42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43               break43               break
44       if not tmodify_item:      44       if not tmodify_item:      
45           print('Item not found in cart. Nothing modified.')  45           print('Item not found in cart. Nothing modified.')  
46   def get_num_items_in_cart(self):46   def get_num_items_in_cart(self):
47       num_items = 047       num_items = 0
48       for item in self.cart_items:48       for item in self.cart_items:
49           num_items = num_items + item.item_quantity49           num_items = num_items + item.item_quantity
50       return num_items50       return num_items
51   def get_cost_of_cart(self):51   def get_cost_of_cart(self):
52       total_cost = 052       total_cost = 0
53       cost = 053       cost = 0
54       for item in self.cart_items:54       for item in self.cart_items:
55           cost = (item.item_quantity * item.item_price)55           cost = (item.item_quantity * item.item_price)
56           total_cost += cost56           total_cost += cost
57       return total_cost57       return total_cost
58   def print_total(self):58   def print_total(self):
59       total_cost = self.get_cost_of_cart()59       total_cost = self.get_cost_of_cart()
60       if (total_cost == 0):60       if (total_cost == 0):
61           print('SHOPPING CART IS EMPTY')61           print('SHOPPING CART IS EMPTY')
62       else:62       else:
63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
64           print('Number of Items: %d\n' %self.get_num_items_in_cart())64           print('Number of Items: %d\n' %self.get_num_items_in_cart())
65           for item in self.cart_items:65           for item in self.cart_items:
66               total = item.item_price * item.item_quantity66               total = item.item_price * item.item_quantity
67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
68           print('\nTotal: $%d' %(total_cost))68           print('\nTotal: $%d' %(total_cost))
69   def print_descriptions(self):69   def print_descriptions(self):
70       if len(self.cart_items) == 0:70       if len(self.cart_items) == 0:
71           print('SHOPPING CART IS EMPTY')71           print('SHOPPING CART IS EMPTY')
72       else:  72       else:  
73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
74           print('\nItem Descriptions')74           print('\nItem Descriptions')
75           for item in self.cart_items:75           for item in self.cart_items:
76               item.print_item_description()  76               item.print_item_description()  
77def print_menu(newCart):77def print_menu(newCart):
78   customer_Cart = newCart78   customer_Cart = newCart
79   menu = ('\nMENU\n'79   menu = ('\nMENU\n'
80       'a - Add item to cart\n'80       'a - Add item to cart\n'
81       'r - Remove item from cart\n'81       'r - Remove item from cart\n'
82       'c - Change item quantity\n'82       'c - Change item quantity\n'
83       "i - Output items' descriptions\n"83       "i - Output items' descriptions\n"
84       'o - Output shopping cart\n'84       'o - Output shopping cart\n'
85       'q - Quit\n')85       'q - Quit\n')
86   command = ''86   command = ''
87   while(command != 'q'):87   while(command != 'q'):
88       print(menu)88       print(menu)
89       command = input('Choose an option:\n')89       command = input('Choose an option:\n')
90       while(command != 'a' and command != 'o' and command != 'i' and command !=90       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
91           command = input('Choose an option:\n')91           command = input('Choose an option:\n')
92       if(command == 'a'):92       if(command == 'a'):
93           print("\nADD ITEM TO CART")93           print("\nADD ITEM TO CART")
94           item_name = input('Enter the item name:\n')94           item_name = input('Enter the item name:\n')
95           item_description = input('Enter the item description:\n')95           item_description = input('Enter the item description:\n')
96           item_price = int(input('Enter the item price:\n'))96           item_price = int(input('Enter the item price:\n'))
97           item_quantity = int(input('Enter the item quantity:\n'))97           item_quantity = int(input('Enter the item quantity:\n'))
98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
99           customer_Cart.add_item(itemtoPurchase)99           customer_Cart.add_item(itemtoPurchase)
100       elif(command == 'o'):100       elif(command == 'o'):
101           print('OUTPUT SHOPPING CART')101           print('OUTPUT SHOPPING CART')
102           customer_Cart.print_total()  102           customer_Cart.print_total()  
103       elif(command == 'i'):103       elif(command == 'i'):
104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
105           customer_Cart.print_descriptions()105           customer_Cart.print_descriptions()
106       elif(command == 'r'):106       elif(command == 'r'):
107           print('REMOVE ITEM FROM CART')107           print('REMOVE ITEM FROM CART')
108           itemName = input('Enter name of item to remove:\n')108           itemName = input('Enter name of item to remove:\n')
109           customer_Cart.remove_item(itemName)109           customer_Cart.remove_item(itemName)
110       elif(command == 'c'):110       elif(command == 'c'):
111           print('\nCHANGE ITEM QUANTITY')111           print('\nCHANGE ITEM QUANTITY')
112           itemName = input('Enter name of item :\n')112           itemName = input('Enter name of item :\n')
113           qty = int(input('Enter the new quantity :\n'))113           qty = int(input('Enter the new quantity :\n'))
114           itemToPurchase = ItemToPurchase(itemName,0,qty)114           itemToPurchase = ItemToPurchase(itemName,0,qty)
115           customer_Cart.modify_item(itemToPurchase)115           customer_Cart.modify_item(itemToPurchase)
116if __name__ == "__main__":116if __name__ == "__main__":
117   customer_name = input("Enter customer's name:\n")117   customer_name = input("Enter customer's name:\n")
118   current_date = input("Enter today's date:\n")118   current_date = input("Enter today's date:\n")
119   print("\nCustomer name: %s" %customer_name)119   print("\nCustomer name: %s" %customer_name)
120   print("Today's date: %s" %current_date)120   print("Today's date: %s" %current_date)
121   newCart = ShoppingCart(customer_name, current_date)121   newCart = ShoppingCart(customer_name, current_date)
122   print_menu(newCart)  import math122   print_menu(newCart)  import math
123class pt3d:123class pt3d:
124    def __init__(self,x=0,y=0,z=0):124    def __init__(self,x=0,y=0,z=0):
125        self.x= x125        self.x= x
126        self.y= y126        self.y= y
127        self.z= z127        self.z= z
128    def __add__(self, other):128    def __add__(self, other):
129        x = self.x + other.x129        x = self.x + other.x
130        y = self.y + other.y130        y = self.y + other.y
131        z = self.z + other.z131        z = self.z + other.z
132        return pt3d(x, y,z)132        return pt3d(x, y,z)
133    def __sub__(self, other):133    def __sub__(self, other):
134        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 134        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>2)+math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
135    def __eq__(self, other):135    def __eq__(self, other):
136        return other.x==self.x and other.y==self.y and other.z==self.z136        return other.x==self.x and other.y==self.y and other.z==self.z
137    def __str__(self):137    def __str__(self):
138        return "<{0},{1},{2}>".format(self.x, self.y, self.z)138        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
139if __name__ == '__main__':139if __name__ == '__main__':
140    p1 = pt3d(1, 1, 1)140    p1 = pt3d(1, 1, 1)
141    p2 = pt3d(2, 2, 2)141    p2 = pt3d(2, 2, 2)
142    print(p1+p2)142    print(p1+p2)
143    print(p1-p2)143    print(p1-p2)
144    print(p1==p2)144    print(p1==p2)
145    print(p1+p1==p2)145    print(p1+p1==p2)
146    print(p1==p2+pt3d(-1,-1,-1))146    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 7

Student ID: 278, P-Value: 4.30e-05

Nearest Neighbor ID: 492

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
3    def __init__(self, rad):3    def __init__(self, rad):
n4        self.r = radn4        self.radius = rad
5    def area(self):5    def area(self):
n6        return (self.r**2)*math.pin6        return (self.radius**2)*math.pi
7    def perimeter(self):7    def perimeter(self):
n8        return self.r*2*math.pin8        return self.radius*2*math.pi
9if __name__ == '__main__':9if __name__ == '__main__':
t10    i = int(input(""))t10    x = int(input(""))
11    NewCircle = Circle(i)11    NewCircle = circle(x)
12    print(NewCircle.area())12    print(NewCircle.area())
13    print(NewCircle.perimeter())class ItemToPurchase:13    print(NewCircle.perimeter())class ItemToPurchase:
14   def __init__(self, name='none', price=0, quantity=0, description='none'):14   def __init__(self, name='none', price=0, quantity=0, description='none'):
15       self.item_name=name15       self.item_name=name
16       self.item_description=description16       self.item_description=description
17       self.item_price=price17       self.item_price=price
18       self.item_quantity=quantity18       self.item_quantity=quantity
19   def print_item_description(self):19   def print_item_description(self):
20       print('%s: %s' % (self.item_name, self.item_description))20       print('%s: %s' % (self.item_name, self.item_description))
21class ShoppingCart:21class ShoppingCart:
22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
23       self.customer_name = customer_name23       self.customer_name = customer_name
24       self.current_date = current_date24       self.current_date = current_date
25       self.cart_items = cart_items  25       self.cart_items = cart_items  
26   def add_item(self, itemToPurchase):26   def add_item(self, itemToPurchase):
27       self.cart_items.append(itemToPurchase)  27       self.cart_items.append(itemToPurchase)  
28   def remove_item(self, itemName):28   def remove_item(self, itemName):
29       tremove_item = False29       tremove_item = False
30       for item in self.cart_items:30       for item in self.cart_items:
31           if item.item_name == itemName:31           if item.item_name == itemName:
32               self.cart_items.remove(item)32               self.cart_items.remove(item)
33               tremove_item = True33               tremove_item = True
34               break34               break
35       if not tremove_item:          35       if not tremove_item:          
36           print('Item not found in cart. Nothing removed.')36           print('Item not found in cart. Nothing removed.')
37   def modify_item(self, itemToPurchase):  37   def modify_item(self, itemToPurchase):  
38       tmodify_item = False38       tmodify_item = False
39       for i in range(len(self.cart_items)):39       for i in range(len(self.cart_items)):
40           if self.cart_items[i].item_name == itemToPurchase.item_name:40           if self.cart_items[i].item_name == itemToPurchase.item_name:
41               tmodify_item = True41               tmodify_item = True
42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43               break43               break
44       if not tmodify_item:      44       if not tmodify_item:      
45           print('Item not found in cart. Nothing modified.')  45           print('Item not found in cart. Nothing modified.')  
46   def get_num_items_in_cart(self):46   def get_num_items_in_cart(self):
47       num_items = 047       num_items = 0
48       for item in self.cart_items:48       for item in self.cart_items:
49           num_items = num_items + item.item_quantity49           num_items = num_items + item.item_quantity
50       return num_items50       return num_items
51   def get_cost_of_cart(self):51   def get_cost_of_cart(self):
52       total_cost = 052       total_cost = 0
53       cost = 053       cost = 0
54       for item in self.cart_items:54       for item in self.cart_items:
55           cost = (item.item_quantity * item.item_price)55           cost = (item.item_quantity * item.item_price)
56           total_cost += cost56           total_cost += cost
57       return total_cost57       return total_cost
58   def print_total(self):58   def print_total(self):
59       total_cost = self.get_cost_of_cart()59       total_cost = self.get_cost_of_cart()
60       if (total_cost == 0):60       if (total_cost == 0):
61           print('SHOPPING CART IS EMPTY')61           print('SHOPPING CART IS EMPTY')
62       else:62       else:
63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
64           print('Number of Items: %d\n' %self.get_num_items_in_cart())64           print('Number of Items: %d\n' %self.get_num_items_in_cart())
65           for item in self.cart_items:65           for item in self.cart_items:
66               total = item.item_price * item.item_quantity66               total = item.item_price * item.item_quantity
67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
68           print('\nTotal: $%d' %(total_cost))68           print('\nTotal: $%d' %(total_cost))
69   def print_descriptions(self):69   def print_descriptions(self):
70       if len(self.cart_items) == 0:70       if len(self.cart_items) == 0:
71           print('SHOPPING CART IS EMPTY')71           print('SHOPPING CART IS EMPTY')
72       else:  72       else:  
73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
74           print('\nItem Descriptions')74           print('\nItem Descriptions')
75           for item in self.cart_items:75           for item in self.cart_items:
76               item.print_item_description()  76               item.print_item_description()  
77def print_menu(newCart):77def print_menu(newCart):
78   customer_Cart = newCart78   customer_Cart = newCart
79   menu = ('\nMENU\n'79   menu = ('\nMENU\n'
80       'a - Add item to cart\n'80       'a - Add item to cart\n'
81       'r - Remove item from cart\n'81       'r - Remove item from cart\n'
82       'c - Change item quantity\n'82       'c - Change item quantity\n'
83       "i - Output items' descriptions\n"83       "i - Output items' descriptions\n"
84       'o - Output shopping cart\n'84       'o - Output shopping cart\n'
85       'q - Quit\n')85       'q - Quit\n')
86   command = ''86   command = ''
87   while(command != 'q'):87   while(command != 'q'):
88       print(menu)88       print(menu)
89       command = input('Choose an option:\n')89       command = input('Choose an option:\n')
90       while(command != 'a' and command != 'o' and command != 'i' and command !=90       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
91           command = input('Choose an option:\n')91           command = input('Choose an option:\n')
92       if(command == 'a'):92       if(command == 'a'):
93           print("\nADD ITEM TO CART")93           print("\nADD ITEM TO CART")
94           item_name = input('Enter the item name:\n')94           item_name = input('Enter the item name:\n')
95           item_description = input('Enter the item description:\n')95           item_description = input('Enter the item description:\n')
96           item_price = int(input('Enter the item price:\n'))96           item_price = int(input('Enter the item price:\n'))
97           item_quantity = int(input('Enter the item quantity:\n'))97           item_quantity = int(input('Enter the item quantity:\n'))
98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
99           customer_Cart.add_item(itemtoPurchase)99           customer_Cart.add_item(itemtoPurchase)
100       elif(command == 'o'):100       elif(command == 'o'):
101           print('OUTPUT SHOPPING CART')101           print('OUTPUT SHOPPING CART')
102           customer_Cart.print_total()  102           customer_Cart.print_total()  
103       elif(command == 'i'):103       elif(command == 'i'):
104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
105           customer_Cart.print_descriptions()105           customer_Cart.print_descriptions()
106       elif(command == 'r'):106       elif(command == 'r'):
107           print('REMOVE ITEM FROM CART')107           print('REMOVE ITEM FROM CART')
108           itemName = input('Enter name of item to remove:\n')108           itemName = input('Enter name of item to remove:\n')
109           customer_Cart.remove_item(itemName)109           customer_Cart.remove_item(itemName)
110       elif(command == 'c'):110       elif(command == 'c'):
111           print('\nCHANGE ITEM QUANTITY')111           print('\nCHANGE ITEM QUANTITY')
112           itemName = input('Enter name of item :\n')112           itemName = input('Enter name of item :\n')
113           qty = int(input('Enter the new quantity :\n'))113           qty = int(input('Enter the new quantity :\n'))
114           itemToPurchase = ItemToPurchase(itemName,0,qty)114           itemToPurchase = ItemToPurchase(itemName,0,qty)
115           customer_Cart.modify_item(itemToPurchase)115           customer_Cart.modify_item(itemToPurchase)
116if __name__ == "__main__":116if __name__ == "__main__":
117   customer_name = input("Enter customer's name:\n")117   customer_name = input("Enter customer's name:\n")
118   current_date = input("Enter today's date:\n")118   current_date = input("Enter today's date:\n")
119   print("\nCustomer name: %s" %customer_name)119   print("\nCustomer name: %s" %customer_name)
120   print("Today's date: %s" %current_date)120   print("Today's date: %s" %current_date)
121   newCart = ShoppingCart(customer_name, current_date)121   newCart = ShoppingCart(customer_name, current_date)
122   print_menu(newCart)  import math122   print_menu(newCart)  import math
123class pt3d:123class pt3d:
124    def __init__(self,x=0,y=0,z=0):124    def __init__(self,x=0,y=0,z=0):
125        self.x= x125        self.x= x
126        self.y= y126        self.y= y
127        self.z= z127        self.z= z
128    def __add__(self, other):128    def __add__(self, other):
129        x = self.x + other.x129        x = self.x + other.x
130        y = self.y + other.y130        y = self.y + other.y
131        z = self.z + other.z131        z = self.z + other.z
132        return pt3d(x, y,z)132        return pt3d(x, y,z)
133    def __sub__(self, other):133    def __sub__(self, other):
134        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 134        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>2)+math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
135    def __eq__(self, other):135    def __eq__(self, other):
136        return other.x==self.x and other.y==self.y and other.z==self.z136        return other.x==self.x and other.y==self.y and other.z==self.z
137    def __str__(self):137    def __str__(self):
138        return "<{0},{1},{2}>".format(self.x, self.y, self.z)138        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
139if __name__ == '__main__':139if __name__ == '__main__':
140    p1 = pt3d(1, 1, 1)140    p1 = pt3d(1, 1, 1)
141    p2 = pt3d(2, 2, 2)141    p2 = pt3d(2, 2, 2)
142    print(p1+p2)142    print(p1+p2)
143    print(p1-p2)143    print(p1-p2)
144    print(p1==p2)144    print(p1==p2)
145    print(p1+p1==p2)145    print(p1+p1==p2)
146    print(p1==p2+pt3d(-1,-1,-1))146    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 8

Student ID: 53, P-Value: 7.95e-05

Nearest Neighbor ID: 345

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle():n2class Circle:
3    def __init__(self, r):3    def __init__(self, r):
4        self.radius = r4        self.radius = r
5    def area(self):5    def area(self):
n6        return self.radius**2*math.pin6        return (self.radius**2)*(math.pi)
7    def perimeter(self):7    def perimeter(self):
n8        return 2*self.radius*math.pin8        return 2*(math.pi)*(self.radius)        
9if __name__=='__main__':
10    x = int(input())
9NewCircle = Circle(8)11    NewCircle = Circle(x)
10print(NewCircle.area())12    print('{:.5f}'.format(NewCircle.area()))
11print(NewCircle.perimeter())class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
12    def __init__(self, item_name = "none", item_price = 0, item_quantity = 0, it14    def __init__(self, item_name = "none", item_price = 0, item_quantity = 0, it
>em_description = "none"):>em_description = "none"):
13        self.item_name = item_name15        self.item_name = item_name
14        self.item_price = item_price16        self.item_price = item_price
15        self.item_quantity = item_quantity17        self.item_quantity = item_quantity
16        self.item_description = item_description18        self.item_description = item_description
17    def print_item_cost(self):19    def print_item_cost(self):
18        print(self.item_name + " " + str(self.item_quantity) + " @ $" + str(self20        print(self.item_name + " " + str(self.item_quantity) + " @ $" + str(self
>.item_price) + " = $" +>.item_price) + " = $" +
19              str(self.item_price * self.item_quantity))21              str(self.item_price * self.item_quantity))
20    def print_item_description(self):22    def print_item_description(self):
21        print(self.item_name + ": " + str(self.item_description))23        print(self.item_name + ": " + str(self.item_description))
22class ShoppingCart:24class ShoppingCart:
23    def __init__(self, customer_name='none', current_date='January 1, 2016'):25    def __init__(self, customer_name='none', current_date='January 1, 2016'):
24        self.customer_name = customer_name26        self.customer_name = customer_name
25        self.current_date = current_date27        self.current_date = current_date
26        self.cart_items = []28        self.cart_items = []
27    def add_item(self, ItemToPurchase):29    def add_item(self, ItemToPurchase):
28        self.cart_items.append(ItemToPurchase)30        self.cart_items.append(ItemToPurchase)
29    def remove_item(self, itemName):31    def remove_item(self, itemName):
30        RemoveIt = False32        RemoveIt = False
31        for item in self.cart_items:33        for item in self.cart_items:
32            if item.item_name == itemName:34            if item.item_name == itemName:
33                self.cart_items.remove(item)35                self.cart_items.remove(item)
34                RemoveIt = True36                RemoveIt = True
35                break37                break
36        if not RemoveIt:38        if not RemoveIt:
37            print('Item not found in cart. Nothing removed.')39            print('Item not found in cart. Nothing removed.')
38    def modify_item(self, itemToPurchase):40    def modify_item(self, itemToPurchase):
39        ModifyIt = False41        ModifyIt = False
40        for i in range(len(self.cart_items)):42        for i in range(len(self.cart_items)):
41            if self.cart_items[i].item_name == itemToPurchase.item_name:43            if self.cart_items[i].item_name == itemToPurchase.item_name:
42                ModifyIt = True44                ModifyIt = True
43                if (45                if (
44                        itemToPurchase.item_price == 0 and itemToPurchase.item_q46                        itemToPurchase.item_price == 0 and itemToPurchase.item_q
>uantity == 0 and itemToPurchase.item_description == 'none'):>uantity == 0 and itemToPurchase.item_description == 'none'):
45                    break47                    break
46                else:48                else:
47                    if (itemToPurchase.item_price != 0):49                    if (itemToPurchase.item_price != 0):
48                        self.cart_items[i].item_price = itemToPurchase.item_pric50                        self.cart_items[i].item_price = itemToPurchase.item_pric
>e>e
49                    if (itemToPurchase.item_quantity != 0):51                    if (itemToPurchase.item_quantity != 0):
50                        self.cart_items[i].item_quantity = itemToPurchase.item_q52                        self.cart_items[i].item_quantity = itemToPurchase.item_q
>uantity>uantity
51                    if (itemToPurchase.item_description != 'none'):53                    if (itemToPurchase.item_description != 'none'):
52                        self.cart_items[i].item_description = itemToPurchase.ite54                        self.cart_items[i].item_description = itemToPurchase.ite
>m_description>m_description
53                    break55                    break
54        if not ModifyIt:56        if not ModifyIt:
55            print('Item not found in cart. Nothing modified.')57            print('Item not found in cart. Nothing modified.')
nn58    def get_num_items_in_cart(self):
59        num_items = 0
60        for item in self.cart_items:
61            num_items = num_items + item.item_quantity
62        return num_items
56    def get_cost_of_cart(self):63    def get_cost_of_cart(self):
57        total_cost = 064        total_cost = 0
58        cost = 065        cost = 0
59        for item in self.cart_items:66        for item in self.cart_items:
60            cost = (item.item_quantity * item.item_price)67            cost = (item.item_quantity * item.item_price)
61            total_cost += cost68            total_cost += cost
62        return total_cost69        return total_cost
n63    def get_num_items_in_cart(self):n
64        num_items = 0
65        for item in self.cart_items:
66            num_items = num_items + item.item_quantity
67        return num_items
68    def print_total(self):70    def print_total(self):
69        total_cost = self.get_cost_of_cart()71        total_cost = self.get_cost_of_cart()
70        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current72        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date))>_date))
71        print('Number of Items: %d\n' % self.get_num_items_in_cart())73        print('Number of Items: %d\n' % self.get_num_items_in_cart())
72        for item in self.cart_items:74        for item in self.cart_items:
73            item.print_item_cost()75            item.print_item_cost()
74        if (total_cost == 0):76        if (total_cost == 0):
75            print('SHOPPING CART IS EMPTY')77            print('SHOPPING CART IS EMPTY')
76        print('\nTotal: $%d' % (total_cost))78        print('\nTotal: $%d' % (total_cost))
77    def print_descriptions(self):79    def print_descriptions(self):
78        if len(self.cart_items) == 0:80        if len(self.cart_items) == 0:
79            print('SHOPPING CART IS EMPTY')81            print('SHOPPING CART IS EMPTY')
80        else:82        else:
81            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur83            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur
>rent_date))>rent_date))
82            print('\nItem Descriptions')84            print('\nItem Descriptions')
83            for item in self.cart_items:85            for item in self.cart_items:
84                item.print_item_description()86                item.print_item_description()
85def print_menu():87def print_menu():
86    print('MENU\n'88    print('MENU\n'
87            'a - Add item to cart\n'89            'a - Add item to cart\n'
88            'r - Remove item from cart\n'90            'r - Remove item from cart\n'
89            'c - Change item quantity\n'91            'c - Change item quantity\n'
90            "i - Output items' descriptions\n"92            "i - Output items' descriptions\n"
91            'o - Output shopping cart\n'93            'o - Output shopping cart\n'
92            'q - Quit\n')94            'q - Quit\n')
93def execute_menu(command, my_cart):95def execute_menu(command, my_cart):
94    customer_Cart = my_cart96    customer_Cart = my_cart
95    if command == 'a':97    if command == 'a':
96        print("\nADD ITEM TO CART")98        print("\nADD ITEM TO CART")
97        item_name = input('Enter the item name:\n')99        item_name = input('Enter the item name:\n')
98        item_description = input('Enter the item description:\n')100        item_description = input('Enter the item description:\n')
99        item_price = int(input('Enter the item price:\n'))101        item_price = int(input('Enter the item price:\n'))
100        item_quantity = int(input('Enter the item quantity:\n'))102        item_quantity = int(input('Enter the item quantity:\n'))
101        itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity, it103        itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity, it
>em_description)>em_description)
102        customer_Cart.add_item(itemtoPurchase)104        customer_Cart.add_item(itemtoPurchase)
nn105    elif command == 'o':
106        print('OUTPUT SHOPPING CART')
107        customer_Cart.print_total()
108    elif command == 'i':
109        print('\nOUTPUT ITEMS\' DESCRIPTIONS')
110        customer_Cart.print_descriptions()
103    elif command == 'r':111    elif command == 'r':
104        print('REMOVE ITEM FROM CART')112        print('REMOVE ITEM FROM CART')
105        itemName = input('Enter name of item to remove:\n')113        itemName = input('Enter name of item to remove:\n')
106        customer_Cart.remove_item(itemName)114        customer_Cart.remove_item(itemName)
n107    elif command == 'o':n
108        print('OUTPUT SHOPPING CART')
109        customer_Cart.print_total()
110    elif command == 'c':115    elif command == 'c':
111        print('\nCHANGE ITEM QUANTITY')116        print('\nCHANGE ITEM QUANTITY')
112        itemName = input('Enter the item name:\n')117        itemName = input('Enter the item name:\n')
113        qty = int(input('Enter the new quantity:\n'))118        qty = int(input('Enter the new quantity:\n'))
114        itemToPurchase = ItemToPurchase(itemName, 0, qty)119        itemToPurchase = ItemToPurchase(itemName, 0, qty)
t115        customer_Cart.modify_item(itemToPurchase)    t120        customer_Cart.modify_item(itemToPurchase)
116    elif command == 'i':
117        print('\nOUTPUT ITEMS\' DESCRIPTIONS')
118        customer_Cart.print_descriptions()
119if __name__ == "__main__":121if __name__ == "__main__":
120    customer_name = input("Enter customer's name:\n")122    customer_name = input("Enter customer's name:\n")
121    current_date = input("Enter today's date:\n")123    current_date = input("Enter today's date:\n")
122    print("\nCustomer name: %s" % customer_name)124    print("\nCustomer name: %s" % customer_name)
123    print("Today's date: %s" % current_date)125    print("Today's date: %s" % current_date)
124    newCart = ShoppingCart(customer_name, current_date)126    newCart = ShoppingCart(customer_name, current_date)
125    command = ''127    command = ''
126    while command != 'q':128    while command != 'q':
127        print()129        print()
128        print_menu()130        print_menu()
129        command = input('Choose an option:\n')131        command = input('Choose an option:\n')
130        while command != 'a' and command != 'o' and command != 'i' and command !132        while command != 'a' and command != 'o' and command != 'i' and command !
>= 'q' and command != 'r' and command != 'c':>= 'q' and command != 'r' and command != 'c':
131            command = input('Choose an option:\n')133            command = input('Choose an option:\n')
132        execute_menu(command, newCart)import math134        execute_menu(command, newCart)import math
133class pt3d:135class pt3d:
134    def __init__(self,x=0,y=0,z=0):136    def __init__(self,x=0,y=0,z=0):
135        self.x= x137        self.x= x
136        self.y= y138        self.y= y
137        self.z= z139        self.z= z
138    def __add__(self, other):140    def __add__(self, other):
139        x = self.x + other.x141        x = self.x + other.x
140        y = self.y + other.y142        y = self.y + other.y
141        z = self.z + other.z143        z = self.z + other.z
142        return pt3d(x, y,z)144        return pt3d(x, y,z)
143    def __sub__(self, other):145    def __sub__(self, other):
144        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 146        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>2)+math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
145    def __eq__(self, other):147    def __eq__(self, other):
146        return other.x==self.x and other.y==self.y and other.z==self.z148        return other.x==self.x and other.y==self.y and other.z==self.z
147    def __str__(self):149    def __str__(self):
148        return "<{0},{1},{2}>".format(self.x, self.y, self.z)150        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
149if __name__ == '__main__':151if __name__ == '__main__':
150    p1 = pt3d(1, 1, 1)152    p1 = pt3d(1, 1, 1)
151    p2 = pt3d(2, 2, 2)153    p2 = pt3d(2, 2, 2)
152    print(p1+p2)154    print(p1+p2)
153    print(p1-p2)155    print(p1-p2)
154    print(p1==p2)156    print(p1==p2)
155    print(p1+p1==p2)157    print(p1+p1==p2)
156    print(p1==p2+pt3d(-1,-1,-1))158    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 9

Student ID: 370, P-Value: 8.95e-05

Nearest Neighbor ID: 114

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self,radius):n3    def __init__(self,radius=0):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
n6        return math.pi * self.radius ** 2n6        return self.radius**2*math.pi
7    def perimeter(self):7    def perimeter(self):
n8        return 2 * math.pi * self.radiusn8        return 2*self.radius*math.pi
9if __name__=='__main__':9if __name__=='__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
n13    print('{:.5f}'.format(NewCircle.perimeter()))n13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14class ItemToPurchase:
15   def __init__(self, name='none', price=0, quantity=0, description='none'):14   def __init__(self, name='none', price=0, quantity=0, description='none'):
16       self.item_name=name15       self.item_name=name
17       self.item_description=description16       self.item_description=description
18       self.item_price=price17       self.item_price=price
19       self.item_quantity=quantity18       self.item_quantity=quantity
20   def print_item_description(self):19   def print_item_description(self):
21       print('%s: %s' % (self.item_name, self.item_description))20       print('%s: %s' % (self.item_name, self.item_description))
22class ShoppingCart:21class ShoppingCart:
23   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
24       self.customer_name = customer_name23       self.customer_name = customer_name
25       self.current_date = current_date24       self.current_date = current_date
26       self.cart_items = cart_items  25       self.cart_items = cart_items  
27   def add_item(self, itemToPurchase):26   def add_item(self, itemToPurchase):
28       self.cart_items.append(itemToPurchase)  27       self.cart_items.append(itemToPurchase)  
29   def remove_item(self, itemName):28   def remove_item(self, itemName):
30       tremove_item = False29       tremove_item = False
31       for item in self.cart_items:30       for item in self.cart_items:
32           if item.item_name == itemName:31           if item.item_name == itemName:
33               self.cart_items.remove(item)32               self.cart_items.remove(item)
34               tremove_item = True33               tremove_item = True
35               break34               break
36       if not tremove_item:          35       if not tremove_item:          
37           print('Item not found in the cart. Nothing removed')36           print('Item not found in the cart. Nothing removed')
38   def modify_item(self, itemToPurchase):  37   def modify_item(self, itemToPurchase):  
39       tmodify_item = False38       tmodify_item = False
40       for i in range(len(self.cart_items)):39       for i in range(len(self.cart_items)):
41           if self.cart_items[i].item_name == itemToPurchase.item_name:40           if self.cart_items[i].item_name == itemToPurchase.item_name:
42               tmodify_item = True41               tmodify_item = True
43               self.cart_items[i].item_quantity = itemToPurchase.item_quantity42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
44               break43               break
45       if not tmodify_item:      44       if not tmodify_item:      
46           print('Item not found in the cart. Nothing modified')  45           print('Item not found in the cart. Nothing modified')  
47   def get_num_items_in_cart(self):46   def get_num_items_in_cart(self):
48       num_items = 047       num_items = 0
49       for item in self.cart_items:48       for item in self.cart_items:
50           num_items = num_items + item.item_quantity49           num_items = num_items + item.item_quantity
51       return num_items50       return num_items
52   def get_cost_of_cart(self):51   def get_cost_of_cart(self):
53       total_cost = 052       total_cost = 0
54       cost = 053       cost = 0
55       for item in self.cart_items:54       for item in self.cart_items:
56           cost = (item.item_quantity * item.item_price)55           cost = (item.item_quantity * item.item_price)
57           total_cost += cost56           total_cost += cost
58       return total_cost57       return total_cost
59   def print_total(self):58   def print_total(self):
60       total_cost = self.get_cost_of_cart()59       total_cost = self.get_cost_of_cart()
61       if (total_cost == 0):60       if (total_cost == 0):
62           print('SHOPPING CART IS EMPTY')61           print('SHOPPING CART IS EMPTY')
63       else:62       else:
64           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
65           print('Number of Items: %d\n' %self.get_num_items_in_cart())64           print('Number of Items: %d\n' %self.get_num_items_in_cart())
66           for item in self.cart_items:65           for item in self.cart_items:
67               total = item.item_price * item.item_quantity66               total = item.item_price * item.item_quantity
68               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
69           print('\nTotal: $%d' %(total_cost))68           print('\nTotal: $%d' %(total_cost))
70   def print_descriptions(self):69   def print_descriptions(self):
71       if len(self.cart_items) == 0:70       if len(self.cart_items) == 0:
72           print('SHOPPING CART IS EMPTY')71           print('SHOPPING CART IS EMPTY')
73       else:  72       else:  
74           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
75           print('\nItem Descriptions')74           print('\nItem Descriptions')
76           for item in self.cart_items:75           for item in self.cart_items:
77               item.print_item_description()  76               item.print_item_description()  
78def print_menu(newCart):77def print_menu(newCart):
79   customer_Cart = newCart78   customer_Cart = newCart
80   menu = ('\nMENU\n'79   menu = ('\nMENU\n'
81       'a - Add item to cart\n'80       'a - Add item to cart\n'
82       'r - Remove item from the cart\n'81       'r - Remove item from the cart\n'
83       'c - Change item quantity\n'82       'c - Change item quantity\n'
84       "i - Output item's descriptions\n"83       "i - Output item's descriptions\n"
85       'o - Output shopping cart\n'84       'o - Output shopping cart\n'
86       'q - Quit\n')85       'q - Quit\n')
87   command = ''86   command = ''
88   while(command != 'q'):87   while(command != 'q'):
89       print(menu)88       print(menu)
90       command = input('Choose an option:')89       command = input('Choose an option:')
91       while(command != 'a' and command != 'o' and command != 'i' and command !=90       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
92           command = input('Choose an option:\n')91           command = input('Choose an option:\n')
93       if(command == 'a'):92       if(command == 'a'):
94           print("\nADD ITEM TO CART")93           print("\nADD ITEM TO CART")
95           item_name = input('Enter the item name:\n')94           item_name = input('Enter the item name:\n')
96           item_description = input('Enter the item description:\n')95           item_description = input('Enter the item description:\n')
97           item_price = int(input('Enter the item price:\n'))96           item_price = int(input('Enter the item price:\n'))
98           item_quantity = int(input('Enter the item quantity:\n'))97           item_quantity = int(input('Enter the item quantity:\n'))
99           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
100           customer_Cart.add_item(itemtoPurchase)99           customer_Cart.add_item(itemtoPurchase)
101       elif(command == 'o'):100       elif(command == 'o'):
102           print('\nOUTPUT SHOPPING CART')101           print('\nOUTPUT SHOPPING CART')
103           customer_Cart.print_total()  102           customer_Cart.print_total()  
104       elif(command == 'i'):103       elif(command == 'i'):
105           print('\nOUTPUT ITEMS\' DESCRIPTIONS')104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
106           customer_Cart.print_descriptions()105           customer_Cart.print_descriptions()
107       elif(command == 'r'):106       elif(command == 'r'):
108           print('REMOVE ITEM FROM CART')107           print('REMOVE ITEM FROM CART')
109           itemName = input('Enter the name of the item to remove :\n')108           itemName = input('Enter the name of the item to remove :\n')
110           customer_Cart.remove_item(itemName)109           customer_Cart.remove_item(itemName)
111       elif(command == 'c'):110       elif(command == 'c'):
112           print('\nCHANGE ITEM QUANTITY')111           print('\nCHANGE ITEM QUANTITY')
113           itemName = input('Enter the name of the item :\n')112           itemName = input('Enter the name of the item :\n')
114           qty = int(input('Enter the new quantity :\n'))113           qty = int(input('Enter the new quantity :\n'))
115           itemToPurchase = ItemToPurchase(itemName,0,qty)114           itemToPurchase = ItemToPurchase(itemName,0,qty)
116           customer_Cart.modify_item(itemToPurchase)115           customer_Cart.modify_item(itemToPurchase)
117if __name__ == "__main__":116if __name__ == "__main__":
118   customer_name = input("Enter customer's name:\n")117   customer_name = input("Enter customer's name:\n")
119   current_date = input("Enter today's date:\n")118   current_date = input("Enter today's date:\n")
120   print("\nCustomer name: %s" %customer_name)119   print("\nCustomer name: %s" %customer_name)
121   print("Today's date: %s" %current_date)120   print("Today's date: %s" %current_date)
122   newCart = ShoppingCart(customer_name, current_date)121   newCart = ShoppingCart(customer_name, current_date)
123   print_menu(newCart)122   print_menu(newCart)
124import math123import math
125from math import sqrt124from math import sqrt
126class pt3d():125class pt3d():
127    def __init__(self,x,y,z):126    def __init__(self,x,y,z):
n128        self.x = xn127        self.x= x
129        self.y = y128        self.y= y
130        self.z = z129        self.z= z
131    def __add__(self, other):130    def __add__(self, other):
t132        sumX = self.x + other.xt131        sumx = self.x + other.x
133        sumY = self.y + other.y132        sumy = self.y + other.y
134        sumZ = self.z + other.z133        sumz = self.z + other.z
135        return pt3d(sumX, sumY,sumZ)134        return pt3d(sumx, sumy,sumz)
136    def __sub__(self, other):135    def __sub__(self, other):
137        return math.sqrt((((other.x-self.x)**2)+((other.y-self.y)**2)+((other.z-136        return math.sqrt((((other.x-self.x)**2)+((other.y-self.y)**2)+((other.z-
>self.z)**2)))>self.z)**2)))
138    def __eq__(self, other):137    def __eq__(self, other):
139        equalcheck = True138        equalcheck = True
140        if self.x != other.x and self.y != other.y and self.z != other.z:139        if self.x != other.x and self.y != other.y and self.z != other.z:
141            equalcheck = False140            equalcheck = False
142        else:141        else:
143            equalcheck = True142            equalcheck = True
144        return equalcheck143        return equalcheck
145    def __str__(self):144    def __str__(self):
146        return f'<{self.x},{self.y},{self.z}>'145        return f'<{self.x},{self.y},{self.z}>'
147def main():146def main():
148    a = pt3d(1, 1, 1)147    a = pt3d(1, 1, 1)
149    b = pt3d(2, 2, 2)148    b = pt3d(2, 2, 2)
150    print(a+b)149    print(a+b)
151    print(b-a)150    print(b-a)
152    a==b151    a==b
153    a+a==b152    a+a==b
154    a==b+pt3d(-1,-1,-1)153    a==b+pt3d(-1,-1,-1)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 10

Student ID: 114, P-Value: 8.95e-05

Nearest Neighbor ID: 370

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self,radius=0):n3    def __init__(self,radius):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
n6        return self.radius**2*math.pin6        return math.pi * self.radius ** 2
7    def perimeter(self):7    def perimeter(self):
n8        return 2*self.radius*math.pin8        return 2 * math.pi * self.radius
9if __name__=='__main__':9if __name__=='__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
n13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:n13    print('{:.5f}'.format(NewCircle.perimeter()))
14class ItemToPurchase:
14   def __init__(self, name='none', price=0, quantity=0, description='none'):15   def __init__(self, name='none', price=0, quantity=0, description='none'):
15       self.item_name=name16       self.item_name=name
16       self.item_description=description17       self.item_description=description
17       self.item_price=price18       self.item_price=price
18       self.item_quantity=quantity19       self.item_quantity=quantity
19   def print_item_description(self):20   def print_item_description(self):
20       print('%s: %s' % (self.item_name, self.item_description))21       print('%s: %s' % (self.item_name, self.item_description))
21class ShoppingCart:22class ShoppingCart:
22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 23   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
23       self.customer_name = customer_name24       self.customer_name = customer_name
24       self.current_date = current_date25       self.current_date = current_date
25       self.cart_items = cart_items  26       self.cart_items = cart_items  
26   def add_item(self, itemToPurchase):27   def add_item(self, itemToPurchase):
27       self.cart_items.append(itemToPurchase)  28       self.cart_items.append(itemToPurchase)  
28   def remove_item(self, itemName):29   def remove_item(self, itemName):
29       tremove_item = False30       tremove_item = False
30       for item in self.cart_items:31       for item in self.cart_items:
31           if item.item_name == itemName:32           if item.item_name == itemName:
32               self.cart_items.remove(item)33               self.cart_items.remove(item)
33               tremove_item = True34               tremove_item = True
34               break35               break
35       if not tremove_item:          36       if not tremove_item:          
36           print('Item not found in the cart. Nothing removed')37           print('Item not found in the cart. Nothing removed')
37   def modify_item(self, itemToPurchase):  38   def modify_item(self, itemToPurchase):  
38       tmodify_item = False39       tmodify_item = False
39       for i in range(len(self.cart_items)):40       for i in range(len(self.cart_items)):
40           if self.cart_items[i].item_name == itemToPurchase.item_name:41           if self.cart_items[i].item_name == itemToPurchase.item_name:
41               tmodify_item = True42               tmodify_item = True
42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity43               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43               break44               break
44       if not tmodify_item:      45       if not tmodify_item:      
45           print('Item not found in the cart. Nothing modified')  46           print('Item not found in the cart. Nothing modified')  
46   def get_num_items_in_cart(self):47   def get_num_items_in_cart(self):
47       num_items = 048       num_items = 0
48       for item in self.cart_items:49       for item in self.cart_items:
49           num_items = num_items + item.item_quantity50           num_items = num_items + item.item_quantity
50       return num_items51       return num_items
51   def get_cost_of_cart(self):52   def get_cost_of_cart(self):
52       total_cost = 053       total_cost = 0
53       cost = 054       cost = 0
54       for item in self.cart_items:55       for item in self.cart_items:
55           cost = (item.item_quantity * item.item_price)56           cost = (item.item_quantity * item.item_price)
56           total_cost += cost57           total_cost += cost
57       return total_cost58       return total_cost
58   def print_total(self):59   def print_total(self):
59       total_cost = self.get_cost_of_cart()60       total_cost = self.get_cost_of_cart()
60       if (total_cost == 0):61       if (total_cost == 0):
61           print('SHOPPING CART IS EMPTY')62           print('SHOPPING CART IS EMPTY')
62       else:63       else:
63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr64           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
64           print('Number of Items: %d\n' %self.get_num_items_in_cart())65           print('Number of Items: %d\n' %self.get_num_items_in_cart())
65           for item in self.cart_items:66           for item in self.cart_items:
66               total = item.item_price * item.item_quantity67               total = item.item_price * item.item_quantity
67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 68               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
68           print('\nTotal: $%d' %(total_cost))69           print('\nTotal: $%d' %(total_cost))
69   def print_descriptions(self):70   def print_descriptions(self):
70       if len(self.cart_items) == 0:71       if len(self.cart_items) == 0:
71           print('SHOPPING CART IS EMPTY')72           print('SHOPPING CART IS EMPTY')
72       else:  73       else:  
73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr74           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
74           print('\nItem Descriptions')75           print('\nItem Descriptions')
75           for item in self.cart_items:76           for item in self.cart_items:
76               item.print_item_description()  77               item.print_item_description()  
77def print_menu(newCart):78def print_menu(newCart):
78   customer_Cart = newCart79   customer_Cart = newCart
79   menu = ('\nMENU\n'80   menu = ('\nMENU\n'
80       'a - Add item to cart\n'81       'a - Add item to cart\n'
81       'r - Remove item from the cart\n'82       'r - Remove item from the cart\n'
82       'c - Change item quantity\n'83       'c - Change item quantity\n'
83       "i - Output item's descriptions\n"84       "i - Output item's descriptions\n"
84       'o - Output shopping cart\n'85       'o - Output shopping cart\n'
85       'q - Quit\n')86       'q - Quit\n')
86   command = ''87   command = ''
87   while(command != 'q'):88   while(command != 'q'):
88       print(menu)89       print(menu)
89       command = input('Choose an option:')90       command = input('Choose an option:')
90       while(command != 'a' and command != 'o' and command != 'i' and command !=91       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
91           command = input('Choose an option:\n')92           command = input('Choose an option:\n')
92       if(command == 'a'):93       if(command == 'a'):
93           print("\nADD ITEM TO CART")94           print("\nADD ITEM TO CART")
94           item_name = input('Enter the item name:\n')95           item_name = input('Enter the item name:\n')
95           item_description = input('Enter the item description:\n')96           item_description = input('Enter the item description:\n')
96           item_price = int(input('Enter the item price:\n'))97           item_price = int(input('Enter the item price:\n'))
97           item_quantity = int(input('Enter the item quantity:\n'))98           item_quantity = int(input('Enter the item quantity:\n'))
98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,99           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
99           customer_Cart.add_item(itemtoPurchase)100           customer_Cart.add_item(itemtoPurchase)
100       elif(command == 'o'):101       elif(command == 'o'):
101           print('\nOUTPUT SHOPPING CART')102           print('\nOUTPUT SHOPPING CART')
102           customer_Cart.print_total()  103           customer_Cart.print_total()  
103       elif(command == 'i'):104       elif(command == 'i'):
104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')105           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
105           customer_Cart.print_descriptions()106           customer_Cart.print_descriptions()
106       elif(command == 'r'):107       elif(command == 'r'):
107           print('REMOVE ITEM FROM CART')108           print('REMOVE ITEM FROM CART')
108           itemName = input('Enter the name of the item to remove :\n')109           itemName = input('Enter the name of the item to remove :\n')
109           customer_Cart.remove_item(itemName)110           customer_Cart.remove_item(itemName)
110       elif(command == 'c'):111       elif(command == 'c'):
111           print('\nCHANGE ITEM QUANTITY')112           print('\nCHANGE ITEM QUANTITY')
112           itemName = input('Enter the name of the item :\n')113           itemName = input('Enter the name of the item :\n')
113           qty = int(input('Enter the new quantity :\n'))114           qty = int(input('Enter the new quantity :\n'))
114           itemToPurchase = ItemToPurchase(itemName,0,qty)115           itemToPurchase = ItemToPurchase(itemName,0,qty)
115           customer_Cart.modify_item(itemToPurchase)116           customer_Cart.modify_item(itemToPurchase)
116if __name__ == "__main__":117if __name__ == "__main__":
117   customer_name = input("Enter customer's name:\n")118   customer_name = input("Enter customer's name:\n")
118   current_date = input("Enter today's date:\n")119   current_date = input("Enter today's date:\n")
119   print("\nCustomer name: %s" %customer_name)120   print("\nCustomer name: %s" %customer_name)
120   print("Today's date: %s" %current_date)121   print("Today's date: %s" %current_date)
121   newCart = ShoppingCart(customer_name, current_date)122   newCart = ShoppingCart(customer_name, current_date)
122   print_menu(newCart)123   print_menu(newCart)
123import math124import math
124from math import sqrt125from math import sqrt
125class pt3d():126class pt3d():
126    def __init__(self,x,y,z):127    def __init__(self,x,y,z):
n127        self.x= xn128        self.x = x
128        self.y= y129        self.y = y
129        self.z= z130        self.z = z
130    def __add__(self, other):131    def __add__(self, other):
t131        sumx = self.x + other.xt132        sumX = self.x + other.x
132        sumy = self.y + other.y133        sumY = self.y + other.y
133        sumz = self.z + other.z134        sumZ = self.z + other.z
134        return pt3d(sumx, sumy,sumz)135        return pt3d(sumX, sumY,sumZ)
135    def __sub__(self, other):136    def __sub__(self, other):
136        return math.sqrt((((other.x-self.x)**2)+((other.y-self.y)**2)+((other.z-137        return math.sqrt((((other.x-self.x)**2)+((other.y-self.y)**2)+((other.z-
>self.z)**2)))>self.z)**2)))
137    def __eq__(self, other):138    def __eq__(self, other):
138        equalcheck = True139        equalcheck = True
139        if self.x != other.x and self.y != other.y and self.z != other.z:140        if self.x != other.x and self.y != other.y and self.z != other.z:
140            equalcheck = False141            equalcheck = False
141        else:142        else:
142            equalcheck = True143            equalcheck = True
143        return equalcheck144        return equalcheck
144    def __str__(self):145    def __str__(self):
145        return f'<{self.x},{self.y},{self.z}>'146        return f'<{self.x},{self.y},{self.z}>'
146def main():147def main():
147    a = pt3d(1, 1, 1)148    a = pt3d(1, 1, 1)
148    b = pt3d(2, 2, 2)149    b = pt3d(2, 2, 2)
149    print(a+b)150    print(a+b)
150    print(b-a)151    print(b-a)
151    a==b152    a==b
152    a+a==b153    a+a==b
153    a==b+pt3d(-1,-1,-1)154    a==b+pt3d(-1,-1,-1)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 11

Student ID: 391, P-Value: 1.58e-04

Nearest Neighbor ID: 88

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self):n3    def __init__(self, radius):
4        self.radius = radius
4    def area(self):5    def area(self):
nn6        return math.pi*(self.radius**2)
5    def perimeter(self):7    def perimeter(self):
nn8        return 2*math.pi*self.radius
6if __name__=='__main__':9if __name__=='__main__':
7    x = int(input())10    x = int(input())
8    NewCircle = Circle(x)11    NewCircle = Circle(x)
9    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
10    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
11   def __init__(self, name='none', price=0, quantity=0, description='none'):14   def __init__(self, name='none', price=0, quantity=0, description='none'):
12       self.item_name=name15       self.item_name=name
13       self.item_description=description16       self.item_description=description
14       self.item_price=price17       self.item_price=price
15       self.item_quantity=quantity18       self.item_quantity=quantity
16   def print_item_description(self):19   def print_item_description(self):
17       print('%s: %s' % (self.item_name, self.item_description))20       print('%s: %s' % (self.item_name, self.item_description))
18class ShoppingCart:21class ShoppingCart:
19   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
20       self.customer_name = customer_name23       self.customer_name = customer_name
21       self.current_date = current_date24       self.current_date = current_date
22       self.cart_items = cart_items  25       self.cart_items = cart_items  
23   def add_item(self, itemToPurchase):26   def add_item(self, itemToPurchase):
24       self.cart_items.append(itemToPurchase)  27       self.cart_items.append(itemToPurchase)  
25   def remove_item(self, itemName):28   def remove_item(self, itemName):
26       tremove_item = False29       tremove_item = False
27       for item in self.cart_items:30       for item in self.cart_items:
28           if item.item_name == itemName:31           if item.item_name == itemName:
29               self.cart_items.remove(item)32               self.cart_items.remove(item)
30               tremove_item = True33               tremove_item = True
31               break34               break
32       if not tremove_item:          35       if not tremove_item:          
n33           print('Item not found in the cart. Nothing removed')n36           print('Item not found in the cart. Nothing removed.')
34   def modify_item(self, itemToPurchase):  37   def modify_item(self, itemToPurchase):  
35       tmodify_item = False38       tmodify_item = False
36       for i in range(len(self.cart_items)):39       for i in range(len(self.cart_items)):
37           if self.cart_items[i].item_name == itemToPurchase.item_name:40           if self.cart_items[i].item_name == itemToPurchase.item_name:
38               tmodify_item = True41               tmodify_item = True
39               self.cart_items[i].item_quantity = itemToPurchase.item_quantity42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
40               break43               break
41       if not tmodify_item:      44       if not tmodify_item:      
n42           print('Item not found in the cart. Nothing modified')  n45           print('Item not found in the cart. Nothing modified.')  
43   def get_num_items_in_cart(self):46   def get_num_items_in_cart(self):
44       num_items = 047       num_items = 0
45       for item in self.cart_items:48       for item in self.cart_items:
46           num_items = num_items + item.item_quantity49           num_items = num_items + item.item_quantity
47       return num_items50       return num_items
48   def get_cost_of_cart(self):51   def get_cost_of_cart(self):
49       total_cost = 052       total_cost = 0
50       cost = 053       cost = 0
51       for item in self.cart_items:54       for item in self.cart_items:
52           cost = (item.item_quantity * item.item_price)55           cost = (item.item_quantity * item.item_price)
53           total_cost += cost56           total_cost += cost
54       return total_cost57       return total_cost
55   def print_total(self):58   def print_total(self):
56       total_cost = self.get_cost_of_cart()59       total_cost = self.get_cost_of_cart()
57       if (total_cost == 0):60       if (total_cost == 0):
58           print('SHOPPING CART IS EMPTY')61           print('SHOPPING CART IS EMPTY')
59       else:62       else:
60           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
61           print('Number of Items: %d\n' %self.get_num_items_in_cart())64           print('Number of Items: %d\n' %self.get_num_items_in_cart())
62           for item in self.cart_items:65           for item in self.cart_items:
63               total = item.item_price * item.item_quantity66               total = item.item_price * item.item_quantity
64               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
65           print('\nTotal: $%d' %(total_cost))68           print('\nTotal: $%d' %(total_cost))
66   def print_descriptions(self):69   def print_descriptions(self):
67       if len(self.cart_items) == 0:70       if len(self.cart_items) == 0:
68           print('SHOPPING CART IS EMPTY')71           print('SHOPPING CART IS EMPTY')
69       else:  72       else:  
70           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
71           print('\nItem Descriptions')74           print('\nItem Descriptions')
72           for item in self.cart_items:75           for item in self.cart_items:
73               item.print_item_description()  76               item.print_item_description()  
74def print_menu(newCart):77def print_menu(newCart):
75   customer_Cart = newCart78   customer_Cart = newCart
76   menu = ('\nMENU\n'79   menu = ('\nMENU\n'
77       'a - Add item to cart\n'80       'a - Add item to cart\n'
78       'r - Remove item from cart\n'81       'r - Remove item from cart\n'
79       'c - Change item quantity\n'82       'c - Change item quantity\n'
80       "i - Output items' descriptions\n"83       "i - Output items' descriptions\n"
81       'o - Output shopping cart\n'84       'o - Output shopping cart\n'
82       'q - Quit\n')85       'q - Quit\n')
83   command = ''86   command = ''
84   while(command != 'q'):87   while(command != 'q'):
85       print(menu)88       print(menu)
86       command = input('Choose an option:\n')89       command = input('Choose an option:\n')
87       while(command != 'a' and command != 'o' and command != 'i' and command !=90       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
88           command = input('Choose an option:\n')91           command = input('Choose an option:\n')
89       if(command == 'a'):92       if(command == 'a'):
90           print("\nADD ITEM TO CART")93           print("\nADD ITEM TO CART")
91           item_name = input('Enter the item name:\n')94           item_name = input('Enter the item name:\n')
92           item_description = input('Enter the item description:\n')95           item_description = input('Enter the item description:\n')
93           item_price = int(input('Enter the item price:\n'))96           item_price = int(input('Enter the item price:\n'))
94           item_quantity = int(input('Enter the item quantity:\n'))97           item_quantity = int(input('Enter the item quantity:\n'))
95           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
96           customer_Cart.add_item(itemtoPurchase)99           customer_Cart.add_item(itemtoPurchase)
97       elif(command == 'o'):100       elif(command == 'o'):
98           print('\nOUTPUT SHOPPING CART')101           print('\nOUTPUT SHOPPING CART')
99           customer_Cart.print_total()  102           customer_Cart.print_total()  
100       elif(command == 'i'):103       elif(command == 'i'):
101           print('\nOUTPUT ITEMS\' DESCRIPTIONS')104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
102           customer_Cart.print_descriptions()105           customer_Cart.print_descriptions()
103       elif(command == 'r'):106       elif(command == 'r'):
104           print('REMOVE ITEM FROM CART')107           print('REMOVE ITEM FROM CART')
105           itemName = input('Enter name of item to remove :\n')108           itemName = input('Enter name of item to remove :\n')
106           customer_Cart.remove_item(itemName)109           customer_Cart.remove_item(itemName)
107       elif(command == 'c'):110       elif(command == 'c'):
108           print('\nCHANGE ITEM QUANTITY')111           print('\nCHANGE ITEM QUANTITY')
109           itemName = input('Enter name of item :\n')112           itemName = input('Enter name of item :\n')
n110           qty = int(input('Enter new quantity :\n'))n113           qty = int(input('Enter the new quantity :\n'))
111           itemToPurchase = ItemToPurchase(itemName,0,qty)114           itemToPurchase = ItemToPurchase(itemName,0,qty)
112           customer_Cart.modify_item(itemToPurchase)115           customer_Cart.modify_item(itemToPurchase)
113if __name__ == "__main__":116if __name__ == "__main__":
114   customer_name = input("Enter customer's name:\n")117   customer_name = input("Enter customer's name:\n")
115   current_date = input("Enter today's date:\n")118   current_date = input("Enter today's date:\n")
116   print("\nCustomer name: %s" %customer_name)119   print("\nCustomer name: %s" %customer_name)
117   print("Today's date: %s" %current_date)120   print("Today's date: %s" %current_date)
118   newCart = ShoppingCart(customer_name, current_date)121   newCart = ShoppingCart(customer_name, current_date)
n119   print_menu(newCart)  class pt3d:n122   print_menu(newCart)from math import sqrt
123class pt3d:
120    def __init__(self, x, y, z):124    def __init__(self, x, y, z):
121        self.x = x125        self.x = x
122        self.y = y126        self.y = y
123        self.z = z127        self.z = z
124    def __add__(self, other):128    def __add__(self, other):
125        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)129        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
126    def __sub__(self, other):130    def __sub__(self, other):
127        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot131        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>her.z)**2)>her.z)**2)
128    def __eq__(self, other):132    def __eq__(self, other):
t129        return self.x == other.x & self.y == other.y & self.z == other.zt133        return self.x == other.x and self.y == other.y and self.z == other.z
130    def __str__(self):134    def __str__(self):
131        return '<{}, {}, {}>'.format(self.x, self.y, self.z)135        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
132p1 = pt3d(1, 1, 1)136p1 = pt3d(1, 1, 1)
133p2 = pt3d(2, 2, 2)137p2 = pt3d(2, 2, 2)
134print(p1 + p2)138print(p1 + p2)
135print(p1 - p2)139print(p1 - p2)
136print(p1 == p2)140print(p1 == p2)
137print(p1+p1 == p2)141print(p1+p1 == p2)
138print(p1==p2+pt3d(-1, -1, -1))142print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 12

Student ID: 478, P-Value: 1.70e-04

Nearest Neighbor ID: 492

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle :n2class Circle:
3    def __init__(self,radius):3    def __init__(self, rad):
4        self.radius = radius4        self.radius = rad
5    def area(self):5    def area(self):
n6        return math.pi*self.radius*self.radiusn6        return (self.radius**2)*math.pi
7    def perimeter(self):7    def perimeter(self):
n8        return 2*math.pi*self.radiusn8        return self.radius*2*math.pi
9if __name__ == '__main__':9if __name__ == '__main__':
n10    x = int(input())n10    x = int(input(""))
11    NewCircle = Circle(x)11    NewCircle = circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print(NewCircle.area())
13    print('{:.5f}'.format(NewCircle.perimeter()))13    print(NewCircle.perimeter())class ItemToPurchase:
14class ItemToPurchase:
15   def __init__(self, name='none', price=0, quantity=0, description='none'):14   def __init__(self, name='none', price=0, quantity=0, description='none'):
16       self.item_name=name15       self.item_name=name
17       self.item_description=description16       self.item_description=description
18       self.item_price=price17       self.item_price=price
19       self.item_quantity=quantity18       self.item_quantity=quantity
20   def print_item_description(self):19   def print_item_description(self):
21       print('%s: %s' % (self.item_name, self.item_description))20       print('%s: %s' % (self.item_name, self.item_description))
22class ShoppingCart:21class ShoppingCart:
23   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
24       self.customer_name = customer_name23       self.customer_name = customer_name
25       self.current_date = current_date24       self.current_date = current_date
26       self.cart_items = cart_items  25       self.cart_items = cart_items  
27   def add_item(self, itemToPurchase):26   def add_item(self, itemToPurchase):
28       self.cart_items.append(itemToPurchase)  27       self.cart_items.append(itemToPurchase)  
29   def remove_item(self, itemName):28   def remove_item(self, itemName):
30       tremove_item = False29       tremove_item = False
31       for item in self.cart_items:30       for item in self.cart_items:
32           if item.item_name == itemName:31           if item.item_name == itemName:
33               self.cart_items.remove(item)32               self.cart_items.remove(item)
34               tremove_item = True33               tremove_item = True
35               break34               break
36       if not tremove_item:          35       if not tremove_item:          
n37           print('Item not found in the cart. Nothing removed')n36           print('Item not found in cart. Nothing removed.')
38   def modify_item(self, itemToPurchase):  37   def modify_item(self, itemToPurchase):  
39       tmodify_item = False38       tmodify_item = False
40       for i in range(len(self.cart_items)):39       for i in range(len(self.cart_items)):
41           if self.cart_items[i].item_name == itemToPurchase.item_name:40           if self.cart_items[i].item_name == itemToPurchase.item_name:
42               tmodify_item = True41               tmodify_item = True
43               self.cart_items[i].item_quantity = itemToPurchase.item_quantity42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
44               break43               break
45       if not tmodify_item:      44       if not tmodify_item:      
n46           print('Item not found in the cart. Nothing modified')  n45           print('Item not found in cart. Nothing modified.')  
47   def get_num_items_in_cart(self):46   def get_num_items_in_cart(self):
48       num_items = 047       num_items = 0
49       for item in self.cart_items:48       for item in self.cart_items:
50           num_items = num_items + item.item_quantity49           num_items = num_items + item.item_quantity
51       return num_items50       return num_items
52   def get_cost_of_cart(self):51   def get_cost_of_cart(self):
53       total_cost = 052       total_cost = 0
54       cost = 053       cost = 0
55       for item in self.cart_items:54       for item in self.cart_items:
56           cost = (item.item_quantity * item.item_price)55           cost = (item.item_quantity * item.item_price)
57           total_cost += cost56           total_cost += cost
58       return total_cost57       return total_cost
59   def print_total(self):58   def print_total(self):
60       total_cost = self.get_cost_of_cart()59       total_cost = self.get_cost_of_cart()
61       if (total_cost == 0):60       if (total_cost == 0):
62           print('SHOPPING CART IS EMPTY')61           print('SHOPPING CART IS EMPTY')
63       else:62       else:
64           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
65           print('Number of Items: %d\n' %self.get_num_items_in_cart())64           print('Number of Items: %d\n' %self.get_num_items_in_cart())
66           for item in self.cart_items:65           for item in self.cart_items:
67               total = item.item_price * item.item_quantity66               total = item.item_price * item.item_quantity
68               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
69           print('\nTotal: $%d' %(total_cost))68           print('\nTotal: $%d' %(total_cost))
70   def print_descriptions(self):69   def print_descriptions(self):
71       if len(self.cart_items) == 0:70       if len(self.cart_items) == 0:
72           print('SHOPPING CART IS EMPTY')71           print('SHOPPING CART IS EMPTY')
73       else:  72       else:  
74           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
75           print('\nItem Descriptions')74           print('\nItem Descriptions')
76           for item in self.cart_items:75           for item in self.cart_items:
77               item.print_item_description()  76               item.print_item_description()  
78def print_menu(newCart):77def print_menu(newCart):
79   customer_Cart = newCart78   customer_Cart = newCart
80   menu = ('\nMENU\n'79   menu = ('\nMENU\n'
81       'a - Add item to cart\n'80       'a - Add item to cart\n'
82       'r - Remove item from cart\n'81       'r - Remove item from cart\n'
83       'c - Change item quantity\n'82       'c - Change item quantity\n'
84       "i - Output items' descriptions\n"83       "i - Output items' descriptions\n"
85       'o - Output shopping cart\n'84       'o - Output shopping cart\n'
86       'q - Quit\n')85       'q - Quit\n')
87   command = ''86   command = ''
88   while(command != 'q'):87   while(command != 'q'):
89       print(menu)88       print(menu)
90       command = input('Choose an option:\n')89       command = input('Choose an option:\n')
91       while(command != 'a' and command != 'o' and command != 'i' and command !=90       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
92           command = input('Choose an option:\n')91           command = input('Choose an option:\n')
93       if(command == 'a'):92       if(command == 'a'):
94           print("\nADD ITEM TO CART")93           print("\nADD ITEM TO CART")
95           item_name = input('Enter the item name:\n')94           item_name = input('Enter the item name:\n')
96           item_description = input('Enter the item description:\n')95           item_description = input('Enter the item description:\n')
97           item_price = int(input('Enter the item price:\n'))96           item_price = int(input('Enter the item price:\n'))
98           item_quantity = int(input('Enter the item quantity:\n'))97           item_quantity = int(input('Enter the item quantity:\n'))
99           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
100           customer_Cart.add_item(itemtoPurchase)99           customer_Cart.add_item(itemtoPurchase)
101       elif(command == 'o'):100       elif(command == 'o'):
n102           print('\nOUTPUT SHOPPING CART')n101           print('OUTPUT SHOPPING CART')
103           customer_Cart.print_total()  102           customer_Cart.print_total()  
104       elif(command == 'i'):103       elif(command == 'i'):
105           print('\nOUTPUT ITEMS\' DESCRIPTIONS')104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
106           customer_Cart.print_descriptions()105           customer_Cart.print_descriptions()
107       elif(command == 'r'):106       elif(command == 'r'):
108           print('REMOVE ITEM FROM CART')107           print('REMOVE ITEM FROM CART')
n109           itemName = input('Enter the name of the item to remove :\n')n108           itemName = input('Enter name of item to remove:\n')
110           customer_Cart.remove_item(itemName)109           customer_Cart.remove_item(itemName)
111       elif(command == 'c'):110       elif(command == 'c'):
112           print('\nCHANGE ITEM QUANTITY')111           print('\nCHANGE ITEM QUANTITY')
n113           itemName = input('Enter the name of the item :\n')n112           itemName = input('Enter name of item :\n')
114           qty = int(input('Enter the new quantity :\n'))113           qty = int(input('Enter the new quantity :\n'))
115           itemToPurchase = ItemToPurchase(itemName,0,qty)114           itemToPurchase = ItemToPurchase(itemName,0,qty)
116           customer_Cart.modify_item(itemToPurchase)115           customer_Cart.modify_item(itemToPurchase)
117if __name__ == "__main__":116if __name__ == "__main__":
118   customer_name = input("Enter customer's name:\n")117   customer_name = input("Enter customer's name:\n")
119   current_date = input("Enter today's date:\n")118   current_date = input("Enter today's date:\n")
120   print("\nCustomer name: %s" %customer_name)119   print("\nCustomer name: %s" %customer_name)
121   print("Today's date: %s" %current_date)120   print("Today's date: %s" %current_date)
122   newCart = ShoppingCart(customer_name, current_date)121   newCart = ShoppingCart(customer_name, current_date)
t123   print_menu(newCart)import matht122   print_menu(newCart)  import math
124class pt3d:123class pt3d:
125    def __init__(self,x=0,y=0,z=0):124    def __init__(self,x=0,y=0,z=0):
126        self.x= x125        self.x= x
127        self.y= y126        self.y= y
128        self.z= z127        self.z= z
129    def __add__(self, other):128    def __add__(self, other):
130        x = self.x + other.x129        x = self.x + other.x
131        y = self.y + other.y130        y = self.y + other.y
132        z = self.z + other.z131        z = self.z + other.z
133        return pt3d(x, y,z)132        return pt3d(x, y,z)
134    def __sub__(self, other):133    def __sub__(self, other):
135        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 134        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>2)+math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
136    def __eq__(self, other):135    def __eq__(self, other):
137        return other.x==self.x and other.y==self.y and other.z==self.z136        return other.x==self.x and other.y==self.y and other.z==self.z
138    def __str__(self):137    def __str__(self):
139        return "<{0},{1},{2}>".format(self.x, self.y, self.z)138        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
140if __name__ == '__main__':139if __name__ == '__main__':
141    p1 = pt3d(1, 1, 1)140    p1 = pt3d(1, 1, 1)
142    p2 = pt3d(2, 2, 2)141    p2 = pt3d(2, 2, 2)
143    print(p1+p2)142    print(p1+p2)
144    print(p1-p2)143    print(p1-p2)
145    print(p1==p2)144    print(p1==p2)
146    print(p1+p1==p2)145    print(p1+p1==p2)
147    print(p1==p2+pt3d(-1,-1,-1))146    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 13

Student ID: 258, P-Value: 1.90e-04

Nearest Neighbor ID: 492

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self,r):n3    def __init__(self, rad):
4        self.rad=r4        self.radius = rad
5    def area(self):5    def area(self):
n6        return self.rad*self.rad*3.14159265359n6        return (self.radius**2)*math.pi
7    def perimeter(self):7    def perimeter(self):
t8        return self.rad*2*3.14159265359t8        return self.radius*2*math.pi
9if __name__=='__main__':9if __name__ == '__main__':
10    x = int(input())10    x = int(input(""))
11    NewCircle = Circle(x)11    NewCircle = circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print(NewCircle.area())
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print(NewCircle.perimeter())class ItemToPurchase:
14   def __init__(self, name='none', price=0, quantity=0, description='none'):14   def __init__(self, name='none', price=0, quantity=0, description='none'):
15       self.item_name=name15       self.item_name=name
16       self.item_description=description16       self.item_description=description
17       self.item_price=price17       self.item_price=price
18       self.item_quantity=quantity18       self.item_quantity=quantity
19   def print_item_description(self):19   def print_item_description(self):
20       print('%s: %s' % (self.item_name, self.item_description))20       print('%s: %s' % (self.item_name, self.item_description))
21class ShoppingCart:21class ShoppingCart:
22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
23       self.customer_name = customer_name23       self.customer_name = customer_name
24       self.current_date = current_date24       self.current_date = current_date
25       self.cart_items = cart_items  25       self.cart_items = cart_items  
26   def add_item(self, itemToPurchase):26   def add_item(self, itemToPurchase):
27       self.cart_items.append(itemToPurchase)  27       self.cart_items.append(itemToPurchase)  
28   def remove_item(self, itemName):28   def remove_item(self, itemName):
29       tremove_item = False29       tremove_item = False
30       for item in self.cart_items:30       for item in self.cart_items:
31           if item.item_name == itemName:31           if item.item_name == itemName:
32               self.cart_items.remove(item)32               self.cart_items.remove(item)
33               tremove_item = True33               tremove_item = True
34               break34               break
35       if not tremove_item:          35       if not tremove_item:          
36           print('Item not found in cart. Nothing removed.')36           print('Item not found in cart. Nothing removed.')
37   def modify_item(self, itemToPurchase):  37   def modify_item(self, itemToPurchase):  
38       tmodify_item = False38       tmodify_item = False
39       for i in range(len(self.cart_items)):39       for i in range(len(self.cart_items)):
40           if self.cart_items[i].item_name == itemToPurchase.item_name:40           if self.cart_items[i].item_name == itemToPurchase.item_name:
41               tmodify_item = True41               tmodify_item = True
42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43               break43               break
44       if not tmodify_item:      44       if not tmodify_item:      
45           print('Item not found in cart. Nothing modified.')  45           print('Item not found in cart. Nothing modified.')  
46   def get_num_items_in_cart(self):46   def get_num_items_in_cart(self):
47       num_items = 047       num_items = 0
48       for item in self.cart_items:48       for item in self.cart_items:
49           num_items = num_items + item.item_quantity49           num_items = num_items + item.item_quantity
50       return num_items50       return num_items
51   def get_cost_of_cart(self):51   def get_cost_of_cart(self):
52       total_cost = 052       total_cost = 0
53       cost = 053       cost = 0
54       for item in self.cart_items:54       for item in self.cart_items:
55           cost = (item.item_quantity * item.item_price)55           cost = (item.item_quantity * item.item_price)
56           total_cost += cost56           total_cost += cost
57       return total_cost57       return total_cost
58   def print_total(self):58   def print_total(self):
59       total_cost = self.get_cost_of_cart()59       total_cost = self.get_cost_of_cart()
60       if (total_cost == 0):60       if (total_cost == 0):
61           print('SHOPPING CART IS EMPTY')61           print('SHOPPING CART IS EMPTY')
62       else:62       else:
63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
64           print('Number of Items: %d\n' %self.get_num_items_in_cart())64           print('Number of Items: %d\n' %self.get_num_items_in_cart())
65           for item in self.cart_items:65           for item in self.cart_items:
66               total = item.item_price * item.item_quantity66               total = item.item_price * item.item_quantity
67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
68           print('\nTotal: $%d' %(total_cost))68           print('\nTotal: $%d' %(total_cost))
69   def print_descriptions(self):69   def print_descriptions(self):
70       if len(self.cart_items) == 0:70       if len(self.cart_items) == 0:
71           print('SHOPPING CART IS EMPTY')71           print('SHOPPING CART IS EMPTY')
72       else:  72       else:  
73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
74           print('\nItem Descriptions')74           print('\nItem Descriptions')
75           for item in self.cart_items:75           for item in self.cart_items:
76               item.print_item_description()  76               item.print_item_description()  
77def print_menu(newCart):77def print_menu(newCart):
78   customer_Cart = newCart78   customer_Cart = newCart
79   menu = ('\nMENU\n'79   menu = ('\nMENU\n'
80       'a - Add item to cart\n'80       'a - Add item to cart\n'
81       'r - Remove item from cart\n'81       'r - Remove item from cart\n'
82       'c - Change item quantity\n'82       'c - Change item quantity\n'
83       "i - Output items' descriptions\n"83       "i - Output items' descriptions\n"
84       'o - Output shopping cart\n'84       'o - Output shopping cart\n'
85       'q - Quit\n')85       'q - Quit\n')
86   command = ''86   command = ''
87   while(command != 'q'):87   while(command != 'q'):
88       print(menu)88       print(menu)
89       command = input('Choose an option:\n')89       command = input('Choose an option:\n')
90       while(command != 'a' and command != 'o' and command != 'i' and command !=90       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
91           command = input('Choose an option:\n')91           command = input('Choose an option:\n')
92       if(command == 'a'):92       if(command == 'a'):
93           print("\nADD ITEM TO CART")93           print("\nADD ITEM TO CART")
94           item_name = input('Enter the item name:\n')94           item_name = input('Enter the item name:\n')
95           item_description = input('Enter the item description:\n')95           item_description = input('Enter the item description:\n')
96           item_price = int(input('Enter the item price:\n'))96           item_price = int(input('Enter the item price:\n'))
97           item_quantity = int(input('Enter the item quantity:\n'))97           item_quantity = int(input('Enter the item quantity:\n'))
98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
99           customer_Cart.add_item(itemtoPurchase)99           customer_Cart.add_item(itemtoPurchase)
100       elif(command == 'o'):100       elif(command == 'o'):
101           print('OUTPUT SHOPPING CART')101           print('OUTPUT SHOPPING CART')
102           customer_Cart.print_total()  102           customer_Cart.print_total()  
103       elif(command == 'i'):103       elif(command == 'i'):
104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
105           customer_Cart.print_descriptions()105           customer_Cart.print_descriptions()
106       elif(command == 'r'):106       elif(command == 'r'):
107           print('REMOVE ITEM FROM CART')107           print('REMOVE ITEM FROM CART')
108           itemName = input('Enter name of item to remove:\n')108           itemName = input('Enter name of item to remove:\n')
109           customer_Cart.remove_item(itemName)109           customer_Cart.remove_item(itemName)
110       elif(command == 'c'):110       elif(command == 'c'):
111           print('\nCHANGE ITEM QUANTITY')111           print('\nCHANGE ITEM QUANTITY')
112           itemName = input('Enter name of item :\n')112           itemName = input('Enter name of item :\n')
113           qty = int(input('Enter the new quantity :\n'))113           qty = int(input('Enter the new quantity :\n'))
114           itemToPurchase = ItemToPurchase(itemName,0,qty)114           itemToPurchase = ItemToPurchase(itemName,0,qty)
115           customer_Cart.modify_item(itemToPurchase)115           customer_Cart.modify_item(itemToPurchase)
116if __name__ == "__main__":116if __name__ == "__main__":
117   customer_name = input("Enter customer's name:\n")117   customer_name = input("Enter customer's name:\n")
118   current_date = input("Enter today's date:\n")118   current_date = input("Enter today's date:\n")
119   print("\nCustomer name: %s" %customer_name)119   print("\nCustomer name: %s" %customer_name)
120   print("Today's date: %s" %current_date)120   print("Today's date: %s" %current_date)
121   newCart = ShoppingCart(customer_name, current_date)121   newCart = ShoppingCart(customer_name, current_date)
122   print_menu(newCart)  import math122   print_menu(newCart)  import math
123class pt3d:123class pt3d:
124    def __init__(self,x=0,y=0,z=0):124    def __init__(self,x=0,y=0,z=0):
125        self.x= x125        self.x= x
126        self.y= y126        self.y= y
127        self.z= z127        self.z= z
128    def __add__(self, other):128    def __add__(self, other):
129        x = self.x + other.x129        x = self.x + other.x
130        y = self.y + other.y130        y = self.y + other.y
131        z = self.z + other.z131        z = self.z + other.z
132        return pt3d(x, y,z)132        return pt3d(x, y,z)
133    def __sub__(self, other):133    def __sub__(self, other):
134        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 134        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>2)+math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
135    def __eq__(self, other):135    def __eq__(self, other):
136        return other.x==self.x and other.y==self.y and other.z==self.z136        return other.x==self.x and other.y==self.y and other.z==self.z
137    def __str__(self):137    def __str__(self):
138        return "<{0},{1},{2}>".format(self.x, self.y, self.z)138        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
139if __name__ == '__main__':139if __name__ == '__main__':
140    p1 = pt3d(1, 1, 1)140    p1 = pt3d(1, 1, 1)
141    p2 = pt3d(2, 2, 2)141    p2 = pt3d(2, 2, 2)
142    print(p1+p2)142    print(p1+p2)
143    print(p1-p2)143    print(p1-p2)
144    print(p1==p2)144    print(p1==p2)
145    print(p1+p1==p2)145    print(p1+p1==p2)
146    print(p1==p2+pt3d(-1,-1,-1))146    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 14

Student ID: 450, P-Value: 2.11e-04

Nearest Neighbor ID: 172

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self, radius):n3    def __init__(self):
4        self.radius = int(radius)4        self.radius=radius
5    def area(self):5    def area(self):
n6        return round(math.pi*self.radius*self.radius,3)n6        return math.pi*(self.radius**2)
7    def perimeter(self):7    def perimeter(self):
n8        return round(2*math.pi*self.radius,3)n8        return 2*math.pi*self.radius
9circle=Circle(2)9if __name__=='__main__':
10print("Area of circle=",circle.area())10   x = int(input())
11print("Perimeter of circle=",circle.perimeter())class ItemToPurchase:11   NewCircle = Circle(x)
12   print('{:.5f}'.format(NewCircle.area()))
13   print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
12   def __init__(self, name='none', price=0, quantity=0, description='none'):14   def __init__(self, name='none', price=0, quantity=0, description='none'):
13       self.item_name=name15       self.item_name=name
14       self.item_description=description16       self.item_description=description
15       self.item_price=price17       self.item_price=price
16       self.item_quantity=quantity18       self.item_quantity=quantity
17   def print_item_description(self):19   def print_item_description(self):
18       print('%s: %s' % (self.item_name, self.item_description))20       print('%s: %s' % (self.item_name, self.item_description))
19class ShoppingCart:21class ShoppingCart:
20   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
21       self.customer_name = customer_name23       self.customer_name = customer_name
22       self.current_date = current_date24       self.current_date = current_date
23       self.cart_items = cart_items  25       self.cart_items = cart_items  
24   def add_item(self, itemToPurchase):26   def add_item(self, itemToPurchase):
25       self.cart_items.append(itemToPurchase)  27       self.cart_items.append(itemToPurchase)  
26   def remove_item(self, itemName):28   def remove_item(self, itemName):
27       tremove_item = False29       tremove_item = False
28       for item in self.cart_items:30       for item in self.cart_items:
29           if item.item_name == itemName:31           if item.item_name == itemName:
30               self.cart_items.remove(item)32               self.cart_items.remove(item)
31               tremove_item = True33               tremove_item = True
32               break34               break
33       if not tremove_item:          35       if not tremove_item:          
34           print('Item not found in the cart. Nothing removed')36           print('Item not found in the cart. Nothing removed')
35   def modify_item(self, itemToPurchase):  37   def modify_item(self, itemToPurchase):  
36       tmodify_item = False38       tmodify_item = False
37       for i in range(len(self.cart_items)):39       for i in range(len(self.cart_items)):
38           if self.cart_items[i].item_name == itemToPurchase.item_name:40           if self.cart_items[i].item_name == itemToPurchase.item_name:
39               tmodify_item = True41               tmodify_item = True
40               self.cart_items[i].item_quantity = itemToPurchase.item_quantity42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
41               break43               break
42       if not tmodify_item:      44       if not tmodify_item:      
43           print('Item not found in the cart. Nothing modified')  45           print('Item not found in the cart. Nothing modified')  
44   def get_num_items_in_cart(self):46   def get_num_items_in_cart(self):
45       num_items = 047       num_items = 0
46       for item in self.cart_items:48       for item in self.cart_items:
47           num_items = num_items + item.item_quantity49           num_items = num_items + item.item_quantity
48       return num_items50       return num_items
49   def get_cost_of_cart(self):51   def get_cost_of_cart(self):
50       total_cost = 052       total_cost = 0
51       cost = 053       cost = 0
52       for item in self.cart_items:54       for item in self.cart_items:
53           cost = (item.item_quantity * item.item_price)55           cost = (item.item_quantity * item.item_price)
54           total_cost += cost56           total_cost += cost
55       return total_cost57       return total_cost
56   def print_total(self):58   def print_total(self):
57       total_cost = self.get_cost_of_cart()59       total_cost = self.get_cost_of_cart()
58       if (total_cost == 0):60       if (total_cost == 0):
59           print('SHOPPING CART IS EMPTY')61           print('SHOPPING CART IS EMPTY')
60       else:62       else:
61           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
62           print('Number of Items: %d\n' %self.get_num_items_in_cart())64           print('Number of Items: %d\n' %self.get_num_items_in_cart())
63           for item in self.cart_items:65           for item in self.cart_items:
64               total = item.item_price * item.item_quantity66               total = item.item_price * item.item_quantity
65               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
66           print('\nTotal: $%d' %(total_cost))68           print('\nTotal: $%d' %(total_cost))
67   def print_descriptions(self):69   def print_descriptions(self):
68       if len(self.cart_items) == 0:70       if len(self.cart_items) == 0:
69           print('SHOPPING CART IS EMPTY')71           print('SHOPPING CART IS EMPTY')
70       else:  72       else:  
71           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
72           print('\nItem Descriptions')74           print('\nItem Descriptions')
73           for item in self.cart_items:75           for item in self.cart_items:
74               item.print_item_description()  76               item.print_item_description()  
75def print_menu(newCart):77def print_menu(newCart):
76   customer_Cart = newCart78   customer_Cart = newCart
77   menu = ('\nMENU\n'79   menu = ('\nMENU\n'
78       'a - Add item to cart\n'80       'a - Add item to cart\n'
79       'r - Remove item from the cart\n'81       'r - Remove item from the cart\n'
80       'c - Change item quantity\n'82       'c - Change item quantity\n'
81       "i - Output item's descriptions\n"83       "i - Output item's descriptions\n"
82       'o - Output shopping cart\n'84       'o - Output shopping cart\n'
83       'q - Quit\n')85       'q - Quit\n')
84   command = ''86   command = ''
85   while(command != 'q'):87   while(command != 'q'):
86       print(menu)88       print(menu)
87       command = input('Choose an option:')89       command = input('Choose an option:')
88       while(command != 'a' and command != 'o' and command != 'i' and command !=90       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
89           command = input('Choose an option:\n')91           command = input('Choose an option:\n')
90       if(command == 'a'):92       if(command == 'a'):
91           print("\nADD ITEM TO CART")93           print("\nADD ITEM TO CART")
92           item_name = input('Enter the item name:\n')94           item_name = input('Enter the item name:\n')
93           item_description = input('Enter the item description:\n')95           item_description = input('Enter the item description:\n')
94           item_price = int(input('Enter the item price:\n'))96           item_price = int(input('Enter the item price:\n'))
95           item_quantity = int(input('Enter the item quantity:\n'))97           item_quantity = int(input('Enter the item quantity:\n'))
96           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
97           customer_Cart.add_item(itemtoPurchase)99           customer_Cart.add_item(itemtoPurchase)
98       elif(command == 'o'):100       elif(command == 'o'):
99           print('\nOUTPUT SHOPPING CART')101           print('\nOUTPUT SHOPPING CART')
100           customer_Cart.print_total()  102           customer_Cart.print_total()  
101       elif(command == 'i'):103       elif(command == 'i'):
102           print('\nOUTPUT ITEMS\' DESCRIPTIONS')104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
103           customer_Cart.print_descriptions()105           customer_Cart.print_descriptions()
104       elif(command == 'r'):106       elif(command == 'r'):
105           print('REMOVE ITEM FROM CART')107           print('REMOVE ITEM FROM CART')
106           itemName = input('Enter the name of the item to remove :\n')108           itemName = input('Enter the name of the item to remove :\n')
107           customer_Cart.remove_item(itemName)109           customer_Cart.remove_item(itemName)
108       elif(command == 'c'):110       elif(command == 'c'):
109           print('\nCHANGE ITEM QUANTITY')111           print('\nCHANGE ITEM QUANTITY')
110           itemName = input('Enter the name of the item :\n')112           itemName = input('Enter the name of the item :\n')
111           qty = int(input('Enter the new quantity :\n'))113           qty = int(input('Enter the new quantity :\n'))
112           itemToPurchase = ItemToPurchase(itemName,0,qty)114           itemToPurchase = ItemToPurchase(itemName,0,qty)
113           customer_Cart.modify_item(itemToPurchase)115           customer_Cart.modify_item(itemToPurchase)
114if __name__ == "__main__":116if __name__ == "__main__":
115   customer_name = input("Enter customer's name:\n")117   customer_name = input("Enter customer's name:\n")
116   current_date = input("Enter today's date:\n")118   current_date = input("Enter today's date:\n")
117   print("\nCustomer name: %s" %customer_name)119   print("\nCustomer name: %s" %customer_name)
118   print("Today's date: %s" %current_date)120   print("Today's date: %s" %current_date)
119   newCart = ShoppingCart(customer_name, current_date)121   newCart = ShoppingCart(customer_name, current_date)
t120   print_menu(newCart)from math import sqrtt122   print_menu(newCart)from math import sqrt 
121class pt3d:123class pt3d:
122    def __init__(self, x, y, z):124    def __init__(self, x, y, z):
123        self.x = x125        self.x = x
124        self.y = y126        self.y = y
125        self.z = z127        self.z = z
126    def __add__(self, other):128    def __add__(self, other):
127        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)129        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
128    def __sub__(self, other):130    def __sub__(self, other):
129        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot131        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>her.z)**2)>her.z)**2)
130    def __eq__(self, other):132    def __eq__(self, other):
131        return self.x == other.x & self.y == other.y & self.z == other.z133        return self.x == other.x & self.y == other.y & self.z == other.z
132    def __str__(self):134    def __str__(self):
133        return '<{}, {}, {}>'.format(self.x, self.y, self.z)135        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
134p1 = pt3d(1, 1, 1)136p1 = pt3d(1, 1, 1)
135p2 = pt3d(2, 2, 2)137p2 = pt3d(2, 2, 2)
136print(p1 + p2)138print(p1 + p2)
137print(p1 - p2)139print(p1 - p2)
138print(p1 == p2)140print(p1 == p2)
139print(p1+p1 == p2)141print(p1+p1 == p2)
140print(p1==p2+pt3d(-1, -1, -1))142print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 15

Student ID: 132, P-Value: 2.35e-04

Nearest Neighbor ID: 88

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class circle():n2class Circle:
3    def __init__(self,radius):3    def __init__(self, radius):
4        self.radius=radius4        self.radius = radius
5    def area(self):5    def area(self):
n6        return math.pi * self.radius * self.radiusn6        return math.pi*(self.radius**2)
7    def perimeter(self):7    def perimeter(self):
8        return 2*math.pi*self.radius8        return 2*math.pi*self.radius
9if __name__=='__main__':9if __name__=='__main__':
10    x = int(input())10    x = int(input())
n11    NewCircle = circle(x)n11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
n13    print('{:.5f}'.format(NewCircle.perimeter()))n13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14class ItemToPurchase:
15   def __init__(self, name='none', price=0, quantity=0, description='none'):14   def __init__(self, name='none', price=0, quantity=0, description='none'):
16       self.item_name=name15       self.item_name=name
17       self.item_description=description16       self.item_description=description
18       self.item_price=price17       self.item_price=price
19       self.item_quantity=quantity18       self.item_quantity=quantity
20   def print_item_description(self):19   def print_item_description(self):
21       print('%s: %s' % (self.item_name, self.item_description))20       print('%s: %s' % (self.item_name, self.item_description))
22class ShoppingCart:21class ShoppingCart:
23   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
24       self.customer_name = customer_name23       self.customer_name = customer_name
25       self.current_date = current_date24       self.current_date = current_date
26       self.cart_items = cart_items  25       self.cart_items = cart_items  
27   def add_item(self, itemToPurchase):26   def add_item(self, itemToPurchase):
28       self.cart_items.append(itemToPurchase)  27       self.cart_items.append(itemToPurchase)  
29   def remove_item(self, itemName):28   def remove_item(self, itemName):
30       tremove_item = False29       tremove_item = False
31       for item in self.cart_items:30       for item in self.cart_items:
32           if item.item_name == itemName:31           if item.item_name == itemName:
33               self.cart_items.remove(item)32               self.cart_items.remove(item)
34               tremove_item = True33               tremove_item = True
35               break34               break
36       if not tremove_item:          35       if not tremove_item:          
37           print('Item not found in the cart. Nothing removed.')36           print('Item not found in the cart. Nothing removed.')
38   def modify_item(self, itemToPurchase):  37   def modify_item(self, itemToPurchase):  
39       tmodify_item = False38       tmodify_item = False
40       for i in range(len(self.cart_items)):39       for i in range(len(self.cart_items)):
41           if self.cart_items[i].item_name == itemToPurchase.item_name:40           if self.cart_items[i].item_name == itemToPurchase.item_name:
42               tmodify_item = True41               tmodify_item = True
43               self.cart_items[i].item_quantity = itemToPurchase.item_quantity42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
44               break43               break
45       if not tmodify_item:      44       if not tmodify_item:      
46           print('Item not found in the cart. Nothing modified.')  45           print('Item not found in the cart. Nothing modified.')  
47   def get_num_items_in_cart(self):46   def get_num_items_in_cart(self):
48       num_items = 047       num_items = 0
49       for item in self.cart_items:48       for item in self.cart_items:
50           num_items = num_items + item.item_quantity49           num_items = num_items + item.item_quantity
51       return num_items50       return num_items
52   def get_cost_of_cart(self):51   def get_cost_of_cart(self):
53       total_cost = 052       total_cost = 0
54       cost = 053       cost = 0
55       for item in self.cart_items:54       for item in self.cart_items:
56           cost = (item.item_quantity * item.item_price)55           cost = (item.item_quantity * item.item_price)
57           total_cost += cost56           total_cost += cost
58       return total_cost57       return total_cost
59   def print_total(self):58   def print_total(self):
60       total_cost = self.get_cost_of_cart()59       total_cost = self.get_cost_of_cart()
61       if (total_cost == 0):60       if (total_cost == 0):
62           print('SHOPPING CART IS EMPTY')61           print('SHOPPING CART IS EMPTY')
63       else:62       else:
64           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
65           print('Number of Items: %d\n' %self.get_num_items_in_cart())64           print('Number of Items: %d\n' %self.get_num_items_in_cart())
66           for item in self.cart_items:65           for item in self.cart_items:
67               total = item.item_price * item.item_quantity66               total = item.item_price * item.item_quantity
68               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
69           print('\nTotal: $%d' %(total_cost))68           print('\nTotal: $%d' %(total_cost))
70   def print_descriptions(self):69   def print_descriptions(self):
71       if len(self.cart_items) == 0:70       if len(self.cart_items) == 0:
72           print('SHOPPING CART IS EMPTY')71           print('SHOPPING CART IS EMPTY')
73       else:  72       else:  
74           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
75           print('\nItem Descriptions')74           print('\nItem Descriptions')
76           for item in self.cart_items:75           for item in self.cart_items:
77               item.print_item_description()  76               item.print_item_description()  
78def print_menu(newCart):77def print_menu(newCart):
79   customer_Cart = newCart78   customer_Cart = newCart
80   menu = ('\nMENU\n'79   menu = ('\nMENU\n'
81       'a - Add item to cart\n'80       'a - Add item to cart\n'
82       'r - Remove item from cart\n'81       'r - Remove item from cart\n'
83       'c - Change item quantity\n'82       'c - Change item quantity\n'
84       "i - Output items' descriptions\n"83       "i - Output items' descriptions\n"
85       'o - Output shopping cart\n'84       'o - Output shopping cart\n'
86       'q - Quit\n')85       'q - Quit\n')
87   command = ''86   command = ''
88   while(command != 'q'):87   while(command != 'q'):
89       print(menu)88       print(menu)
90       command = input('Choose an option:\n')89       command = input('Choose an option:\n')
91       while(command != 'a' and command != 'o' and command != 'i' and command !=90       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
92           command = input('Choose an option:\n')91           command = input('Choose an option:\n')
93       if(command == 'a'):92       if(command == 'a'):
94           print("\nADD ITEM TO CART")93           print("\nADD ITEM TO CART")
95           item_name = input('Enter the item name:\n')94           item_name = input('Enter the item name:\n')
96           item_description = input('Enter the item description:\n')95           item_description = input('Enter the item description:\n')
97           item_price = int(input('Enter the item price:\n'))96           item_price = int(input('Enter the item price:\n'))
98           item_quantity = int(input('Enter the item quantity:\n'))97           item_quantity = int(input('Enter the item quantity:\n'))
99           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
100           customer_Cart.add_item(itemtoPurchase)99           customer_Cart.add_item(itemtoPurchase)
101       elif(command == 'o'):100       elif(command == 'o'):
102           print('\nOUTPUT SHOPPING CART')101           print('\nOUTPUT SHOPPING CART')
103           customer_Cart.print_total()  102           customer_Cart.print_total()  
104       elif(command == 'i'):103       elif(command == 'i'):
105           print('\nOUTPUT ITEMS\' DESCRIPTIONS')104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
106           customer_Cart.print_descriptions()105           customer_Cart.print_descriptions()
107       elif(command == 'r'):106       elif(command == 'r'):
108           print('REMOVE ITEM FROM CART')107           print('REMOVE ITEM FROM CART')
n109           itemName = input('Enter name of item to remove:\n')n108           itemName = input('Enter name of item to remove :\n')
110           customer_Cart.remove_item(itemName)109           customer_Cart.remove_item(itemName)
111       elif(command == 'c'):110       elif(command == 'c'):
112           print('\nCHANGE ITEM QUANTITY')111           print('\nCHANGE ITEM QUANTITY')
n113           itemName = input('Enter the name of the item :\n')n112           itemName = input('Enter name of item :\n')
114           qty = int(input('Enter the new quantity :\n'))113           qty = int(input('Enter the new quantity :\n'))
115           itemToPurchase = ItemToPurchase(itemName,0,qty)114           itemToPurchase = ItemToPurchase(itemName,0,qty)
116           customer_Cart.modify_item(itemToPurchase)115           customer_Cart.modify_item(itemToPurchase)
117if __name__ == "__main__":116if __name__ == "__main__":
118   customer_name = input("Enter customer's name:\n")117   customer_name = input("Enter customer's name:\n")
119   current_date = input("Enter today's date:\n")118   current_date = input("Enter today's date:\n")
120   print("\nCustomer name: %s" %customer_name)119   print("\nCustomer name: %s" %customer_name)
121   print("Today's date: %s" %current_date)120   print("Today's date: %s" %current_date)
122   newCart = ShoppingCart(customer_name, current_date)121   newCart = ShoppingCart(customer_name, current_date)
n123   print_menu(newCart)  from math import sqrtn122   print_menu(newCart)from math import sqrt
124class pt3d:123class pt3d:
n125    def __init__(self,x,y,z):n124    def __init__(self, x, y, z):
126        self.x = x125        self.x = x
127        self.y = y126        self.y = y
128        self.z = z127        self.z = z
129    def __add__(self, other):128    def __add__(self, other):
130        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)129        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
131    def __sub__(self, other):130    def __sub__(self, other):
132        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot131        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>her.z)**2)>her.z)**2)
133    def __eq__(self, other):132    def __eq__(self, other):
134        return self.x == other.x and self.y == other.y and self.z == other.z133        return self.x == other.x and self.y == other.y and self.z == other.z
135    def __str__(self):134    def __str__(self):
t136        myStr = "<"+str(self.x) +","+ str(self.y) + ","+ str(self.z)+">"t135        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
137        return myStr
138p1 = pt3d(1, 1, 1)136p1 = pt3d(1, 1, 1)
139p2 = pt3d(2, 2, 2)137p2 = pt3d(2, 2, 2)
140print(p1 + p2)138print(p1 + p2)
141print(p1 - p2)139print(p1 - p2)
142print(p1 == p2)140print(p1 == p2)
143print(p1+p1 == p2)141print(p1+p1 == p2)
144print(p1==p2+pt3d(-1, -1, -1))142print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 16

Student ID: 10, P-Value: 2.79e-04

Nearest Neighbor ID: 364

Student (left) and Nearest Neighbor (right).


n1class circle():n1class Circle():
2    def __init__(self, radius):2    def __init__(self, radius):
3        self.radius = radius3        self.radius = radius
4    def area(self):4    def area(self):
5        return 3.14 * self.radius * self.radius5        return 3.14 * self.radius * self.radius
6    def perimeter(self):6    def perimeter(self):
n7        return 2 * 3.14 * self.radiusn7        return 2*self.radius*3.14
8if __name__ == '__main__':
9    x = int(input(""))
10    NewCircle = circle(x)8NewCircle = Circle(8)
11    print(NewCircle.area())9print(NewCircle.area())
12    print(NewCircle.perimeter())class ItemToPurchase:10print(NewCircle.perimeter())
11class ItemToPurchase:
13   def __init__(self, name='none', price=0, quantity=0, description='none'):12   def __init__ (self, name= "none", price = 0, quantity = 0, description="none"
 >):
14       self.item_name=name13       self.item_name=name
15       self.item_description=description14       self.item_description=description
16       self.item_price=price15       self.item_price=price
17       self.item_quantity=quantity16       self.item_quantity=quantity
18   def print_item_description(self):17   def print_item_description(self):
19       print('%s: %s' % (self.item_name, self.item_description))18       print('%s: %s' % (self.item_name, self.item_description))
20class ShoppingCart:19class ShoppingCart:
21   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 20   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
22       self.customer_name = customer_name21       self.customer_name = customer_name
23       self.current_date = current_date22       self.current_date = current_date
24       self.cart_items = cart_items  23       self.cart_items = cart_items  
25   def add_item(self, itemToPurchase):24   def add_item(self, itemToPurchase):
26       self.cart_items.append(itemToPurchase)  25       self.cart_items.append(itemToPurchase)  
27   def remove_item(self, itemName):26   def remove_item(self, itemName):
28       tremove_item = False27       tremove_item = False
29       for item in self.cart_items:28       for item in self.cart_items:
30           if item.item_name == itemName:29           if item.item_name == itemName:
31               self.cart_items.remove(item)30               self.cart_items.remove(item)
32               tremove_item = True31               tremove_item = True
33               break32               break
34       if not tremove_item:          33       if not tremove_item:          
35           print('Item not found in the cart. Nothing removed')34           print('Item not found in the cart. Nothing removed')
36   def modify_item(self, itemToPurchase):  35   def modify_item(self, itemToPurchase):  
37       tmodify_item = False36       tmodify_item = False
38       for i in range(len(self.cart_items)):37       for i in range(len(self.cart_items)):
39           if self.cart_items[i].item_name == itemToPurchase.item_name:38           if self.cart_items[i].item_name == itemToPurchase.item_name:
40               tmodify_item = True39               tmodify_item = True
41               self.cart_items[i].item_quantity = itemToPurchase.item_quantity40               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
42               break41               break
43       if not tmodify_item:      42       if not tmodify_item:      
44           print('Item not found in the cart. Nothing modified')  43           print('Item not found in the cart. Nothing modified')  
45   def get_num_items_in_cart(self):44   def get_num_items_in_cart(self):
46       num_items = 045       num_items = 0
47       for item in self.cart_items:46       for item in self.cart_items:
48           num_items = num_items + item.item_quantity47           num_items = num_items + item.item_quantity
49       return num_items48       return num_items
50   def get_cost_of_cart(self):49   def get_cost_of_cart(self):
51       total_cost = 050       total_cost = 0
52       cost = 051       cost = 0
53       for item in self.cart_items:52       for item in self.cart_items:
54           cost = (item.item_quantity * item.item_price)53           cost = (item.item_quantity * item.item_price)
55           total_cost += cost54           total_cost += cost
56       return total_cost55       return total_cost
57   def print_total(self):56   def print_total(self):
58       total_cost = self.get_cost_of_cart()57       total_cost = self.get_cost_of_cart()
59       if (total_cost == 0):58       if (total_cost == 0):
60           print('SHOPPING CART IS EMPTY')59           print('SHOPPING CART IS EMPTY')
61       else:60       else:
62           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr61           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
63           print('Number of Items: %d\n' %self.get_num_items_in_cart())62           print('Number of Items: %d\n' %self.get_num_items_in_cart())
64           for item in self.cart_items:63           for item in self.cart_items:
65               total = item.item_price * item.item_quantity64               total = item.item_price * item.item_quantity
66               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 65               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
67           print('\nTotal: $%d' %(total_cost))66           print('\nTotal: $%d' %(total_cost))
68   def print_descriptions(self):67   def print_descriptions(self):
69       if len(self.cart_items) == 0:68       if len(self.cart_items) == 0:
70           print('SHOPPING CART IS EMPTY')69           print('SHOPPING CART IS EMPTY')
71       else:  70       else:  
72           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr71           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
73           print('\nItem Descriptions')72           print('\nItem Descriptions')
74           for item in self.cart_items:73           for item in self.cart_items:
75               item.print_item_description()  74               item.print_item_description()  
76def print_menu(newCart):75def print_menu(newCart):
77   customer_Cart = newCart76   customer_Cart = newCart
78   menu = ('\nMENU\n'77   menu = ('\nMENU\n'
79       'a - Add item to cart\n'78       'a - Add item to cart\n'
80       'r - Remove item from the cart\n'79       'r - Remove item from the cart\n'
81       'c - Change item quantity\n'80       'c - Change item quantity\n'
82       "i - Output item's descriptions\n"81       "i - Output item's descriptions\n"
83       'o - Output shopping cart\n'82       'o - Output shopping cart\n'
84       'q - Quit\n')83       'q - Quit\n')
85   command = ''84   command = ''
86   while(command != 'q'):85   while(command != 'q'):
87       print(menu)86       print(menu)
88       command = input('Choose an option:')87       command = input('Choose an option:')
89       while(command != 'a' and command != 'o' and command != 'i' and command !=88       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
90           command = input('Choose an option:\n')89           command = input('Choose an option:\n')
91       if(command == 'a'):90       if(command == 'a'):
92           print("\nADD ITEM TO CART")91           print("\nADD ITEM TO CART")
93           item_name = input('Enter the item name:\n')92           item_name = input('Enter the item name:\n')
94           item_description = input('Enter the item description:\n')93           item_description = input('Enter the item description:\n')
95           item_price = int(input('Enter the item price:\n'))94           item_price = int(input('Enter the item price:\n'))
96           item_quantity = int(input('Enter the item quantity:\n'))95           item_quantity = int(input('Enter the item quantity:\n'))
97           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,96           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
98           customer_Cart.add_item(itemtoPurchase)97           customer_Cart.add_item(itemtoPurchase)
99       elif(command == 'o'):98       elif(command == 'o'):
100           print('\nOUTPUT SHOPPING CART')99           print('\nOUTPUT SHOPPING CART')
101           customer_Cart.print_total()  100           customer_Cart.print_total()  
102       elif(command == 'i'):101       elif(command == 'i'):
103           print('\nOUTPUT ITEMS\' DESCRIPTIONS')102           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
104           customer_Cart.print_descriptions()103           customer_Cart.print_descriptions()
105       elif(command == 'r'):104       elif(command == 'r'):
106           print('REMOVE ITEM FROM CART')105           print('REMOVE ITEM FROM CART')
107           itemName = input('Enter the name of the item to remove :\n')106           itemName = input('Enter the name of the item to remove :\n')
108           customer_Cart.remove_item(itemName)107           customer_Cart.remove_item(itemName)
109       elif(command == 'c'):108       elif(command == 'c'):
110           print('\nCHANGE ITEM QUANTITY')109           print('\nCHANGE ITEM QUANTITY')
111           itemName = input('Enter the name of the item :\n')110           itemName = input('Enter the name of the item :\n')
112           qty = int(input('Enter the new quantity :\n'))111           qty = int(input('Enter the new quantity :\n'))
113           itemToPurchase = ItemToPurchase(itemName,0,qty)112           itemToPurchase = ItemToPurchase(itemName,0,qty)
114           customer_Cart.modify_item(itemToPurchase)113           customer_Cart.modify_item(itemToPurchase)
115if __name__ == "__main__":114if __name__ == "__main__":
116   customer_name = input("Enter customer's name:\n")115   customer_name = input("Enter customer's name:\n")
117   current_date = input("Enter today's date:\n")116   current_date = input("Enter today's date:\n")
118   print("\nCustomer name: %s" %customer_name)117   print("\nCustomer name: %s" %customer_name)
119   print("Today's date: %s" %current_date)118   print("Today's date: %s" %current_date)
120   newCart = ShoppingCart(customer_name, current_date)119   newCart = ShoppingCart(customer_name, current_date)
t121   print_menu(newCart)  t120   print_menu(newCart)  import math
122import math
123class pt3d:121class pt3d:
124    def __init__(self,x=0,y=0,z=0):122    def __init__(self,x=0,y=0,z=0):
125        self.x= x123        self.x= x
126        self.y= y124        self.y= y
127        self.z= z125        self.z= z
128    def __add__(self, other):126    def __add__(self, other):
129        x = self.x + other.x127        x = self.x + other.x
130        y = self.y + other.y128        y = self.y + other.y
131        z = self.z + other.z129        z = self.z + other.z
132        return pt3d(x, y,z)130        return pt3d(x, y,z)
133    def __sub__(self, other):131    def __sub__(self, other):
134        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 132        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>2)+math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
135    def __eq__(self, other):133    def __eq__(self, other):
136        return other.x==self.x and other.y==self.y and other.z==self.z134        return other.x==self.x and other.y==self.y and other.z==self.z
137    def __str__(self):135    def __str__(self):
138        return "<{0},{1},{2}>".format(self.x, self.y, self.z)136        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
139if __name__ == '__main__':137if __name__ == '__main__':
140    p1 = pt3d(1, 1, 1)138    p1 = pt3d(1, 1, 1)
141    p2 = pt3d(2, 2, 2)139    p2 = pt3d(2, 2, 2)
142    print(p1+p2)140    print(p1+p2)
143    print(p1-p2)141    print(p1-p2)
144    print(p1==p2)142    print(p1==p2)
145    print(p1+p1==p2)143    print(p1+p1==p2)
146    print(p1==p2+pt3d(-1,-1,-1))144    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 17

Student ID: 364, P-Value: 2.79e-04

Nearest Neighbor ID: 10

Student (left) and Nearest Neighbor (right).


n1class Circle():n1class circle():
2    def __init__(self, radius):2    def __init__(self, radius):
3        self.radius = radius3        self.radius = radius
4    def area(self):4    def area(self):
5        return 3.14 * self.radius * self.radius5        return 3.14 * self.radius * self.radius
6    def perimeter(self):6    def perimeter(self):
n7        return 2*self.radius*3.14n7        return 2 * 3.14 * self.radius
8if __name__ == '__main__':
9    x = int(input(""))
8NewCircle = Circle(8)10    NewCircle = circle(x)
9print(NewCircle.area())11    print(NewCircle.area())
10print(NewCircle.perimeter())12    print(NewCircle.perimeter())class ItemToPurchase:
11class ItemToPurchase:
12   def __init__ (self, name= "none", price = 0, quantity = 0, description="none"13   def __init__(self, name='none', price=0, quantity=0, description='none'):
>): 
13       self.item_name=name14       self.item_name=name
14       self.item_description=description15       self.item_description=description
15       self.item_price=price16       self.item_price=price
16       self.item_quantity=quantity17       self.item_quantity=quantity
17   def print_item_description(self):18   def print_item_description(self):
18       print('%s: %s' % (self.item_name, self.item_description))19       print('%s: %s' % (self.item_name, self.item_description))
19class ShoppingCart:20class ShoppingCart:
20   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 21   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
21       self.customer_name = customer_name22       self.customer_name = customer_name
22       self.current_date = current_date23       self.current_date = current_date
23       self.cart_items = cart_items  24       self.cart_items = cart_items  
24   def add_item(self, itemToPurchase):25   def add_item(self, itemToPurchase):
25       self.cart_items.append(itemToPurchase)  26       self.cart_items.append(itemToPurchase)  
26   def remove_item(self, itemName):27   def remove_item(self, itemName):
27       tremove_item = False28       tremove_item = False
28       for item in self.cart_items:29       for item in self.cart_items:
29           if item.item_name == itemName:30           if item.item_name == itemName:
30               self.cart_items.remove(item)31               self.cart_items.remove(item)
31               tremove_item = True32               tremove_item = True
32               break33               break
33       if not tremove_item:          34       if not tremove_item:          
34           print('Item not found in the cart. Nothing removed')35           print('Item not found in the cart. Nothing removed')
35   def modify_item(self, itemToPurchase):  36   def modify_item(self, itemToPurchase):  
36       tmodify_item = False37       tmodify_item = False
37       for i in range(len(self.cart_items)):38       for i in range(len(self.cart_items)):
38           if self.cart_items[i].item_name == itemToPurchase.item_name:39           if self.cart_items[i].item_name == itemToPurchase.item_name:
39               tmodify_item = True40               tmodify_item = True
40               self.cart_items[i].item_quantity = itemToPurchase.item_quantity41               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
41               break42               break
42       if not tmodify_item:      43       if not tmodify_item:      
43           print('Item not found in the cart. Nothing modified')  44           print('Item not found in the cart. Nothing modified')  
44   def get_num_items_in_cart(self):45   def get_num_items_in_cart(self):
45       num_items = 046       num_items = 0
46       for item in self.cart_items:47       for item in self.cart_items:
47           num_items = num_items + item.item_quantity48           num_items = num_items + item.item_quantity
48       return num_items49       return num_items
49   def get_cost_of_cart(self):50   def get_cost_of_cart(self):
50       total_cost = 051       total_cost = 0
51       cost = 052       cost = 0
52       for item in self.cart_items:53       for item in self.cart_items:
53           cost = (item.item_quantity * item.item_price)54           cost = (item.item_quantity * item.item_price)
54           total_cost += cost55           total_cost += cost
55       return total_cost56       return total_cost
56   def print_total(self):57   def print_total(self):
57       total_cost = self.get_cost_of_cart()58       total_cost = self.get_cost_of_cart()
58       if (total_cost == 0):59       if (total_cost == 0):
59           print('SHOPPING CART IS EMPTY')60           print('SHOPPING CART IS EMPTY')
60       else:61       else:
61           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr62           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
62           print('Number of Items: %d\n' %self.get_num_items_in_cart())63           print('Number of Items: %d\n' %self.get_num_items_in_cart())
63           for item in self.cart_items:64           for item in self.cart_items:
64               total = item.item_price * item.item_quantity65               total = item.item_price * item.item_quantity
65               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 66               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
66           print('\nTotal: $%d' %(total_cost))67           print('\nTotal: $%d' %(total_cost))
67   def print_descriptions(self):68   def print_descriptions(self):
68       if len(self.cart_items) == 0:69       if len(self.cart_items) == 0:
69           print('SHOPPING CART IS EMPTY')70           print('SHOPPING CART IS EMPTY')
70       else:  71       else:  
71           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr72           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
72           print('\nItem Descriptions')73           print('\nItem Descriptions')
73           for item in self.cart_items:74           for item in self.cart_items:
74               item.print_item_description()  75               item.print_item_description()  
75def print_menu(newCart):76def print_menu(newCart):
76   customer_Cart = newCart77   customer_Cart = newCart
77   menu = ('\nMENU\n'78   menu = ('\nMENU\n'
78       'a - Add item to cart\n'79       'a - Add item to cart\n'
79       'r - Remove item from the cart\n'80       'r - Remove item from the cart\n'
80       'c - Change item quantity\n'81       'c - Change item quantity\n'
81       "i - Output item's descriptions\n"82       "i - Output item's descriptions\n"
82       'o - Output shopping cart\n'83       'o - Output shopping cart\n'
83       'q - Quit\n')84       'q - Quit\n')
84   command = ''85   command = ''
85   while(command != 'q'):86   while(command != 'q'):
86       print(menu)87       print(menu)
87       command = input('Choose an option:')88       command = input('Choose an option:')
88       while(command != 'a' and command != 'o' and command != 'i' and command !=89       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
89           command = input('Choose an option:\n')90           command = input('Choose an option:\n')
90       if(command == 'a'):91       if(command == 'a'):
91           print("\nADD ITEM TO CART")92           print("\nADD ITEM TO CART")
92           item_name = input('Enter the item name:\n')93           item_name = input('Enter the item name:\n')
93           item_description = input('Enter the item description:\n')94           item_description = input('Enter the item description:\n')
94           item_price = int(input('Enter the item price:\n'))95           item_price = int(input('Enter the item price:\n'))
95           item_quantity = int(input('Enter the item quantity:\n'))96           item_quantity = int(input('Enter the item quantity:\n'))
96           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,97           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
97           customer_Cart.add_item(itemtoPurchase)98           customer_Cart.add_item(itemtoPurchase)
98       elif(command == 'o'):99       elif(command == 'o'):
99           print('\nOUTPUT SHOPPING CART')100           print('\nOUTPUT SHOPPING CART')
100           customer_Cart.print_total()  101           customer_Cart.print_total()  
101       elif(command == 'i'):102       elif(command == 'i'):
102           print('\nOUTPUT ITEMS\' DESCRIPTIONS')103           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
103           customer_Cart.print_descriptions()104           customer_Cart.print_descriptions()
104       elif(command == 'r'):105       elif(command == 'r'):
105           print('REMOVE ITEM FROM CART')106           print('REMOVE ITEM FROM CART')
106           itemName = input('Enter the name of the item to remove :\n')107           itemName = input('Enter the name of the item to remove :\n')
107           customer_Cart.remove_item(itemName)108           customer_Cart.remove_item(itemName)
108       elif(command == 'c'):109       elif(command == 'c'):
109           print('\nCHANGE ITEM QUANTITY')110           print('\nCHANGE ITEM QUANTITY')
110           itemName = input('Enter the name of the item :\n')111           itemName = input('Enter the name of the item :\n')
111           qty = int(input('Enter the new quantity :\n'))112           qty = int(input('Enter the new quantity :\n'))
112           itemToPurchase = ItemToPurchase(itemName,0,qty)113           itemToPurchase = ItemToPurchase(itemName,0,qty)
113           customer_Cart.modify_item(itemToPurchase)114           customer_Cart.modify_item(itemToPurchase)
114if __name__ == "__main__":115if __name__ == "__main__":
115   customer_name = input("Enter customer's name:\n")116   customer_name = input("Enter customer's name:\n")
116   current_date = input("Enter today's date:\n")117   current_date = input("Enter today's date:\n")
117   print("\nCustomer name: %s" %customer_name)118   print("\nCustomer name: %s" %customer_name)
118   print("Today's date: %s" %current_date)119   print("Today's date: %s" %current_date)
119   newCart = ShoppingCart(customer_name, current_date)120   newCart = ShoppingCart(customer_name, current_date)
t120   print_menu(newCart)  import matht121   print_menu(newCart)  
122import math
121class pt3d:123class pt3d:
122    def __init__(self,x=0,y=0,z=0):124    def __init__(self,x=0,y=0,z=0):
123        self.x= x125        self.x= x
124        self.y= y126        self.y= y
125        self.z= z127        self.z= z
126    def __add__(self, other):128    def __add__(self, other):
127        x = self.x + other.x129        x = self.x + other.x
128        y = self.y + other.y130        y = self.y + other.y
129        z = self.z + other.z131        z = self.z + other.z
130        return pt3d(x, y,z)132        return pt3d(x, y,z)
131    def __sub__(self, other):133    def __sub__(self, other):
132        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 134        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>2)+math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
133    def __eq__(self, other):135    def __eq__(self, other):
134        return other.x==self.x and other.y==self.y and other.z==self.z136        return other.x==self.x and other.y==self.y and other.z==self.z
135    def __str__(self):137    def __str__(self):
136        return "<{0},{1},{2}>".format(self.x, self.y, self.z)138        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
137if __name__ == '__main__':139if __name__ == '__main__':
138    p1 = pt3d(1, 1, 1)140    p1 = pt3d(1, 1, 1)
139    p2 = pt3d(2, 2, 2)141    p2 = pt3d(2, 2, 2)
140    print(p1+p2)142    print(p1+p2)
141    print(p1-p2)143    print(p1-p2)
142    print(p1==p2)144    print(p1==p2)
143    print(p1+p1==p2)145    print(p1+p1==p2)
144    print(p1==p2+pt3d(-1,-1,-1))146    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 18

Student ID: 129, P-Value: 2.79e-04

Nearest Neighbor ID: 478

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle:n2class Circle :
3    def __init__(self,x):3    def __init__(self,radius):
4        self.x = x4        self.radius = radius
5    def area(self):5    def area(self):
n6        return math.pi*x**2n6        return math.pi*self.radius*self.radius
7    def perimeter(self):7    def perimeter(self):
n8        return 2*math.pi*xn8        return 2*math.pi*self.radius
9if __name__=='__main__':9if __name__ == '__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
n13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:n13    print('{:.5f}'.format(NewCircle.perimeter()))
14class ItemToPurchase:
14   def __init__(self, name='none', price=0, quantity=0, description='none'):15   def __init__(self, name='none', price=0, quantity=0, description='none'):
15       self.item_name=name16       self.item_name=name
16       self.item_description=description17       self.item_description=description
17       self.item_price=price18       self.item_price=price
18       self.item_quantity=quantity19       self.item_quantity=quantity
19   def print_item_description(self):20   def print_item_description(self):
20       print('%s: %s' % (self.item_name, self.item_description))21       print('%s: %s' % (self.item_name, self.item_description))
21class ShoppingCart:22class ShoppingCart:
22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 23   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
23       self.customer_name = customer_name24       self.customer_name = customer_name
24       self.current_date = current_date25       self.current_date = current_date
25       self.cart_items = cart_items  26       self.cart_items = cart_items  
26   def add_item(self, itemToPurchase):27   def add_item(self, itemToPurchase):
27       self.cart_items.append(itemToPurchase)  28       self.cart_items.append(itemToPurchase)  
28   def remove_item(self, itemName):29   def remove_item(self, itemName):
29       tremove_item = False30       tremove_item = False
30       for item in self.cart_items:31       for item in self.cart_items:
31           if item.item_name == itemName:32           if item.item_name == itemName:
32               self.cart_items.remove(item)33               self.cart_items.remove(item)
33               tremove_item = True34               tremove_item = True
34               break35               break
35       if not tremove_item:          36       if not tremove_item:          
36           print('Item not found in the cart. Nothing removed')37           print('Item not found in the cart. Nothing removed')
37   def modify_item(self, itemToPurchase):  38   def modify_item(self, itemToPurchase):  
38       tmodify_item = False39       tmodify_item = False
39       for i in range(len(self.cart_items)):40       for i in range(len(self.cart_items)):
40           if self.cart_items[i].item_name == itemToPurchase.item_name:41           if self.cart_items[i].item_name == itemToPurchase.item_name:
41               tmodify_item = True42               tmodify_item = True
42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity43               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43               break44               break
44       if not tmodify_item:      45       if not tmodify_item:      
45           print('Item not found in the cart. Nothing modified')  46           print('Item not found in the cart. Nothing modified')  
46   def get_num_items_in_cart(self):47   def get_num_items_in_cart(self):
47       num_items = 048       num_items = 0
48       for item in self.cart_items:49       for item in self.cart_items:
49           num_items = num_items + item.item_quantity50           num_items = num_items + item.item_quantity
50       return num_items51       return num_items
51   def get_cost_of_cart(self):52   def get_cost_of_cart(self):
52       total_cost = 053       total_cost = 0
53       cost = 054       cost = 0
54       for item in self.cart_items:55       for item in self.cart_items:
55           cost = (item.item_quantity * item.item_price)56           cost = (item.item_quantity * item.item_price)
56           total_cost += cost57           total_cost += cost
57       return total_cost58       return total_cost
58   def print_total(self):59   def print_total(self):
59       total_cost = self.get_cost_of_cart()60       total_cost = self.get_cost_of_cart()
60       if (total_cost == 0):61       if (total_cost == 0):
61           print('SHOPPING CART IS EMPTY')62           print('SHOPPING CART IS EMPTY')
62       else:63       else:
63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr64           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
64           print('Number of Items: %d\n' %self.get_num_items_in_cart())65           print('Number of Items: %d\n' %self.get_num_items_in_cart())
65           for item in self.cart_items:66           for item in self.cart_items:
66               total = item.item_price * item.item_quantity67               total = item.item_price * item.item_quantity
67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 68               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
68           print('\nTotal: $%d' %(total_cost))69           print('\nTotal: $%d' %(total_cost))
69   def print_descriptions(self):70   def print_descriptions(self):
70       if len(self.cart_items) == 0:71       if len(self.cart_items) == 0:
71           print('SHOPPING CART IS EMPTY')72           print('SHOPPING CART IS EMPTY')
72       else:  73       else:  
73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr74           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
74           print('\nItem Descriptions')75           print('\nItem Descriptions')
75           for item in self.cart_items:76           for item in self.cart_items:
76               item.print_item_description()  77               item.print_item_description()  
77def print_menu(newCart):78def print_menu(newCart):
78   customer_Cart = newCart79   customer_Cart = newCart
79   menu = ('\nMENU\n'80   menu = ('\nMENU\n'
80       'a - Add item to cart\n'81       'a - Add item to cart\n'
n81       'r - Remove item from the cart\n'n82       'r - Remove item from cart\n'
82       'c - Change item quantity\n'83       'c - Change item quantity\n'
n83       "i - Output item's descriptions\n"n84       "i - Output items' descriptions\n"
84       'o - Output shopping cart\n'85       'o - Output shopping cart\n'
85       'q - Quit\n')86       'q - Quit\n')
86   command = ''87   command = ''
87   while(command != 'q'):88   while(command != 'q'):
88       print(menu)89       print(menu)
n89       command = input('Choose an option:')n90       command = input('Choose an option:\n')
90       while(command != 'a' and command != 'o' and command != 'i' and command !=91       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
91           command = input('Choose an option:\n')92           command = input('Choose an option:\n')
92       if(command == 'a'):93       if(command == 'a'):
93           print("\nADD ITEM TO CART")94           print("\nADD ITEM TO CART")
94           item_name = input('Enter the item name:\n')95           item_name = input('Enter the item name:\n')
95           item_description = input('Enter the item description:\n')96           item_description = input('Enter the item description:\n')
96           item_price = int(input('Enter the item price:\n'))97           item_price = int(input('Enter the item price:\n'))
97           item_quantity = int(input('Enter the item quantity:\n'))98           item_quantity = int(input('Enter the item quantity:\n'))
98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,99           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
99           customer_Cart.add_item(itemtoPurchase)100           customer_Cart.add_item(itemtoPurchase)
100       elif(command == 'o'):101       elif(command == 'o'):
101           print('\nOUTPUT SHOPPING CART')102           print('\nOUTPUT SHOPPING CART')
102           customer_Cart.print_total()  103           customer_Cart.print_total()  
103       elif(command == 'i'):104       elif(command == 'i'):
104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')105           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
105           customer_Cart.print_descriptions()106           customer_Cart.print_descriptions()
106       elif(command == 'r'):107       elif(command == 'r'):
107           print('REMOVE ITEM FROM CART')108           print('REMOVE ITEM FROM CART')
108           itemName = input('Enter the name of the item to remove :\n')109           itemName = input('Enter the name of the item to remove :\n')
109           customer_Cart.remove_item(itemName)110           customer_Cart.remove_item(itemName)
110       elif(command == 'c'):111       elif(command == 'c'):
111           print('\nCHANGE ITEM QUANTITY')112           print('\nCHANGE ITEM QUANTITY')
112           itemName = input('Enter the name of the item :\n')113           itemName = input('Enter the name of the item :\n')
113           qty = int(input('Enter the new quantity :\n'))114           qty = int(input('Enter the new quantity :\n'))
114           itemToPurchase = ItemToPurchase(itemName,0,qty)115           itemToPurchase = ItemToPurchase(itemName,0,qty)
115           customer_Cart.modify_item(itemToPurchase)116           customer_Cart.modify_item(itemToPurchase)
116if __name__ == "__main__":117if __name__ == "__main__":
117   customer_name = input("Enter customer's name:\n")118   customer_name = input("Enter customer's name:\n")
118   current_date = input("Enter today's date:\n")119   current_date = input("Enter today's date:\n")
119   print("\nCustomer name: %s" %customer_name)120   print("\nCustomer name: %s" %customer_name)
120   print("Today's date: %s" %current_date)121   print("Today's date: %s" %current_date)
121   newCart = ShoppingCart(customer_name, current_date)122   newCart = ShoppingCart(customer_name, current_date)
n122   print_menu(newCart)  import mathn123   print_menu(newCart)import math
123class pt3d:124class pt3d:
n124    def __init__(self,x,y,z):n125    def __init__(self,x=0,y=0,z=0):
125        self.x= x126        self.x= x
126        self.y= y127        self.y= y
127        self.z= z128        self.z= z
t128def __add__(self, other):t129    def __add__(self, other):
129    x = self.x + other.x130        x = self.x + other.x
130    y = self.y + other.y131        y = self.y + other.y
131    z = self.z + other.z132        z = self.z + other.z
132    return pt3d(x, y,z)133        return pt3d(x, y,z)
133def __sub__(self, other):134    def __sub__(self, other):
134    return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 2)+m135        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>ath.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
135def __eq__(self, other):136    def __eq__(self, other):
136    return other.x==self.x and other.y==self.y and other.z==self.z137        return other.x==self.x and other.y==self.y and other.z==self.z
137def __str__(self):138    def __str__(self):
138    return "<{0},{1},{2}>".format(self.x, self.y, self.z)139        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
139if __name__ == '__main__':140if __name__ == '__main__':
140    p1 = pt3d(1, 1, 1)141    p1 = pt3d(1, 1, 1)
141    p2 = pt3d(2, 2, 2)142    p2 = pt3d(2, 2, 2)
142    print(p1+p2)143    print(p1+p2)
143    print(p1-p2)144    print(p1-p2)
144    print(p1==p2)145    print(p1==p2)
145    print(p1+p1==p2)146    print(p1+p1==p2)
146    print(p1==p2+pt3d(-1,-1,-1))147    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 19

Student ID: 309, P-Value: 2.99e-04

Nearest Neighbor ID: 279

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle:n2class Circle():
3    def __init__(self,radius):3    def __init__(self, radius):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
6        return math.pi * self.radius**26        return math.pi * self.radius**2
7    def perimeter(self):7    def perimeter(self):
n8        return 2 * math.pi * self.radiusn8        return 2*math.pi*self.radius
9if __name__=='__main__':9if __name__ == '__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
n13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:n13    print('{:.5f}'.format(NewCircle.perimeter()))
14class ItemToPurchase:
14       def __init__(self, name='none', price=0, quantity=0, description='none'):15   def __init__(self, name='none', price=0, quantity=0, description='none'):
15        self.item_name=name16       self.item_name=name
16        self.item_description=description17       self.item_description=description
17        self.item_price=price18       self.item_price=price
18        self.item_quantity=quantity19       self.item_quantity=quantity
19        def print_item_description(self):20   def print_item_description(self):
20            print('%s: %s' % (self.item_name, self.item_description))21       print('%s: %s' % (self.item_name, self.item_description))
21class ShoppingCart:22class ShoppingCart:
22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 23   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
23       self.customer_name = customer_name24       self.customer_name = customer_name
24       self.current_date = current_date25       self.current_date = current_date
25       self.cart_items = cart_items  26       self.cart_items = cart_items  
26   def add_item(self, itemToPurchase):27   def add_item(self, itemToPurchase):
27       self.cart_items.append(itemToPurchase)  28       self.cart_items.append(itemToPurchase)  
28   def remove_item(self, itemName):29   def remove_item(self, itemName):
29       tremove_item = False30       tremove_item = False
30       for item in self.cart_items:31       for item in self.cart_items:
31           if item.item_name == itemName:32           if item.item_name == itemName:
32               self.cart_items.remove(item)33               self.cart_items.remove(item)
33               tremove_item = True34               tremove_item = True
34               break35               break
35       if not tremove_item:          36       if not tremove_item:          
36           print('Item not found in the cart. Nothing removed')37           print('Item not found in the cart. Nothing removed')
37   def modify_item(self, itemToPurchase):  38   def modify_item(self, itemToPurchase):  
38       tmodify_item = False39       tmodify_item = False
39       for i in range(len(self.cart_items)):40       for i in range(len(self.cart_items)):
40           if self.cart_items[i].item_name == itemToPurchase.item_name:41           if self.cart_items[i].item_name == itemToPurchase.item_name:
41               tmodify_item = True42               tmodify_item = True
42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity43               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43               break44               break
44       if not tmodify_item:      45       if not tmodify_item:      
45           print('Item not found in the cart. Nothing modified')  46           print('Item not found in the cart. Nothing modified')  
46   def get_num_items_in_cart(self):47   def get_num_items_in_cart(self):
47       num_items = 048       num_items = 0
48       for item in self.cart_items:49       for item in self.cart_items:
49           num_items = num_items + item.item_quantity50           num_items = num_items + item.item_quantity
50       return num_items51       return num_items
51   def get_cost_of_cart(self):52   def get_cost_of_cart(self):
52       total_cost = 053       total_cost = 0
53       cost = 054       cost = 0
54       for item in self.cart_items:55       for item in self.cart_items:
55           cost = (item.item_quantity * item.item_price)56           cost = (item.item_quantity * item.item_price)
56           total_cost += cost57           total_cost += cost
57       return total_cost58       return total_cost
58   def print_total(self):59   def print_total(self):
59       total_cost = self.get_cost_of_cart()60       total_cost = self.get_cost_of_cart()
60       if (total_cost == 0):61       if (total_cost == 0):
61           print('SHOPPING CART IS EMPTY')62           print('SHOPPING CART IS EMPTY')
62       else:63       else:
63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr64           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
64           print('Number of Items: %d\n' %self.get_num_items_in_cart())65           print('Number of Items: %d\n' %self.get_num_items_in_cart())
65           for item in self.cart_items:66           for item in self.cart_items:
66               total = item.item_price * item.item_quantity67               total = item.item_price * item.item_quantity
67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 68               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
68           print('\nTotal: $%d' %(total_cost))69           print('\nTotal: $%d' %(total_cost))
69   def print_descriptions(self):70   def print_descriptions(self):
70       if len(self.cart_items) == 0:71       if len(self.cart_items) == 0:
71           print('SHOPPING CART IS EMPTY')72           print('SHOPPING CART IS EMPTY')
72       else:  73       else:  
73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr74           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
74           print('\nItem Descriptions')75           print('\nItem Descriptions')
75           for item in self.cart_items:76           for item in self.cart_items:
76               item.print_item_description()  77               item.print_item_description()  
n77def print_menu(new_cart):n78def print_menu(newCart):
78   customer_cart = new_cart79   customer_Cart = newCart
79   menu = ('\nMENU\n'80   menu = ('\nMENU\n'
n80       "a - Add item to cart\n"n81       'a - Add item to cart\n'
81       "r - Remove item from cart\n"82       'r - Remove item from the cart\n'
82       "c - Change item quantity\n"83       'c - Change item quantity\n'
83       "i - Output items' descriptions\n"84       "i - Output item's descriptions\n"
84       "o - Output shopping cart\n"85       'o - Output shopping cart\n'
85       "q - Quit\n")86       'q - Quit\n')
86   command = ''87   command = ''
87   while(command != 'q'):88   while(command != 'q'):
88       print(menu)89       print(menu)
n89       command = input('Choose an option:\n')n90       command = input('Choose an option:')
90       while(command != 'a' and command != 'o' and command != 'i' and command !=91       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
91           command = input('Choose an option:\n')92           command = input('Choose an option:\n')
92       if(command == 'a'):93       if(command == 'a'):
93           print("\nADD ITEM TO CART")94           print("\nADD ITEM TO CART")
94           item_name = input('Enter the item name:\n')95           item_name = input('Enter the item name:\n')
95           item_description = input('Enter the item description:\n')96           item_description = input('Enter the item description:\n')
96           item_price = int(input('Enter the item price:\n'))97           item_price = int(input('Enter the item price:\n'))
97           item_quantity = int(input('Enter the item quantity:\n'))98           item_quantity = int(input('Enter the item quantity:\n'))
98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,99           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
99           customer_Cart.add_item(itemtoPurchase)100           customer_Cart.add_item(itemtoPurchase)
100       elif(command == 'o'):101       elif(command == 'o'):
101           print('\nOUTPUT SHOPPING CART')102           print('\nOUTPUT SHOPPING CART')
n102           customer_cart.print_total()  n103           customer_Cart.print_total()  
103       elif(command == 'i'):104       elif(command == 'i'):
104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')105           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
n105           customer_cart.print_descriptions()n106           customer_Cart.print_descriptions()
106       elif(command == 'r'):107       elif(command == 'r'):
107           print('REMOVE ITEM FROM CART')108           print('REMOVE ITEM FROM CART')
108           itemName = input('Enter the name of the item to remove :\n')109           itemName = input('Enter the name of the item to remove :\n')
n109           customer_cart.remove_item(itemName)n110           customer_Cart.remove_item(itemName)
110       elif(command == 'c'):111       elif(command == 'c'):
111           print('\nCHANGE ITEM QUANTITY')112           print('\nCHANGE ITEM QUANTITY')
112           itemName = input('Enter the name of the item :\n')113           itemName = input('Enter the name of the item :\n')
113           qty = int(input('Enter the new quantity :\n'))114           qty = int(input('Enter the new quantity :\n'))
114           itemToPurchase = ItemToPurchase(itemName,0,qty)115           itemToPurchase = ItemToPurchase(itemName,0,qty)
n115           customer_cart.modify_item(itemToPurchase)n116           customer_Cart.modify_item(itemToPurchase)
116if __name__ == "__main__":117if __name__ == "__main__":
117   customer_name = input("Enter customer's name:\n")118   customer_name = input("Enter customer's name:\n")
118   current_date = input("Enter today's date:\n")119   current_date = input("Enter today's date:\n")
119   print("\nCustomer name: %s" %customer_name)120   print("\nCustomer name: %s" %customer_name)
120   print("Today's date: %s" %current_date)121   print("Today's date: %s" %current_date)
t121   new_cart = ShoppingCart(customer_name, current_date)t122   newCart = ShoppingCart(customer_name, current_date)
122   print_menu(new_cart)123   print_menu(newCart)from math import sqrt
123from math import sqrt
124class pt3d:124class pt3d:
125    def __init__(self, x, y, z):125    def __init__(self, x, y, z):
126        self.x = x126        self.x = x
127        self.y = y127        self.y = y
128        self.z = z128        self.z = z
129    def __add__(self, other):129    def __add__(self, other):
130        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)130        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
131    def __sub__(self, other):131    def __sub__(self, other):
132        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot132        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>her.z)**2)>her.z)**2)
133    def __eq__(self, other):133    def __eq__(self, other):
134        return self.x == other.x & self.y == other.y & self.z == other.z134        return self.x == other.x & self.y == other.y & self.z == other.z
135    def __str__(self):135    def __str__(self):
136        return '<{}, {}, {}>'.format(self.x, self.y, self.z)136        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
137p1 = pt3d(1, 1, 1)137p1 = pt3d(1, 1, 1)
138p2 = pt3d(2, 2, 2)138p2 = pt3d(2, 2, 2)
139print(p1 + p2)139print(p1 + p2)
140print(p1 - p2)140print(p1 - p2)
141print(p1 == p2)141print(p1 == p2)
142print(p1+p1 == p2)142print(p1+p1 == p2)
143print(p1==p2+pt3d(-1, -1, -1))143print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 20

Student ID: 178, P-Value: 3.20e-04

Nearest Neighbor ID: 450

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class circle():n2class Circle:
3    def __init__(self,radius):3    def __init__(self, radius):
4        self.radius=radius4        self.radius = int(radius)
5    def area(self):5    def area(self):
n6        return math.pi*(self.radius**2)n6        return round(math.pi*self.radius*self.radius,3)
7    def perimeter(self):7    def perimeter(self):
n8        return 2*math.pi*self.radiusn8        return round(2*math.pi*self.radius,3)
9r=int(input("Enter radius of circle: "))9circle=Circle(2)
10obj=circle(r)
11print("Area of circle:",round(obj.area(),2))10print("Area of circle=",circle.area())
12print("Perimeter of circle:",round(obj.perimeter(),2))class ItemToPurchase:11print("Perimeter of circle=",circle.perimeter())class ItemToPurchase:
13   def __init__(self, name='none', price=0, quantity=0, description='none'):12   def __init__(self, name='none', price=0, quantity=0, description='none'):
14       self.item_name=name13       self.item_name=name
15       self.item_description=description14       self.item_description=description
16       self.item_price=price15       self.item_price=price
17       self.item_quantity=quantity16       self.item_quantity=quantity
18   def print_item_description(self):17   def print_item_description(self):
19       print('%s: %s' % (self.item_name, self.item_description))18       print('%s: %s' % (self.item_name, self.item_description))
20class ShoppingCart:19class ShoppingCart:
21   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 20   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
22       self.customer_name = customer_name21       self.customer_name = customer_name
23       self.current_date = current_date22       self.current_date = current_date
24       self.cart_items = cart_items  23       self.cart_items = cart_items  
25   def add_item(self, itemToPurchase):24   def add_item(self, itemToPurchase):
26       self.cart_items.append(itemToPurchase)  25       self.cart_items.append(itemToPurchase)  
27   def remove_item(self, itemName):26   def remove_item(self, itemName):
28       tremove_item = False27       tremove_item = False
29       for item in self.cart_items:28       for item in self.cart_items:
30           if item.item_name == itemName:29           if item.item_name == itemName:
31               self.cart_items.remove(item)30               self.cart_items.remove(item)
32               tremove_item = True31               tremove_item = True
33               break32               break
34       if not tremove_item:          33       if not tremove_item:          
35           print('Item not found in the cart. Nothing removed')34           print('Item not found in the cart. Nothing removed')
36   def modify_item(self, itemToPurchase):  35   def modify_item(self, itemToPurchase):  
37       tmodify_item = False36       tmodify_item = False
38       for i in range(len(self.cart_items)):37       for i in range(len(self.cart_items)):
39           if self.cart_items[i].item_name == itemToPurchase.item_name:38           if self.cart_items[i].item_name == itemToPurchase.item_name:
40               tmodify_item = True39               tmodify_item = True
41               self.cart_items[i].item_quantity = itemToPurchase.item_quantity40               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
42               break41               break
43       if not tmodify_item:      42       if not tmodify_item:      
44           print('Item not found in the cart. Nothing modified')  43           print('Item not found in the cart. Nothing modified')  
45   def get_num_items_in_cart(self):44   def get_num_items_in_cart(self):
46       num_items = 045       num_items = 0
47       for item in self.cart_items:46       for item in self.cart_items:
48           num_items = num_items + item.item_quantity47           num_items = num_items + item.item_quantity
49       return num_items48       return num_items
50   def get_cost_of_cart(self):49   def get_cost_of_cart(self):
51       total_cost = 050       total_cost = 0
52       cost = 051       cost = 0
53       for item in self.cart_items:52       for item in self.cart_items:
54           cost = (item.item_quantity * item.item_price)53           cost = (item.item_quantity * item.item_price)
55           total_cost += cost54           total_cost += cost
56       return total_cost55       return total_cost
57   def print_total(self):56   def print_total(self):
58       total_cost = self.get_cost_of_cart()57       total_cost = self.get_cost_of_cart()
59       if (total_cost == 0):58       if (total_cost == 0):
60           print('SHOPPING CART IS EMPTY')59           print('SHOPPING CART IS EMPTY')
61       else:60       else:
62           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr61           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
63           print('Number of Items: %d\n' %self.get_num_items_in_cart())62           print('Number of Items: %d\n' %self.get_num_items_in_cart())
64           for item in self.cart_items:63           for item in self.cart_items:
65               total = item.item_price * item.item_quantity64               total = item.item_price * item.item_quantity
66               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 65               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
67           print('\nTotal: $%d' %(total_cost))66           print('\nTotal: $%d' %(total_cost))
68   def print_descriptions(self):67   def print_descriptions(self):
69       if len(self.cart_items) == 0:68       if len(self.cart_items) == 0:
70           print('SHOPPING CART IS EMPTY')69           print('SHOPPING CART IS EMPTY')
71       else:  70       else:  
72           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr71           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
73           print('\nItem Descriptions')72           print('\nItem Descriptions')
74           for item in self.cart_items:73           for item in self.cart_items:
75               item.print_item_description()  74               item.print_item_description()  
76def print_menu(newCart):75def print_menu(newCart):
77   customer_Cart = newCart76   customer_Cart = newCart
78   menu = ('\nMENU\n'77   menu = ('\nMENU\n'
79       'a - Add item to cart\n'78       'a - Add item to cart\n'
n80       'r - Remove item from cart\n'n79       'r - Remove item from the cart\n'
81       'c - Change item quantity\n'80       'c - Change item quantity\n'
n82       "i - Output items' descriptions\n"n81       "i - Output item's descriptions\n"
83       'o - Output shopping cart\n'82       'o - Output shopping cart\n'
84       'q - Quit\n')83       'q - Quit\n')
85   command = ''84   command = ''
86   while(command != 'q'):85   while(command != 'q'):
87       print(menu)86       print(menu)
n88       command = input('Choose an option:\n')n87       command = input('Choose an option:')
89       while(command != 'a' and command != 'o' and command != 'i' and command !=88       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
90           command = input('Choose an option:\n')89           command = input('Choose an option:\n')
91       if(command == 'a'):90       if(command == 'a'):
92           print("\nADD ITEM TO CART")91           print("\nADD ITEM TO CART")
93           item_name = input('Enter the item name:\n')92           item_name = input('Enter the item name:\n')
94           item_description = input('Enter the item description:\n')93           item_description = input('Enter the item description:\n')
95           item_price = int(input('Enter the item price:\n'))94           item_price = int(input('Enter the item price:\n'))
96           item_quantity = int(input('Enter the item quantity:\n'))95           item_quantity = int(input('Enter the item quantity:\n'))
97           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,96           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
98           customer_Cart.add_item(itemtoPurchase)97           customer_Cart.add_item(itemtoPurchase)
99       elif(command == 'o'):98       elif(command == 'o'):
100           print('\nOUTPUT SHOPPING CART')99           print('\nOUTPUT SHOPPING CART')
101           customer_Cart.print_total()  100           customer_Cart.print_total()  
102       elif(command == 'i'):101       elif(command == 'i'):
103           print('\nOUTPUT ITEMS\' DESCRIPTIONS')102           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
104           customer_Cart.print_descriptions()103           customer_Cart.print_descriptions()
105       elif(command == 'r'):104       elif(command == 'r'):
106           print('REMOVE ITEM FROM CART')105           print('REMOVE ITEM FROM CART')
107           itemName = input('Enter the name of the item to remove :\n')106           itemName = input('Enter the name of the item to remove :\n')
108           customer_Cart.remove_item(itemName)107           customer_Cart.remove_item(itemName)
109       elif(command == 'c'):108       elif(command == 'c'):
110           print('\nCHANGE ITEM QUANTITY')109           print('\nCHANGE ITEM QUANTITY')
111           itemName = input('Enter the name of the item :\n')110           itemName = input('Enter the name of the item :\n')
112           qty = int(input('Enter the new quantity :\n'))111           qty = int(input('Enter the new quantity :\n'))
113           itemToPurchase = ItemToPurchase(itemName,0,qty)112           itemToPurchase = ItemToPurchase(itemName,0,qty)
114           customer_Cart.modify_item(itemToPurchase)113           customer_Cart.modify_item(itemToPurchase)
115if __name__ == "__main__":114if __name__ == "__main__":
116   customer_name = input("Enter customer's name:\n")115   customer_name = input("Enter customer's name:\n")
117   current_date = input("Enter today's date:\n")116   current_date = input("Enter today's date:\n")
118   print("\nCustomer name: %s" %customer_name)117   print("\nCustomer name: %s" %customer_name)
119   print("Today's date: %s" %current_date)118   print("Today's date: %s" %current_date)
120   newCart = ShoppingCart(customer_name, current_date)119   newCart = ShoppingCart(customer_name, current_date)
t121   print_menu(newCart)  t120   print_menu(newCart)from math import sqrt
122from math import sqrt
123class pt3d:121class pt3d:
124    def __init__(self, x, y, z):122    def __init__(self, x, y, z):
125        self.x = x123        self.x = x
126        self.y = y124        self.y = y
127        self.z = z125        self.z = z
128    def __add__(self, other):126    def __add__(self, other):
129        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)127        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
130    def __sub__(self, other):128    def __sub__(self, other):
131        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot129        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>her.z)**2)>her.z)**2)
132    def __eq__(self, other):130    def __eq__(self, other):
133        return self.x == other.x & self.y == other.y & self.z == other.z131        return self.x == other.x & self.y == other.y & self.z == other.z
134    def __str__(self):132    def __str__(self):
135        return '<{}, {}, {}>'.format(self.x, self.y, self.z)133        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
136p1 = pt3d(1, 1, 1)134p1 = pt3d(1, 1, 1)
137p2 = pt3d(2, 2, 2)135p2 = pt3d(2, 2, 2)
138print(p1 + p2)136print(p1 + p2)
139print(p1 - p2)137print(p1 - p2)
140print(p1 == p2)138print(p1 == p2)
141print(p1+p1 == p2)139print(p1+p1 == p2)
142print(p1==p2+pt3d(-1, -1, -1))140print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 21

Student ID: 423, P-Value: 4.17e-04

Nearest Neighbor ID: 370

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
3    def __init__(self,radius):3    def __init__(self,radius):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
6        return math.pi * self.radius ** 26        return math.pi * self.radius ** 2
7    def perimeter(self):7    def perimeter(self):
8        return 2 * math.pi * self.radius8        return 2 * math.pi * self.radius
9if __name__=='__main__':9if __name__=='__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
n13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:n13    print('{:.5f}'.format(NewCircle.perimeter()))
14class ItemToPurchase:
14       def __init__(self, name='none', price=0, quantity=0, description='none'):15   def __init__(self, name='none', price=0, quantity=0, description='none'):
15        self.item_name=name16       self.item_name=name
16        self.item_description=description17       self.item_description=description
17        self.item_price=price18       self.item_price=price
18        self.item_quantity=quantity19       self.item_quantity=quantity
19        def print_item_description(self):20   def print_item_description(self):
20            print('%s: %s' % (self.item_name, self.item_description))21       print('%s: %s' % (self.item_name, self.item_description))
21class ShoppingCart:22class ShoppingCart:
22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 23   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
23       self.customer_name = customer_name24       self.customer_name = customer_name
24       self.current_date = current_date25       self.current_date = current_date
25       self.cart_items = cart_items  26       self.cart_items = cart_items  
26   def add_item(self, itemToPurchase):27   def add_item(self, itemToPurchase):
27       self.cart_items.append(itemToPurchase)  28       self.cart_items.append(itemToPurchase)  
28   def remove_item(self, itemName):29   def remove_item(self, itemName):
29       tremove_item = False30       tremove_item = False
30       for item in self.cart_items:31       for item in self.cart_items:
31           if item.item_name == itemName:32           if item.item_name == itemName:
32               self.cart_items.remove(item)33               self.cart_items.remove(item)
33               tremove_item = True34               tremove_item = True
34               break35               break
35       if not tremove_item:          36       if not tremove_item:          
36           print('Item not found in the cart. Nothing removed')37           print('Item not found in the cart. Nothing removed')
37   def modify_item(self, itemToPurchase):  38   def modify_item(self, itemToPurchase):  
38       tmodify_item = False39       tmodify_item = False
39       for i in range(len(self.cart_items)):40       for i in range(len(self.cart_items)):
40           if self.cart_items[i].item_name == itemToPurchase.item_name:41           if self.cart_items[i].item_name == itemToPurchase.item_name:
41               tmodify_item = True42               tmodify_item = True
42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity43               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43               break44               break
44       if not tmodify_item:      45       if not tmodify_item:      
45           print('Item not found in the cart. Nothing modified')  46           print('Item not found in the cart. Nothing modified')  
46   def get_num_items_in_cart(self):47   def get_num_items_in_cart(self):
47       num_items = 048       num_items = 0
48       for item in self.cart_items:49       for item in self.cart_items:
49           num_items = num_items + item.item_quantity50           num_items = num_items + item.item_quantity
50       return num_items51       return num_items
51   def get_cost_of_cart(self):52   def get_cost_of_cart(self):
52       total_cost = 053       total_cost = 0
53       cost = 054       cost = 0
54       for item in self.cart_items:55       for item in self.cart_items:
55           cost = (item.item_quantity * item.item_price)56           cost = (item.item_quantity * item.item_price)
56           total_cost += cost57           total_cost += cost
57       return total_cost58       return total_cost
58   def print_total(self):59   def print_total(self):
59       total_cost = self.get_cost_of_cart()60       total_cost = self.get_cost_of_cart()
60       if (total_cost == 0):61       if (total_cost == 0):
61           print('SHOPPING CART IS EMPTY')62           print('SHOPPING CART IS EMPTY')
62       else:63       else:
63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr64           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
64           print('Number of Items: %d\n' %self.get_num_items_in_cart())65           print('Number of Items: %d\n' %self.get_num_items_in_cart())
65           for item in self.cart_items:66           for item in self.cart_items:
66               total = item.item_price * item.item_quantity67               total = item.item_price * item.item_quantity
67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 68               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
68           print('\nTotal: $%d' %(total_cost))69           print('\nTotal: $%d' %(total_cost))
69   def print_descriptions(self):70   def print_descriptions(self):
70       if len(self.cart_items) == 0:71       if len(self.cart_items) == 0:
71           print('SHOPPING CART IS EMPTY')72           print('SHOPPING CART IS EMPTY')
72       else:  73       else:  
73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr74           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
74           print('\nItem Descriptions')75           print('\nItem Descriptions')
75           for item in self.cart_items:76           for item in self.cart_items:
76               item.print_item_description()  77               item.print_item_description()  
n77def print_menu(new_cart):n78def print_menu(newCart):
78   customer_cart = new_cart79   customer_Cart = newCart
79   menu = ('\nMENU\n'80   menu = ('\nMENU\n'
n80       "a - Add item to cart\n"n81       'a - Add item to cart\n'
81       "r - Remove item from cart\n"82       'r - Remove item from the cart\n'
82       "c - Change item quantity\n"83       'c - Change item quantity\n'
83       "i - Output items' descriptions\n"84       "i - Output item's descriptions\n"
84       "o - Output shopping cart\n"85       'o - Output shopping cart\n'
85       "q - Quit\n")86       'q - Quit\n')
86   command = ''87   command = ''
87   while(command != 'q'):88   while(command != 'q'):
88       print(menu)89       print(menu)
n89       command = input('Choose an option:\n')n90       command = input('Choose an option:')
90       while(command != 'a' and command != 'o' and command != 'i' and command !=91       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
91           command = input('Choose an option:\n')92           command = input('Choose an option:\n')
92       if(command == 'a'):93       if(command == 'a'):
93           print("\nADD ITEM TO CART")94           print("\nADD ITEM TO CART")
94           item_name = input('Enter the item name:\n')95           item_name = input('Enter the item name:\n')
95           item_description = input('Enter the item description:\n')96           item_description = input('Enter the item description:\n')
96           item_price = int(input('Enter the item price:\n'))97           item_price = int(input('Enter the item price:\n'))
97           item_quantity = int(input('Enter the item quantity:\n'))98           item_quantity = int(input('Enter the item quantity:\n'))
98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,99           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
99           customer_Cart.add_item(itemtoPurchase)100           customer_Cart.add_item(itemtoPurchase)
100       elif(command == 'o'):101       elif(command == 'o'):
101           print('\nOUTPUT SHOPPING CART')102           print('\nOUTPUT SHOPPING CART')
n102           customer_cart.print_total()  n103           customer_Cart.print_total()  
103       elif(command == 'i'):104       elif(command == 'i'):
104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')105           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
n105           customer_cart.print_descriptions()n106           customer_Cart.print_descriptions()
106       elif(command == 'r'):107       elif(command == 'r'):
107           print('REMOVE ITEM FROM CART')108           print('REMOVE ITEM FROM CART')
108           itemName = input('Enter the name of the item to remove :\n')109           itemName = input('Enter the name of the item to remove :\n')
n109           customer_cart.remove_item(itemName)n110           customer_Cart.remove_item(itemName)
110       elif(command == 'c'):111       elif(command == 'c'):
111           print('\nCHANGE ITEM QUANTITY')112           print('\nCHANGE ITEM QUANTITY')
112           itemName = input('Enter the name of the item :\n')113           itemName = input('Enter the name of the item :\n')
113           qty = int(input('Enter the new quantity :\n'))114           qty = int(input('Enter the new quantity :\n'))
114           itemToPurchase = ItemToPurchase(itemName,0,qty)115           itemToPurchase = ItemToPurchase(itemName,0,qty)
n115           customer_cart.modify_item(itemToPurchase)n116           customer_Cart.modify_item(itemToPurchase)
116if __name__ == "__main__":117if __name__ == "__main__":
117   customer_name = input("Enter customer's name:\n")118   customer_name = input("Enter customer's name:\n")
118   current_date = input("Enter today's date:\n")119   current_date = input("Enter today's date:\n")
119   print("\nCustomer name: %s" %customer_name)120   print("\nCustomer name: %s" %customer_name)
120   print("Today's date: %s" %current_date)121   print("Today's date: %s" %current_date)
n121   new_cart = ShoppingCart(customer_name, current_date)n122   newCart = ShoppingCart(customer_name, current_date)
122   print_menu(new_cart)123   print_menu(newCart)
123import math124import math
nn125from math import sqrt
124class pt3d():126class pt3d():
125    def __init__(self,x,y,z):127    def __init__(self,x,y,z):
t126        self.x= xt128        self.x = x
127        self.y= y129        self.y = y
128        self.z= z130        self.z = z
129    def __add__(self, other):131    def __add__(self, other):
130        sumX = self.x + other.x132        sumX = self.x + other.x
131        sumY = self.y + other.y133        sumY = self.y + other.y
132        sumZ = self.z + other.z134        sumZ = self.z + other.z
133        return pt3d(sumX, sumY,sumZ)135        return pt3d(sumX, sumY,sumZ)
134    def __sub__(self, other):136    def __sub__(self, other):
135        return math.sqrt((((other.x-self.x)**2)+((other.y-self.y)**2)+((other.z-137        return math.sqrt((((other.x-self.x)**2)+((other.y-self.y)**2)+((other.z-
>self.z)**2)))>self.z)**2)))
136    def __eq__(self, other):138    def __eq__(self, other):
137        equalcheck = True139        equalcheck = True
138        if self.x != other.x and self.y != other.y and self.z != other.z:140        if self.x != other.x and self.y != other.y and self.z != other.z:
139            equalcheck = False141            equalcheck = False
140        else:142        else:
141            equalcheck = True143            equalcheck = True
142        return equalcheck144        return equalcheck
143    def __str__(self):145    def __str__(self):
144        return f'<{self.x},{self.y},{self.z}>'146        return f'<{self.x},{self.y},{self.z}>'
145def main():147def main():
146    a = pt3d(1, 1, 1)148    a = pt3d(1, 1, 1)
147    b = pt3d(2, 2, 2)149    b = pt3d(2, 2, 2)
148    print(a+b)150    print(a+b)
149    print(b-a)151    print(b-a)
150    a==b152    a==b
151    a+a==b153    a+a==b
152    a==b+pt3d(-1,-1,-1)154    a==b+pt3d(-1,-1,-1)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 22

Student ID: 395, P-Value: 4.75e-04

Nearest Neighbor ID: 88

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self, r):n3    def __init__(self, radius):
4        self.radius = r4        self.radius = radius
5    def area(self):5    def area(self):
n6        return math.pi*self.radius**2n6        return math.pi*(self.radius**2)
7    def perimeter(self):7    def perimeter(self):
n8        return 2*self.radius*math.pin8        return 2*math.pi*self.radius
9if __name__=='__main__':9if __name__=='__main__':
n10    x = int(input(""))n10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
n12    print(NewCircle.area())n12    print('{:.5f}'.format(NewCircle.area()))
13    print(NewCircle.perimeter())class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14   def __init__(self, name='none', price=0, quantity=0, description='none'):14   def __init__(self, name='none', price=0, quantity=0, description='none'):
15       self.item_name=name15       self.item_name=name
16       self.item_description=description16       self.item_description=description
17       self.item_price=price17       self.item_price=price
18       self.item_quantity=quantity18       self.item_quantity=quantity
19   def print_item_description(self):19   def print_item_description(self):
20       print('%s: %s' % (self.item_name, self.item_description))20       print('%s: %s' % (self.item_name, self.item_description))
21class ShoppingCart:21class ShoppingCart:
n22   def __init__(self, customer_name = 'none', current_date = 'March 06, 2022', cn22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>art_items = []):>cart_items = []):
23       self.customer_name = customer_name23       self.customer_name = customer_name
24       self.current_date = current_date24       self.current_date = current_date
25       self.cart_items = cart_items  25       self.cart_items = cart_items  
26   def add_item(self, itemToPurchase):26   def add_item(self, itemToPurchase):
27       self.cart_items.append(itemToPurchase)  27       self.cart_items.append(itemToPurchase)  
28   def remove_item(self, itemName):28   def remove_item(self, itemName):
n29       remove_item = Falsen29       tremove_item = False
30       for item in self.cart_items:30       for item in self.cart_items:
31           if item.item_name == itemName:31           if item.item_name == itemName:
32               self.cart_items.remove(item)32               self.cart_items.remove(item)
33               tremove_item = True33               tremove_item = True
34               break34               break
n35       if not remove_item:          n35       if not tremove_item:          
36           print('Item not found in cart. Nothing removed.')36           print('Item not found in the cart. Nothing removed.')
37   def modify_item(self, itemToPurchase):  37   def modify_item(self, itemToPurchase):  
n38       modify_item = Falsen38       tmodify_item = False
39       for i in range(len(self.cart_items)):39       for i in range(len(self.cart_items)):
40           if self.cart_items[i].item_name == itemToPurchase.item_name:40           if self.cart_items[i].item_name == itemToPurchase.item_name:
n41               modify_item = Truen41               tmodify_item = True
42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43               break43               break
n44       if not modify_item:      n44       if not tmodify_item:      
45           print('Item not found in cart. Nothing modified.')  45           print('Item not found in the cart. Nothing modified.')  
46   def get_num_items_in_cart(self):46   def get_num_items_in_cart(self):
47       num_items = 047       num_items = 0
48       for item in self.cart_items:48       for item in self.cart_items:
49           num_items = num_items + item.item_quantity49           num_items = num_items + item.item_quantity
50       return num_items50       return num_items
51   def get_cost_of_cart(self):51   def get_cost_of_cart(self):
52       total_cost = 052       total_cost = 0
53       cost = 053       cost = 0
54       for item in self.cart_items:54       for item in self.cart_items:
55           cost = (item.item_quantity * item.item_price)55           cost = (item.item_quantity * item.item_price)
56           total_cost += cost56           total_cost += cost
57       return total_cost57       return total_cost
58   def print_total(self):58   def print_total(self):
59       total_cost = self.get_cost_of_cart()59       total_cost = self.get_cost_of_cart()
60       if (total_cost == 0):60       if (total_cost == 0):
61           print('SHOPPING CART IS EMPTY')61           print('SHOPPING CART IS EMPTY')
62       else:62       else:
63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
64           print('Number of Items: %d\n' %self.get_num_items_in_cart())64           print('Number of Items: %d\n' %self.get_num_items_in_cart())
65           for item in self.cart_items:65           for item in self.cart_items:
66               total = item.item_price * item.item_quantity66               total = item.item_price * item.item_quantity
67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
68           print('\nTotal: $%d' %(total_cost))68           print('\nTotal: $%d' %(total_cost))
69   def print_descriptions(self):69   def print_descriptions(self):
70       if len(self.cart_items) == 0:70       if len(self.cart_items) == 0:
n71           print('SHOPPING CART IS EMPTY\n')n71           print('SHOPPING CART IS EMPTY')
72       else:  72       else:  
73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
74           print('\nItem Descriptions')74           print('\nItem Descriptions')
75           for item in self.cart_items:75           for item in self.cart_items:
76               item.print_item_description()  76               item.print_item_description()  
77def print_menu(newCart):77def print_menu(newCart):
78   customer_Cart = newCart78   customer_Cart = newCart
79   menu = ('\nMENU\n'79   menu = ('\nMENU\n'
80       'a - Add item to cart\n'80       'a - Add item to cart\n'
81       'r - Remove item from cart\n'81       'r - Remove item from cart\n'
82       'c - Change item quantity\n'82       'c - Change item quantity\n'
83       "i - Output items' descriptions\n"83       "i - Output items' descriptions\n"
84       'o - Output shopping cart\n'84       'o - Output shopping cart\n'
85       'q - Quit\n')85       'q - Quit\n')
86   command = ''86   command = ''
87   while(command != 'q'):87   while(command != 'q'):
88       print(menu)88       print(menu)
89       command = input('Choose an option:\n')89       command = input('Choose an option:\n')
90       while(command != 'a' and command != 'o' and command != 'i' and command !=90       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
91           command = input('Choose an option:\n')91           command = input('Choose an option:\n')
92       if(command == 'a'):92       if(command == 'a'):
93           print("\nADD ITEM TO CART")93           print("\nADD ITEM TO CART")
94           item_name = input('Enter the item name:\n')94           item_name = input('Enter the item name:\n')
95           item_description = input('Enter the item description:\n')95           item_description = input('Enter the item description:\n')
96           item_price = int(input('Enter the item price:\n'))96           item_price = int(input('Enter the item price:\n'))
97           item_quantity = int(input('Enter the item quantity:\n'))97           item_quantity = int(input('Enter the item quantity:\n'))
98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
99           customer_Cart.add_item(itemtoPurchase)99           customer_Cart.add_item(itemtoPurchase)
100       elif(command == 'o'):100       elif(command == 'o'):
n101           print('OUTPUT SHOPPING CART')n101           print('\nOUTPUT SHOPPING CART')
102           customer_Cart.print_total()  102           customer_Cart.print_total()  
103       elif(command == 'i'):103       elif(command == 'i'):
104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
105           customer_Cart.print_descriptions()105           customer_Cart.print_descriptions()
106       elif(command == 'r'):106       elif(command == 'r'):
107           print('REMOVE ITEM FROM CART')107           print('REMOVE ITEM FROM CART')
n108           itemName = input('Enter name of item to remove:\n')n108           itemName = input('Enter name of item to remove :\n')
109           customer_Cart.remove_item(itemName)109           customer_Cart.remove_item(itemName)
110       elif(command == 'c'):110       elif(command == 'c'):
111           print('\nCHANGE ITEM QUANTITY')111           print('\nCHANGE ITEM QUANTITY')
n112           itemName = input('Enter the item name:\n')n112           itemName = input('Enter name of item :\n')
113           qty = int(input('Enter the new quantity:\n'))113           qty = int(input('Enter the new quantity :\n'))
114           itemToPurchase = ItemToPurchase(itemName,0,qty)114           itemToPurchase = ItemToPurchase(itemName,0,qty)
115           customer_Cart.modify_item(itemToPurchase)115           customer_Cart.modify_item(itemToPurchase)
116if __name__ == "__main__":116if __name__ == "__main__":
117   customer_name = input("Enter customer's name:\n")117   customer_name = input("Enter customer's name:\n")
118   current_date = input("Enter today's date:\n")118   current_date = input("Enter today's date:\n")
119   print("\nCustomer name: %s" %customer_name)119   print("\nCustomer name: %s" %customer_name)
120   print("Today's date: %s" %current_date)120   print("Today's date: %s" %current_date)
121   newCart = ShoppingCart(customer_name, current_date)121   newCart = ShoppingCart(customer_name, current_date)
n122   print_menu(newCart)  from math import sqrtn122   print_menu(newCart)from math import sqrt
123class pt3d:123class pt3d:
124    def __init__(self, x, y, z):124    def __init__(self, x, y, z):
125        self.x = x125        self.x = x
126        self.y = y126        self.y = y
127        self.z = z127        self.z = z
128    def __add__(self, other):128    def __add__(self, other):
129        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)129        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
130    def __sub__(self, other):130    def __sub__(self, other):
131        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot131        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>her.z)**2)>her.z)**2)
132    def __eq__(self, other):132    def __eq__(self, other):
t133        return self.x == other.x & self.y == other.y & self.z == other.zt133        return self.x == other.x and self.y == other.y and self.z == other.z
134    def __str__(self):134    def __str__(self):
135        return '<{}, {}, {}>'.format(self.x, self.y, self.z)135        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
136p1 = pt3d(1, 1, 1)136p1 = pt3d(1, 1, 1)
137p2 = pt3d(2, 2, 2)137p2 = pt3d(2, 2, 2)
138print(p1 + p2)138print(p1 + p2)
139print(p1 - p2)139print(p1 - p2)
140print(p1 == p2)140print(p1 == p2)
141print(p1+p1 == p2)141print(p1+p1 == p2)
142print(p1==p2+pt3d(-1, -1, -1))142print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 23

Student ID: 192, P-Value: 5.56e-04

Nearest Neighbor ID: 79

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle():n2class Circle :
3    def __init__(self, radius):3    def __init__(self,radius):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
6        return math.pi*self.radius*self.radius6        return math.pi*self.radius*self.radius
7    def perimeter(self):7    def perimeter(self):
8        return 2*math.pi*self.radius8        return 2*math.pi*self.radius
n9if __name__=='__main__':n9if __name__ == '__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des14    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des
>cription = 'none'):>cription = 'none'):
15        self.item_name = item_name15        self.item_name = item_name
16        self.item_price = item_price16        self.item_price = item_price
17        self.item_quantity = item_quantity17        self.item_quantity = item_quantity
18        self.item_description = item_description18        self.item_description = item_description
19    def print_item_cost(self):19    def print_item_cost(self):
n20        string = '\n{} {} @ ${} = ${}'.format(self.item_name, self.item_quantityn20        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, 
>, self.item_price,(self.item_quantity * self.item_price))>self.item_price,
21        (self.item_quantity * self.item_price))
21        cost = self.item_quantity * self.item_price22        cost = self.item_quantity * self.item_price
22        return string, cost23        return string, cost
23    def print_item_description(self):24    def print_item_description(self):
24        string = '{}: {}, %d oz.'.format(self.item_name, self.item_description, 25        string = '{}: {}, %d oz.'.format(self.item_name, self.item_description, 
>self.item_quantity)>self.item_quantity)
25        print(string)26        print(string)
26        return string27        return string
27class ShoppingCart:28class ShoppingCart:
28    def __init__(self, customer_name = 'none', current_date = 'January 1, 2016',29    def __init__(self, customer_name = 'none', current_date = 'January 1, 2016',
> cart_items = []):> cart_items = []):
29        self.customer_name = customer_name30        self.customer_name = customer_name
30        self.current_date = current_date31        self.current_date = current_date
31        self.cart_items = cart_items32        self.cart_items = cart_items
32    def add_item(self):33    def add_item(self):
33        print('ADD ITEM TO CART')34        print('ADD ITEM TO CART')
n34        item_name = str(input('Enter the item name:\n'))n35        item_name = str(input('Enter the item name:'))
36        print()
35        item_description = str(input('Enter the item description:\n'))37        item_description = str(input('Enter the item description:'))
38        print()
36        item_price = int(input('Enter the item price:\n'))39        item_price = int(input('Enter the item price:'))
40        print()
37        item_quantity = int(input('Enter the item quantity:\n'))41        item_quantity = int(input('Enter the item quantity:'))
42        print()
38        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti43        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti
>ty, item_description))>ty, item_description))
39    def remove_item(self):44    def remove_item(self):
40        print('REMOVE ITEM FROM CART')45        print('REMOVE ITEM FROM CART')
n41        string = str(input('Enter name of item to remove:\n'))n46        string = str(input('Enter name of item to remove:'))
47        print()
42        i = 048        i = 0
43        for item in self.cart_items:49        for item in self.cart_items:
44            if(item.item_name == string):               50            if(item.item_name == string):               
45                del self.cart_items[i]51                del self.cart_items[i]
46                flag=True52                flag=True
47                break53                break
48            else:54            else:
49                flag=False55                flag=False
50            i += 156            i += 1
51        if(flag==False):57        if(flag==False):
52            print('Item not found in cart. Nothing removed.')58            print('Item not found in cart. Nothing removed.')
53    def modify_item(self):59    def modify_item(self):
54        print('CHANGE ITEM QUANTITY')60        print('CHANGE ITEM QUANTITY')
55        name = str(input('Enter the item name:'))61        name = str(input('Enter the item name:'))
56        print()62        print()
57        for item in self.cart_items:63        for item in self.cart_items:
58            if(item.item_name == name):64            if(item.item_name == name):
59                quantity = int(input('Enter the new quantity:'))65                quantity = int(input('Enter the new quantity:'))
nn66                print()
60                item.item_quantity = quantity67                item.item_quantity = quantity
61                flag=True68                flag=True
nn69                break
62            else:70            else:
63                flag=False71                flag=False
64        if(flag==False):72        if(flag==False):
65            print('Item not found in cart. Nothing modified.')73            print('Item not found in cart. Nothing modified.')
66        print()74        print()
67    def get_num_items_in_cart(self):75    def get_num_items_in_cart(self):
68        num_items=076        num_items=0
69        for item in self.cart_items:77        for item in self.cart_items:
70            num_items= num_items+item.item_quantity78            num_items= num_items+item.item_quantity
71        return num_items79        return num_items
72    def get_cost_of_cart(self):80    def get_cost_of_cart(self):
73        total_cost = 081        total_cost = 0
74        cost = 082        cost = 0
75        for item in self.cart_items:83        for item in self.cart_items:
76            cost = (item.item_quantity * item.item_price)84            cost = (item.item_quantity * item.item_price)
77            total_cost += cost85            total_cost += cost
78        return total_cost86        return total_cost
79    def print_total(self):87    def print_total(self):
80        total_cost = self.get_cost_of_cart()88        total_cost = self.get_cost_of_cart()
81        if (total_cost == 0):89        if (total_cost == 0):
82            print('SHOPPING CART IS EMPTY')90            print('SHOPPING CART IS EMPTY')
83        else:91        else:
84            self.output_cart()92            self.output_cart()
85    def print_descriptions(self):93    def print_descriptions(self):
86        print('OUTPUT ITEMS\' DESCRIPTIONS')94        print('OUTPUT ITEMS\' DESCRIPTIONS')
87        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current95        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date),end='\n')>_date),end='\n')
88        print('\nItem Descriptions')96        print('\nItem Descriptions')
89        for item in self.cart_items:97        for item in self.cart_items:
90            print('{}: {}'.format(item.item_name, item.item_description))98            print('{}: {}'.format(item.item_name, item.item_description))
91    def output_cart(self):99    def output_cart(self):
92        print('OUTPUT SHOPPING CART')100        print('OUTPUT SHOPPING CART')
93        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current101        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date))      >_date))      
94        print('Number of Items:', self.get_num_items_in_cart())102        print('Number of Items:', self.get_num_items_in_cart())
nn103        print()
95        tc = 0104        tc = 0
96        for item in self.cart_items:105        for item in self.cart_items:
97            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,106            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,
98              item.item_price, (item.item_quantity * item.item_price)))107              item.item_price, (item.item_quantity * item.item_price)))
99            tc += (item.item_quantity * item.item_price)108            tc += (item.item_quantity * item.item_price)
100        if len(self.cart_items) == 0:109        if len(self.cart_items) == 0:
n101            print('\nSHOPPING CART IS EMPTY')n110            print('SHOPPING CART IS EMPTY')
102        print()111        print()
103        print('Total: ${}'.format(tc))112        print('Total: ${}'.format(tc))
104def print_menu(customer_Cart):113def print_menu(customer_Cart):
105    menu = ('\nMENU\n'114    menu = ('\nMENU\n'
106    'a - Add item to cart\n'115    'a - Add item to cart\n'
107    'r - Remove item from cart\n'116    'r - Remove item from cart\n'
108    'c - Change item quantity\n'117    'c - Change item quantity\n'
109    'i - Output items\' descriptions\n'118    'i - Output items\' descriptions\n'
110    'o - Output shopping cart\n'119    'o - Output shopping cart\n'
111    'q - Quit\n')120    'q - Quit\n')
112    command = ''121    command = ''
113    while(command != 'q'):122    while(command != 'q'):
114        print(menu)123        print(menu)
n115        command = input('Choose an option:\n')n124        command = input('Choose an option:')
125        print()
116        while(command != 'a' and command != 'o' and command != 'i' and command !126        while(command != 'a' and command != 'o' and command != 'i' and command !
>= 'r'and command != 'c' and command != 'q'):>= 'r'
127              and command != 'c' and command != 'q'):
117            command = input('Choose an option:\n')128            command = input('Choose an option:')
129            print()
118        if(command == 'a'):130        if(command == 'a'):
119            customer_Cart.add_item()131            customer_Cart.add_item()
120        if(command == 'o'):132        if(command == 'o'):
121            customer_Cart.output_cart()133            customer_Cart.output_cart()
122        if(command == 'i'):134        if(command == 'i'):
123            customer_Cart.print_descriptions()135            customer_Cart.print_descriptions()
124        if(command == 'r'):136        if(command == 'r'):
125            customer_Cart.remove_item()137            customer_Cart.remove_item()
126        if(command == 'c'):138        if(command == 'c'):
127            customer_Cart.modify_item()139            customer_Cart.modify_item()
128def main():140def main():
129    customer_name = str(input('Enter customer\'s name:'))141    customer_name = str(input('Enter customer\'s name:'))
130    print()142    print()
131    current_date = str(input('Enter today\'s date:'))143    current_date = str(input('Enter today\'s date:'))
n132    print()n144    print('\n')
133    print()
134    print('Customer name:', customer_name)145    print('Customer name:', customer_name, end='\n')
135    print('Today\'s date:', current_date)146    print('Today\'s date:', current_date, end='\n')
136    x = ShoppingCart(customer_name, current_date)147    newCart = ShoppingCart(customer_name, current_date)
137    print_menu(x)148    print_menu(newCart)
138if __name__ == '__main__':149if __name__ == '__main__':
139    main()import math150    main()import math
140class pt3d:151class pt3d:
141    def __init__(self,x=0,y=0,z=0):152    def __init__(self,x=0,y=0,z=0):
142        self.x= x153        self.x= x
143        self.y= y154        self.y= y
144        self.z= z155        self.z= z
145    def __add__(self, other):156    def __add__(self, other):
146        x = self.x + other.x157        x = self.x + other.x
147        y = self.y + other.y158        y = self.y + other.y
148        z = self.z + other.z159        z = self.z + other.z
149        return pt3d(x, y,z)160        return pt3d(x, y,z)
150    def __sub__(self, other):161    def __sub__(self, other):
151        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 162        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>2)+math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
152    def __eq__(self, other):163    def __eq__(self, other):
153        return other.x==self.x and other.y==self.y and other.z==self.z164        return other.x==self.x and other.y==self.y and other.z==self.z
154    def __str__(self):165    def __str__(self):
155        return "<{0},{1},{2}>".format(self.x, self.y, self.z)166        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
156if __name__ == '__main__':167if __name__ == '__main__':
157    p1 = pt3d(1, 1, 1)168    p1 = pt3d(1, 1, 1)
158    p2 = pt3d(2, 2, 2)169    p2 = pt3d(2, 2, 2)
159    print(p1+p2)170    print(p1+p2)
160    print(p1-p2)171    print(p1-p2)
161    print(p1==p2)172    print(p1==p2)
162    print(p1+p1==p2)173    print(p1+p1==p2)
t163    print(p1==p2+pt3d(-1,-1,-1))t
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 24

Student ID: 79, P-Value: 5.56e-04

Nearest Neighbor ID: 192

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle :n2class Circle():
3    def __init__(self,radius):3    def __init__(self, radius):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
6        return math.pi*self.radius*self.radius6        return math.pi*self.radius*self.radius
7    def perimeter(self):7    def perimeter(self):
8        return 2*math.pi*self.radius8        return 2*math.pi*self.radius
n9if __name__ == '__main__':n9if __name__=='__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des14    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des
>cription = 'none'):>cription = 'none'):
15        self.item_name = item_name15        self.item_name = item_name
16        self.item_price = item_price16        self.item_price = item_price
17        self.item_quantity = item_quantity17        self.item_quantity = item_quantity
18        self.item_description = item_description18        self.item_description = item_description
19    def print_item_cost(self):19    def print_item_cost(self):
n20        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, n20        string = '\n{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity
>self.item_price,>, self.item_price,(self.item_quantity * self.item_price))
21        (self.item_quantity * self.item_price))
22        cost = self.item_quantity * self.item_price21        cost = self.item_quantity * self.item_price
23        return string, cost22        return string, cost
24    def print_item_description(self):23    def print_item_description(self):
25        string = '{}: {}, %d oz.'.format(self.item_name, self.item_description, 24        string = '{}: {}, %d oz.'.format(self.item_name, self.item_description, 
>self.item_quantity)>self.item_quantity)
26        print(string)25        print(string)
27        return string26        return string
28class ShoppingCart:27class ShoppingCart:
29    def __init__(self, customer_name = 'none', current_date = 'January 1, 2016',28    def __init__(self, customer_name = 'none', current_date = 'January 1, 2016',
> cart_items = []):> cart_items = []):
30        self.customer_name = customer_name29        self.customer_name = customer_name
31        self.current_date = current_date30        self.current_date = current_date
32        self.cart_items = cart_items31        self.cart_items = cart_items
33    def add_item(self):32    def add_item(self):
34        print('ADD ITEM TO CART')33        print('ADD ITEM TO CART')
n35        item_name = str(input('Enter the item name:'))n34        item_name = str(input('Enter the item name:\n'))
36        print()
37        item_description = str(input('Enter the item description:'))35        item_description = str(input('Enter the item description:\n'))
38        print()
39        item_price = int(input('Enter the item price:'))36        item_price = int(input('Enter the item price:\n'))
40        print()
41        item_quantity = int(input('Enter the item quantity:'))37        item_quantity = int(input('Enter the item quantity:\n'))
42        print()
43        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti38        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti
>ty, item_description))>ty, item_description))
44    def remove_item(self):39    def remove_item(self):
45        print('REMOVE ITEM FROM CART')40        print('REMOVE ITEM FROM CART')
n46        string = str(input('Enter name of item to remove:'))n41        string = str(input('Enter name of item to remove:\n'))
47        print()
48        i = 042        i = 0
49        for item in self.cart_items:43        for item in self.cart_items:
50            if(item.item_name == string):               44            if(item.item_name == string):               
51                del self.cart_items[i]45                del self.cart_items[i]
52                flag=True46                flag=True
53                break47                break
54            else:48            else:
55                flag=False49                flag=False
56            i += 150            i += 1
57        if(flag==False):51        if(flag==False):
58            print('Item not found in cart. Nothing removed.')52            print('Item not found in cart. Nothing removed.')
59    def modify_item(self):53    def modify_item(self):
60        print('CHANGE ITEM QUANTITY')54        print('CHANGE ITEM QUANTITY')
61        name = str(input('Enter the item name:'))55        name = str(input('Enter the item name:'))
62        print()56        print()
63        for item in self.cart_items:57        for item in self.cart_items:
64            if(item.item_name == name):58            if(item.item_name == name):
65                quantity = int(input('Enter the new quantity:'))59                quantity = int(input('Enter the new quantity:'))
n66                print()n
67                item.item_quantity = quantity60                item.item_quantity = quantity
68                flag=True61                flag=True
n69                breakn
70            else:62            else:
71                flag=False63                flag=False
72        if(flag==False):64        if(flag==False):
73            print('Item not found in cart. Nothing modified.')65            print('Item not found in cart. Nothing modified.')
74        print()66        print()
75    def get_num_items_in_cart(self):67    def get_num_items_in_cart(self):
76        num_items=068        num_items=0
77        for item in self.cart_items:69        for item in self.cart_items:
78            num_items= num_items+item.item_quantity70            num_items= num_items+item.item_quantity
79        return num_items71        return num_items
80    def get_cost_of_cart(self):72    def get_cost_of_cart(self):
81        total_cost = 073        total_cost = 0
82        cost = 074        cost = 0
83        for item in self.cart_items:75        for item in self.cart_items:
84            cost = (item.item_quantity * item.item_price)76            cost = (item.item_quantity * item.item_price)
85            total_cost += cost77            total_cost += cost
86        return total_cost78        return total_cost
87    def print_total(self):79    def print_total(self):
88        total_cost = self.get_cost_of_cart()80        total_cost = self.get_cost_of_cart()
89        if (total_cost == 0):81        if (total_cost == 0):
90            print('SHOPPING CART IS EMPTY')82            print('SHOPPING CART IS EMPTY')
91        else:83        else:
92            self.output_cart()84            self.output_cart()
93    def print_descriptions(self):85    def print_descriptions(self):
94        print('OUTPUT ITEMS\' DESCRIPTIONS')86        print('OUTPUT ITEMS\' DESCRIPTIONS')
95        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current87        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date),end='\n')>_date),end='\n')
96        print('\nItem Descriptions')88        print('\nItem Descriptions')
97        for item in self.cart_items:89        for item in self.cart_items:
98            print('{}: {}'.format(item.item_name, item.item_description))90            print('{}: {}'.format(item.item_name, item.item_description))
99    def output_cart(self):91    def output_cart(self):
100        print('OUTPUT SHOPPING CART')92        print('OUTPUT SHOPPING CART')
101        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current93        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date))      >_date))      
102        print('Number of Items:', self.get_num_items_in_cart())94        print('Number of Items:', self.get_num_items_in_cart())
n103        print()n
104        tc = 095        tc = 0
105        for item in self.cart_items:96        for item in self.cart_items:
106            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,97            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,
107              item.item_price, (item.item_quantity * item.item_price)))98              item.item_price, (item.item_quantity * item.item_price)))
108            tc += (item.item_quantity * item.item_price)99            tc += (item.item_quantity * item.item_price)
109        if len(self.cart_items) == 0:100        if len(self.cart_items) == 0:
n110            print('SHOPPING CART IS EMPTY')n101            print('\nSHOPPING CART IS EMPTY')
111        print()102        print()
112        print('Total: ${}'.format(tc))103        print('Total: ${}'.format(tc))
113def print_menu(customer_Cart):104def print_menu(customer_Cart):
114    menu = ('\nMENU\n'105    menu = ('\nMENU\n'
115    'a - Add item to cart\n'106    'a - Add item to cart\n'
116    'r - Remove item from cart\n'107    'r - Remove item from cart\n'
117    'c - Change item quantity\n'108    'c - Change item quantity\n'
118    'i - Output items\' descriptions\n'109    'i - Output items\' descriptions\n'
119    'o - Output shopping cart\n'110    'o - Output shopping cart\n'
120    'q - Quit\n')111    'q - Quit\n')
121    command = ''112    command = ''
122    while(command != 'q'):113    while(command != 'q'):
123        print(menu)114        print(menu)
n124        command = input('Choose an option:')n115        command = input('Choose an option:\n')
125        print()
126        while(command != 'a' and command != 'o' and command != 'i' and command !116        while(command != 'a' and command != 'o' and command != 'i' and command !
>= 'r'>= 'r'and command != 'c' and command != 'q'):
127              and command != 'c' and command != 'q'):
128            command = input('Choose an option:')117            command = input('Choose an option:\n')
129            print()
130        if(command == 'a'):118        if(command == 'a'):
131            customer_Cart.add_item()119            customer_Cart.add_item()
132        if(command == 'o'):120        if(command == 'o'):
133            customer_Cart.output_cart()121            customer_Cart.output_cart()
134        if(command == 'i'):122        if(command == 'i'):
135            customer_Cart.print_descriptions()123            customer_Cart.print_descriptions()
136        if(command == 'r'):124        if(command == 'r'):
137            customer_Cart.remove_item()125            customer_Cart.remove_item()
138        if(command == 'c'):126        if(command == 'c'):
139            customer_Cart.modify_item()127            customer_Cart.modify_item()
140def main():128def main():
141    customer_name = str(input('Enter customer\'s name:'))129    customer_name = str(input('Enter customer\'s name:'))
142    print()130    print()
143    current_date = str(input('Enter today\'s date:'))131    current_date = str(input('Enter today\'s date:'))
n144    print('\n')n132    print()
133    print()
145    print('Customer name:', customer_name, end='\n')134    print('Customer name:', customer_name)
146    print('Today\'s date:', current_date, end='\n')135    print('Today\'s date:', current_date)
147    newCart = ShoppingCart(customer_name, current_date)136    x = ShoppingCart(customer_name, current_date)
148    print_menu(newCart)137    print_menu(x)
149if __name__ == '__main__':138if __name__ == '__main__':
150    main()import math139    main()import math
151class pt3d:140class pt3d:
152    def __init__(self,x=0,y=0,z=0):141    def __init__(self,x=0,y=0,z=0):
153        self.x= x142        self.x= x
154        self.y= y143        self.y= y
155        self.z= z144        self.z= z
156    def __add__(self, other):145    def __add__(self, other):
157        x = self.x + other.x146        x = self.x + other.x
158        y = self.y + other.y147        y = self.y + other.y
159        z = self.z + other.z148        z = self.z + other.z
160        return pt3d(x, y,z)149        return pt3d(x, y,z)
161    def __sub__(self, other):150    def __sub__(self, other):
162        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 151        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>2)+math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
163    def __eq__(self, other):152    def __eq__(self, other):
164        return other.x==self.x and other.y==self.y and other.z==self.z153        return other.x==self.x and other.y==self.y and other.z==self.z
165    def __str__(self):154    def __str__(self):
166        return "<{0},{1},{2}>".format(self.x, self.y, self.z)155        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
167if __name__ == '__main__':156if __name__ == '__main__':
168    p1 = pt3d(1, 1, 1)157    p1 = pt3d(1, 1, 1)
169    p2 = pt3d(2, 2, 2)158    p2 = pt3d(2, 2, 2)
170    print(p1+p2)159    print(p1+p2)
171    print(p1-p2)160    print(p1-p2)
172    print(p1==p2)161    print(p1==p2)
173    print(p1+p1==p2)162    print(p1+p1==p2)
tt163    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 25

Student ID: 296, P-Value: 7.57e-04

Nearest Neighbor ID: 478

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle:n2class Circle :
3    def __init__(self, radius):3    def __init__(self,radius):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
n6        return math.pi * self.radius * self.radiusn6        return math.pi*self.radius*self.radius
7    def perimeter(self):7    def perimeter(self):
n8        return 2 * math.pi * self.radiusn8        return 2*math.pi*self.radius
9small_circle = Circle(2)9if __name__ == '__main__':
10print('Area of the circle:{:.3f}'.format(small_circle.area()))class ItemToPurcha10    x = int(input())
>se: 
11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))
14class ItemToPurchase:
11   def __init__(self, name='none', price=0, quantity=0, description='none'):15   def __init__(self, name='none', price=0, quantity=0, description='none'):
12       self.item_name=name16       self.item_name=name
13       self.item_description=description17       self.item_description=description
14       self.item_price=price18       self.item_price=price
15       self.item_quantity=quantity19       self.item_quantity=quantity
16   def print_item_description(self):20   def print_item_description(self):
17       print('%s: %s' % (self.item_name, self.item_description))21       print('%s: %s' % (self.item_name, self.item_description))
18class ShoppingCart:22class ShoppingCart:
19   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 23   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
20       self.customer_name = customer_name24       self.customer_name = customer_name
21       self.current_date = current_date25       self.current_date = current_date
22       self.cart_items = cart_items  26       self.cart_items = cart_items  
23   def add_item(self, itemToPurchase):27   def add_item(self, itemToPurchase):
n24       self.cart_items.append(itemToPurchase)    n28       self.cart_items.append(itemToPurchase)  
25   def remove_item(self, itemName):29   def remove_item(self, itemName):
26       tremove_item = False30       tremove_item = False
27       for item in self.cart_items:31       for item in self.cart_items:
28           if item.item_name == itemName:32           if item.item_name == itemName:
29               self.cart_items.remove(item)33               self.cart_items.remove(item)
30               tremove_item = True34               tremove_item = True
31               break35               break
32       if not tremove_item:          36       if not tremove_item:          
n33           print('Item not found in the cart. Nothing removed')          n37           print('Item not found in the cart. Nothing removed')
34   def modify_item(self, itemToPurchase):  38   def modify_item(self, itemToPurchase):  
35       tmodify_item = False39       tmodify_item = False
36       for i in range(len(self.cart_items)):40       for i in range(len(self.cart_items)):
37           if self.cart_items[i].item_name == itemToPurchase.item_name:41           if self.cart_items[i].item_name == itemToPurchase.item_name:
38               tmodify_item = True42               tmodify_item = True
39               self.cart_items[i].item_quantity = itemToPurchase.item_quantity43               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
40               break44               break
41       if not tmodify_item:      45       if not tmodify_item:      
n42           print('Item not found in the cart. Nothing modified')     n46           print('Item not found in the cart. Nothing modified')  
43   def get_num_items_in_cart(self):47   def get_num_items_in_cart(self):
44       num_items = 048       num_items = 0
45       for item in self.cart_items:49       for item in self.cart_items:
46           num_items = num_items + item.item_quantity50           num_items = num_items + item.item_quantity
47       return num_items51       return num_items
48   def get_cost_of_cart(self):52   def get_cost_of_cart(self):
49       total_cost = 053       total_cost = 0
50       cost = 054       cost = 0
51       for item in self.cart_items:55       for item in self.cart_items:
52           cost = (item.item_quantity * item.item_price)56           cost = (item.item_quantity * item.item_price)
53           total_cost += cost57           total_cost += cost
n54       return total_cost       n58       return total_cost
55   def print_total(self):59   def print_total(self):
56       total_cost = self.get_cost_of_cart()60       total_cost = self.get_cost_of_cart()
57       if (total_cost == 0):61       if (total_cost == 0):
58           print('SHOPPING CART IS EMPTY')62           print('SHOPPING CART IS EMPTY')
59       else:63       else:
60           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr64           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
61           print('Number of Items: %d\n' %self.get_num_items_in_cart())65           print('Number of Items: %d\n' %self.get_num_items_in_cart())
62           for item in self.cart_items:66           for item in self.cart_items:
63               total = item.item_price * item.item_quantity67               total = item.item_price * item.item_quantity
64               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 68               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
n65           print('\nTotal: $%d' %(total_cost))     n69           print('\nTotal: $%d' %(total_cost))
66   def print_descriptions(self):70   def print_descriptions(self):
67       if len(self.cart_items) == 0:71       if len(self.cart_items) == 0:
68           print('SHOPPING CART IS EMPTY')72           print('SHOPPING CART IS EMPTY')
69       else:  73       else:  
70           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr74           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
71           print('\nItem Descriptions')75           print('\nItem Descriptions')
72           for item in self.cart_items:76           for item in self.cart_items:
n73               item.print_item_description()          n77               item.print_item_description()  
74def print_menu(newCart):78def print_menu(newCart):
75   customer_Cart = newCart79   customer_Cart = newCart
76   menu = ('\nMENU\n'80   menu = ('\nMENU\n'
77       'a - Add item to cart\n'81       'a - Add item to cart\n'
n78       'r - Remove item from the cart\n'n82       'r - Remove item from cart\n'
79       'c - Change item quantity\n'83       'c - Change item quantity\n'
n80       "i - Output item's descriptions\n"n84       "i - Output items' descriptions\n"
81       'o - Output shopping cart\n'85       'o - Output shopping cart\n'
82       'q - Quit\n')86       'q - Quit\n')
83   command = ''87   command = ''
84   while(command != 'q'):88   while(command != 'q'):
85       print(menu)89       print(menu)
n86       command = input('Choose an option:')n90       command = input('Choose an option:\n')
87       while(command != 'a' and command != 'o' and command != 'i' and command !=91       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
88           command = input('Choose an option:\n')92           command = input('Choose an option:\n')
89       if(command == 'a'):93       if(command == 'a'):
90           print("\nADD ITEM TO CART")94           print("\nADD ITEM TO CART")
91           item_name = input('Enter the item name:\n')95           item_name = input('Enter the item name:\n')
92           item_description = input('Enter the item description:\n')96           item_description = input('Enter the item description:\n')
93           item_price = int(input('Enter the item price:\n'))97           item_price = int(input('Enter the item price:\n'))
94           item_quantity = int(input('Enter the item quantity:\n'))98           item_quantity = int(input('Enter the item quantity:\n'))
95           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,99           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
96           customer_Cart.add_item(itemtoPurchase)100           customer_Cart.add_item(itemtoPurchase)
97       elif(command == 'o'):101       elif(command == 'o'):
98           print('\nOUTPUT SHOPPING CART')102           print('\nOUTPUT SHOPPING CART')
99           customer_Cart.print_total()  103           customer_Cart.print_total()  
100       elif(command == 'i'):104       elif(command == 'i'):
101           print('\nOUTPUT ITEMS\' DESCRIPTIONS')105           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
102           customer_Cart.print_descriptions()106           customer_Cart.print_descriptions()
103       elif(command == 'r'):107       elif(command == 'r'):
104           print('REMOVE ITEM FROM CART')108           print('REMOVE ITEM FROM CART')
105           itemName = input('Enter the name of the item to remove :\n')109           itemName = input('Enter the name of the item to remove :\n')
106           customer_Cart.remove_item(itemName)110           customer_Cart.remove_item(itemName)
107       elif(command == 'c'):111       elif(command == 'c'):
108           print('\nCHANGE ITEM QUANTITY')112           print('\nCHANGE ITEM QUANTITY')
109           itemName = input('Enter the name of the item :\n')113           itemName = input('Enter the name of the item :\n')
110           qty = int(input('Enter the new quantity :\n'))114           qty = int(input('Enter the new quantity :\n'))
111           itemToPurchase = ItemToPurchase(itemName,0,qty)115           itemToPurchase = ItemToPurchase(itemName,0,qty)
112           customer_Cart.modify_item(itemToPurchase)116           customer_Cart.modify_item(itemToPurchase)
113if __name__ == "__main__":117if __name__ == "__main__":
114   customer_name = input("Enter customer's name:\n")118   customer_name = input("Enter customer's name:\n")
115   current_date = input("Enter today's date:\n")119   current_date = input("Enter today's date:\n")
116   print("\nCustomer name: %s" %customer_name)120   print("\nCustomer name: %s" %customer_name)
117   print("Today's date: %s" %current_date)121   print("Today's date: %s" %current_date)
118   newCart = ShoppingCart(customer_name, current_date)122   newCart = ShoppingCart(customer_name, current_date)
119   print_menu(newCart)import math123   print_menu(newCart)import math
120class pt3d:124class pt3d:
t121    def __init__(self,x,y,z):t125    def __init__(self,x=0,y=0,z=0):
122        self.x= x126        self.x= x
123        self.y= y127        self.y= y
124        self.z= z128        self.z= z
125    def __add__(self, other):129    def __add__(self, other):
126        x = self.x + other.x130        x = self.x + other.x
127        y = self.y + other.y131        y = self.y + other.y
128        z = self.z + other.z132        z = self.z + other.z
129        return pt3d(x, y,z)133        return pt3d(x, y,z)
130    def __sub__(self, other):134    def __sub__(self, other):
131        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 135        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>2)+math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
132    def __eq__(self, other):136    def __eq__(self, other):
133        return other.x==self.x and other.y==self.y and other.z==self.z137        return other.x==self.x and other.y==self.y and other.z==self.z
134    def __str__(self):138    def __str__(self):
135        return "<{0},{1},{2}>".format(self.x, self.y, self.z)139        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
136if __name__ == '__main__':140if __name__ == '__main__':
137    p1 = pt3d(1, 1, 1)141    p1 = pt3d(1, 1, 1)
138    p2 = pt3d(2, 2, 2)142    p2 = pt3d(2, 2, 2)
139    print(p1+p2)143    print(p1+p2)
140    print(p1-p2)144    print(p1-p2)
141    print(p1==p2)145    print(p1==p2)
142    print(p1+p1==p2)146    print(p1+p1==p2)
143    print(p1==p2+pt3d(-1,-1,-1))147    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 26

Student ID: 30, P-Value: 9.60e-04

Nearest Neighbor ID: 192

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle:n2class Circle():
3    def __init__(self,radius):3    def __init__(self, radius):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
6        return math.pi*self.radius*self.radius6        return math.pi*self.radius*self.radius
7    def perimeter(self):7    def perimeter(self):
8        return 2*math.pi*self.radius8        return 2*math.pi*self.radius
9if __name__=='__main__':9if __name__=='__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des14    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des
>cription = 'none'):>cription = 'none'):
15        self.item_name = item_name15        self.item_name = item_name
16        self.item_price = item_price16        self.item_price = item_price
17        self.item_quantity = item_quantity17        self.item_quantity = item_quantity
18        self.item_description = item_description18        self.item_description = item_description
19    def print_item_cost(self):19    def print_item_cost(self):
n20        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, n20        string = '\n{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity
>self.item_price,>, self.item_price,(self.item_quantity * self.item_price))
21        (self.item_quantity * self.item_price))
22        cost = self.item_quantity * self.item_price21        cost = self.item_quantity * self.item_price
23        return string, cost22        return string, cost
24    def print_item_description(self):23    def print_item_description(self):
25        string = '{}: {}, %d oz.'.format(self.item_name, self.item_description, 24        string = '{}: {}, %d oz.'.format(self.item_name, self.item_description, 
>self.item_quantity)>self.item_quantity)
26        print(string)25        print(string)
27        return string26        return string
28class ShoppingCart:27class ShoppingCart:
29    def __init__(self, customer_name = 'none', current_date = 'January 1, 2016',28    def __init__(self, customer_name = 'none', current_date = 'January 1, 2016',
> cart_items = []):> cart_items = []):
30        self.customer_name = customer_name29        self.customer_name = customer_name
31        self.current_date = current_date30        self.current_date = current_date
32        self.cart_items = cart_items31        self.cart_items = cart_items
33    def add_item(self):32    def add_item(self):
34        print('ADD ITEM TO CART')33        print('ADD ITEM TO CART')
n35        item_name = str(input('Enter the item name:'))n34        item_name = str(input('Enter the item name:\n'))
36        item_description = str(input('Enter the item description:'))35        item_description = str(input('Enter the item description:\n'))
37        item_price = int(input('Enter the item price:'))36        item_price = int(input('Enter the item price:\n'))
38        item_quantity = int(input('Enter the item quantity:'))37        item_quantity = int(input('Enter the item quantity:\n'))
39        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti38        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti
>ty, item_description))>ty, item_description))
40    def remove_item(self):39    def remove_item(self):
41        print('REMOVE ITEM FROM CART')40        print('REMOVE ITEM FROM CART')
n42        string = str(input('Enter name of item to remove:'))n41        string = str(input('Enter name of item to remove:\n'))
43        i = 042        i = 0
44        for item in self.cart_items:43        for item in self.cart_items:
45            if(item.item_name == string):               44            if(item.item_name == string):               
46                del self.cart_items[i]45                del self.cart_items[i]
47                flag=True46                flag=True
48                break47                break
49            else:48            else:
50                flag=False49                flag=False
51            i += 150            i += 1
52        if(flag==False):51        if(flag==False):
53            print('Item not found in cart. Nothing removed.')52            print('Item not found in cart. Nothing removed.')
54    def modify_item(self):53    def modify_item(self):
55        print('CHANGE ITEM QUANTITY')54        print('CHANGE ITEM QUANTITY')
56        name = str(input('Enter the item name:'))55        name = str(input('Enter the item name:'))
57        print()56        print()
58        for item in self.cart_items:57        for item in self.cart_items:
59            if(item.item_name == name):58            if(item.item_name == name):
60                quantity = int(input('Enter the new quantity:'))59                quantity = int(input('Enter the new quantity:'))
61                item.item_quantity = quantity60                item.item_quantity = quantity
62                flag=True61                flag=True
n63                breakn
64            else:62            else:
65                flag=False63                flag=False
66        if(flag==False):64        if(flag==False):
67            print('Item not found in cart. Nothing modified.')65            print('Item not found in cart. Nothing modified.')
68        print()66        print()
69    def get_num_items_in_cart(self):67    def get_num_items_in_cart(self):
70        num_items=068        num_items=0
71        for item in self.cart_items:69        for item in self.cart_items:
72            num_items= num_items+item.item_quantity70            num_items= num_items+item.item_quantity
73        return num_items71        return num_items
74    def get_cost_of_cart(self):72    def get_cost_of_cart(self):
75        total_cost = 073        total_cost = 0
76        cost = 074        cost = 0
77        for item in self.cart_items:75        for item in self.cart_items:
78            cost = (item.item_quantity * item.item_price)76            cost = (item.item_quantity * item.item_price)
79            total_cost += cost77            total_cost += cost
80        return total_cost78        return total_cost
81    def print_total(self):79    def print_total(self):
82        total_cost = self.get_cost_of_cart()80        total_cost = self.get_cost_of_cart()
83        if (total_cost == 0):81        if (total_cost == 0):
84            print('SHOPPING CART IS EMPTY')82            print('SHOPPING CART IS EMPTY')
85        else:83        else:
86            self.output_cart()84            self.output_cart()
87    def print_descriptions(self):85    def print_descriptions(self):
88        print('OUTPUT ITEMS\' DESCRIPTIONS')86        print('OUTPUT ITEMS\' DESCRIPTIONS')
89        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current87        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date),end='\n')>_date),end='\n')
90        print('\nItem Descriptions')88        print('\nItem Descriptions')
91        for item in self.cart_items:89        for item in self.cart_items:
92            print('{}: {}'.format(item.item_name, item.item_description))90            print('{}: {}'.format(item.item_name, item.item_description))
93    def output_cart(self):91    def output_cart(self):
94        print('OUTPUT SHOPPING CART')92        print('OUTPUT SHOPPING CART')
95        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current93        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date))      >_date))      
96        print('Number of Items:', self.get_num_items_in_cart())94        print('Number of Items:', self.get_num_items_in_cart())
97        tc = 095        tc = 0
98        for item in self.cart_items:96        for item in self.cart_items:
99            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,97            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,
100              item.item_price, (item.item_quantity * item.item_price)))98              item.item_price, (item.item_quantity * item.item_price)))
101            tc += (item.item_quantity * item.item_price)99            tc += (item.item_quantity * item.item_price)
102        if len(self.cart_items) == 0:100        if len(self.cart_items) == 0:
n103            print('SHOPPING CART IS EMPTY')n101            print('\nSHOPPING CART IS EMPTY')
104        print()102        print()
105        print('Total: ${}'.format(tc))103        print('Total: ${}'.format(tc))
106def print_menu(customer_Cart):104def print_menu(customer_Cart):
107    menu = ('\nMENU\n'105    menu = ('\nMENU\n'
108    'a - Add item to cart\n'106    'a - Add item to cart\n'
109    'r - Remove item from cart\n'107    'r - Remove item from cart\n'
110    'c - Change item quantity\n'108    'c - Change item quantity\n'
111    'i - Output items\' descriptions\n'109    'i - Output items\' descriptions\n'
112    'o - Output shopping cart\n'110    'o - Output shopping cart\n'
113    'q - Quit\n')111    'q - Quit\n')
114    command = ''112    command = ''
115    while(command != 'q'):113    while(command != 'q'):
116        print(menu)114        print(menu)
n117        command = input('Choose an option:')n115        command = input('Choose an option:\n')
118        while(command != 'a' and command != 'o' and command != 'i' and command !116        while(command != 'a' and command != 'o' and command != 'i' and command !
>= 'r'>= 'r'and command != 'c' and command != 'q'):
119              and command != 'c' and command != 'q'):
120            command = input('Choose an option:')117            command = input('Choose an option:\n')
121        if(command == 'a'):118        if(command == 'a'):
122            customer_Cart.add_item()119            customer_Cart.add_item()
123        if(command == 'o'):120        if(command == 'o'):
124            customer_Cart.output_cart()121            customer_Cart.output_cart()
125        if(command == 'i'):122        if(command == 'i'):
126            customer_Cart.print_descriptions()123            customer_Cart.print_descriptions()
127        if(command == 'r'):124        if(command == 'r'):
128            customer_Cart.remove_item()125            customer_Cart.remove_item()
129        if(command == 'c'):126        if(command == 'c'):
130            customer_Cart.modify_item()127            customer_Cart.modify_item()
n131if __name__ == '__main__':n128def main():
132    customer_name = str(input('Enter customer\'s name:'))129    customer_name = str(input('Enter customer\'s name:'))
nn130    print()
133    current_date = str(input('Enter today\'s date:'))131    current_date = str(input('Enter today\'s date:'))
nn132    print()
133    print()
134    print('Customer name:', customer_name)134    print('Customer name:', customer_name)
135    print('Today\'s date:', current_date)135    print('Today\'s date:', current_date)
136    x = ShoppingCart(customer_name, current_date)136    x = ShoppingCart(customer_name, current_date)
137    print_menu(x)137    print_menu(x)
n138import mathn138if __name__ == '__main__':
139    main()import math
139class pt3d:140class pt3d:
n140    def __init__(self,x,y,z):n141    def __init__(self,x=0,y=0,z=0):
141        self.x= x142        self.x= x
142        self.y= y143        self.y= y
143        self.z= z144        self.z= z
144    def __add__(self, other):145    def __add__(self, other):
145        x = self.x + other.x146        x = self.x + other.x
146        y = self.y + other.y147        y = self.y + other.y
147        z = self.z + other.z148        z = self.z + other.z
148        return pt3d(x, y,z)149        return pt3d(x, y,z)
149    def __sub__(self, other):150    def __sub__(self, other):
150        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 151        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>2)+math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
151    def __eq__(self, other):152    def __eq__(self, other):
152        return other.x==self.x and other.y==self.y and other.z==self.z153        return other.x==self.x and other.y==self.y and other.z==self.z
153    def __str__(self):154    def __str__(self):
154        return "<{0},{1},{2}>".format(self.x, self.y, self.z)155        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
t155if __name__ == "__main__":t156if __name__ == '__main__':
156   p1 = pt3d(1,1,1)157    p1 = pt3d(1, 1, 1)
157    p2 = pt3d(2,2,2)158    p2 = pt3d(2, 2, 2)
158    print(p1 + p2)159    print(p1+p2)
159    print(p1 - p2)160    print(p1-p2)
160    print(p1 == p2)161    print(p1==p2)
161    print(p1+p1 == p2)162    print(p1+p1==p2)
162    print(p1==p2+pt3d(-1,-1,-1))163    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 27

Student ID: 272, P-Value: 9.88e-04

Nearest Neighbor ID: 149

Student (left) and Nearest Neighbor (right).


n1from math import pin1import math
2class Circle:2class Circle:
n3    def __init__(self,r):n3    def __init__(self,x):
4        self.radiusr4        self.x
5    def area(self):5    def area(self):
n6        return self.radius**2*pin6        area = math.pi*((self.x)**2)
7        return area
7    def perimeter(self):8    def perimeter(self):
n8        return 2*pi*self.radiusn9        perimeter = 2*math.pi*self.x
10        return perimeter
9if __name__=='__main__':11if __name__=='__main__':
10    x = int(input())12    x = int(input())
11    NewCircle = Circle(x)13    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))14    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:15    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14   def __init__(self, name='none', price=0, quantity=0, description='none'):16   def __init__(self, name='none', price=0, quantity=0, description='none'):
15       self.item_name=name17       self.item_name=name
16       self.item_description=description18       self.item_description=description
17       self.item_price=price19       self.item_price=price
18       self.item_quantity=quantity20       self.item_quantity=quantity
19   def print_item_description(self):21   def print_item_description(self):
20       print('%s: %s' % (self.item_name, self.item_description))22       print('%s: %s' % (self.item_name, self.item_description))
21class ShoppingCart:23class ShoppingCart:
22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 24   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
23       self.customer_name = customer_name25       self.customer_name = customer_name
24       self.current_date = current_date26       self.current_date = current_date
25       self.cart_items = cart_items  27       self.cart_items = cart_items  
26   def add_item(self, itemToPurchase):28   def add_item(self, itemToPurchase):
27       self.cart_items.append(itemToPurchase)  29       self.cart_items.append(itemToPurchase)  
28   def remove_item(self, itemName):30   def remove_item(self, itemName):
29       tremove_item = False31       tremove_item = False
30       for item in self.cart_items:32       for item in self.cart_items:
31           if item.item_name == itemName:33           if item.item_name == itemName:
32               self.cart_items.remove(item)34               self.cart_items.remove(item)
33               tremove_item = True35               tremove_item = True
34               break36               break
35       if not tremove_item:          37       if not tremove_item:          
36           print('Item not found in cart. Nothing removed.')38           print('Item not found in cart. Nothing removed.')
37   def modify_item(self, itemToPurchase):  39   def modify_item(self, itemToPurchase):  
38       tmodify_item = False40       tmodify_item = False
39       for i in range(len(self.cart_items)):41       for i in range(len(self.cart_items)):
40           if self.cart_items[i].item_name == itemToPurchase.item_name:42           if self.cart_items[i].item_name == itemToPurchase.item_name:
41               tmodify_item = True43               tmodify_item = True
42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity44               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43               break45               break
44       if not tmodify_item:      46       if not tmodify_item:      
45           print('Item not found in cart. Nothing modified.')  47           print('Item not found in cart. Nothing modified.')  
46   def get_num_items_in_cart(self):48   def get_num_items_in_cart(self):
47       num_items = 049       num_items = 0
48       for item in self.cart_items:50       for item in self.cart_items:
49           num_items = num_items + item.item_quantity51           num_items = num_items + item.item_quantity
50       return num_items52       return num_items
51   def get_cost_of_cart(self):53   def get_cost_of_cart(self):
52       total_cost = 054       total_cost = 0
53       cost = 055       cost = 0
54       for item in self.cart_items:56       for item in self.cart_items:
55           cost = (item.item_quantity * item.item_price)57           cost = (item.item_quantity * item.item_price)
56           total_cost += cost58           total_cost += cost
57       return total_cost59       return total_cost
58   def print_total(self):60   def print_total(self):
59       total_cost = self.get_cost_of_cart()61       total_cost = self.get_cost_of_cart()
60       if (total_cost == 0):62       if (total_cost == 0):
61           print('SHOPPING CART IS EMPTY')63           print('SHOPPING CART IS EMPTY')
62       else:64       else:
63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr65           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
64           print('Number of Items: %d\n' %self.get_num_items_in_cart())66           print('Number of Items: %d\n' %self.get_num_items_in_cart())
65           for item in self.cart_items:67           for item in self.cart_items:
66               total = item.item_price * item.item_quantity68               total = item.item_price * item.item_quantity
67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 69               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
68           print('\nTotal: $%d' %(total_cost))70           print('\nTotal: $%d' %(total_cost))
69   def print_descriptions(self):71   def print_descriptions(self):
70       if len(self.cart_items) == 0:72       if len(self.cart_items) == 0:
71           print('SHOPPING CART IS EMPTY')73           print('SHOPPING CART IS EMPTY')
72       else:  74       else:  
73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr75           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
74           print('\nItem Descriptions')76           print('\nItem Descriptions')
75           for item in self.cart_items:77           for item in self.cart_items:
76               item.print_item_description()  78               item.print_item_description()  
77def print_menu(newCart):79def print_menu(newCart):
78   customer_Cart = newCart80   customer_Cart = newCart
79   menu = ('\nMENU\n'81   menu = ('\nMENU\n'
80       'a - Add item to cart\n'82       'a - Add item to cart\n'
81       'r - Remove item from cart\n'83       'r - Remove item from cart\n'
82       'c - Change item quantity\n'84       'c - Change item quantity\n'
83       "i - Output items' descriptions\n"85       "i - Output items' descriptions\n"
84       'o - Output shopping cart\n'86       'o - Output shopping cart\n'
85       'q - Quit\n')87       'q - Quit\n')
86   command = ''88   command = ''
87   while(command != 'q'):89   while(command != 'q'):
88       print(menu)90       print(menu)
89       command = input('Choose an option:')91       command = input('Choose an option:')
90       while(command != 'a' and command != 'o' and command != 'i' and command !=92       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
n91           command = input('Choose an option\n:')n93           command = input('\nChoose an option:')
92       if(command == 'a'):94       if(command == 'a'):
93           print("\nADD ITEM TO CART")95           print("\nADD ITEM TO CART")
n94           item_name = input('Enter the item name:\n')n96           item_name = input('Enter item name:\n')
95           item_description = input('Enter the item description:\n')97           item_description = input('Enter item description:\n')
96           item_price = int(input('Enter the item price:\n'))98           item_price = int(input('Enter the item price:\n'))
97           item_quantity = int(input('Enter the item quantity:\n'))99           item_quantity = int(input('Enter the item quantity:\n'))
98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,100           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
99           customer_Cart.add_item(itemtoPurchase)101           customer_Cart.add_item(itemtoPurchase)
100       elif(command == 'o'):102       elif(command == 'o'):
101           print('\nOUTPUT SHOPPING CART')103           print('\nOUTPUT SHOPPING CART')
102           customer_Cart.print_total()  104           customer_Cart.print_total()  
103       elif(command == 'i'):105       elif(command == 'i'):
104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')106           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
105           customer_Cart.print_descriptions()107           customer_Cart.print_descriptions()
106       elif(command == 'r'):108       elif(command == 'r'):
107           print('REMOVE ITEM FROM CART')109           print('REMOVE ITEM FROM CART')
108           itemName = input('Enter name of item to remove:\n')110           itemName = input('Enter name of item to remove:\n')
109           customer_Cart.remove_item(itemName)111           customer_Cart.remove_item(itemName)
110       elif(command == 'c'):112       elif(command == 'c'):
111           print('\nCHANGE ITEM QUANTITY')113           print('\nCHANGE ITEM QUANTITY')
n112           itemName = input('Enter the item name:\n')n114           itemName = input('Enter name of item:\n')
113           qty = int(input('Enter the new quantity:\n'))115           quantity = int(input('Enter the new quantity:\n'))
114           itemToPurchase = ItemToPurchase(itemName,0,qty)116           itemToPurchase = ItemToPurchase(itemName,0,quantity)
115           customer_Cart.modify_item(itemToPurchase)117           customer_Cart.modify_item(itemToPurchase)
116if __name__ == "__main__":118if __name__ == "__main__":
117   customer_name = input("Enter customer's name:\n")119   customer_name = input("Enter customer's name:\n")
118   current_date = input("Enter today's date:\n")120   current_date = input("Enter today's date:\n")
119   print("\nCustomer name: %s" %customer_name)121   print("\nCustomer name: %s" %customer_name)
120   print("Today's date: %s" %current_date)122   print("Today's date: %s" %current_date)
121   newCart = ShoppingCart(customer_name, current_date)123   newCart = ShoppingCart(customer_name, current_date)
122   print_menu(newCart)  124   print_menu(newCart)  
123   print()import math125   print()import math
124class pt3d:126class pt3d:
125    def __init__(self,x=0,y=0,z=0):127    def __init__(self,x=0,y=0,z=0):
n126        self.x = xn128        self.x=x
127        self.y = y129        self.y=y
128        self.z = z130        self.z=z
129    def __add__(self,point):131    def __add__(self,point):
t130        x1 = self.x + point.xt132        x1 = self.x+point.x
131        y1 = self.y + point.y133        y1 = self.y+point.y
132        z1 = self.z + point.z134        z1 = self.z+point.z
133        return pt3d(x1,y1,z1)135        return pt3d(x1, y1, z1)
134    def __sub__(self,point):  136    def __sub__(self,point):
135        x1 = (self.x-point.x)**2137        x1 = (self.x-point.x)**2
136        y1 = (self.y-point.y)**2138        y1 = (self.y-point.y)**2
137        z1 = (self.z-point.z)**2139        z1 = (self.z-point.z)**2
138        return math.sqrt(x1+y1+z1)140        return math.sqrt(x1+y1+z1)
139    def __str__(self):141    def __str__(self):
140        return f"<{self.x},{self.y},{self.z}>"142        return f"<{self.x},{self.y},{self.z}>"
141    def __eq__(self,point):143    def __eq__(self,point):
142        if (self.x == point.x) and (self.y == point.y) and (self.x == point.x):144        if (self.x == point.x) and (self.y == point.y) and (self.x == point.x):
143            return True145            return True
144        else:146        else:
145            return False147            return False
146a = pt3d(1,1,1)148a = pt3d(1,1,1)
147b = pt3d(2,2,2)149b = pt3d(2,2,2)
148print(a-b)150print(a-b)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 28

Student ID: 149, P-Value: 9.88e-04

Nearest Neighbor ID: 272

Student (left) and Nearest Neighbor (right).


n1import mathn1from math import pi
2class Circle:2class Circle:
n3    def __init__(self,x):n3    def __init__(self,r):
4        self.x4        self.radiusr
5    def area(self):5    def area(self):
n6        area = math.pi*((self.x)**2)n6        return self.radius**2*pi
7        return area
8    def perimeter(self):7    def perimeter(self):
n9        perimeter = 2*math.pi*self.xn8        return 2*pi*self.radius
10        return perimeter
11if __name__=='__main__':9if __name__=='__main__':
12    x = int(input())10    x = int(input())
13    NewCircle = Circle(x)11    NewCircle = Circle(x)
14    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
15    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
16   def __init__(self, name='none', price=0, quantity=0, description='none'):14   def __init__(self, name='none', price=0, quantity=0, description='none'):
17       self.item_name=name15       self.item_name=name
18       self.item_description=description16       self.item_description=description
19       self.item_price=price17       self.item_price=price
20       self.item_quantity=quantity18       self.item_quantity=quantity
21   def print_item_description(self):19   def print_item_description(self):
22       print('%s: %s' % (self.item_name, self.item_description))20       print('%s: %s' % (self.item_name, self.item_description))
23class ShoppingCart:21class ShoppingCart:
24   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
25       self.customer_name = customer_name23       self.customer_name = customer_name
26       self.current_date = current_date24       self.current_date = current_date
27       self.cart_items = cart_items  25       self.cart_items = cart_items  
28   def add_item(self, itemToPurchase):26   def add_item(self, itemToPurchase):
29       self.cart_items.append(itemToPurchase)  27       self.cart_items.append(itemToPurchase)  
30   def remove_item(self, itemName):28   def remove_item(self, itemName):
31       tremove_item = False29       tremove_item = False
32       for item in self.cart_items:30       for item in self.cart_items:
33           if item.item_name == itemName:31           if item.item_name == itemName:
34               self.cart_items.remove(item)32               self.cart_items.remove(item)
35               tremove_item = True33               tremove_item = True
36               break34               break
37       if not tremove_item:          35       if not tremove_item:          
38           print('Item not found in cart. Nothing removed.')36           print('Item not found in cart. Nothing removed.')
39   def modify_item(self, itemToPurchase):  37   def modify_item(self, itemToPurchase):  
40       tmodify_item = False38       tmodify_item = False
41       for i in range(len(self.cart_items)):39       for i in range(len(self.cart_items)):
42           if self.cart_items[i].item_name == itemToPurchase.item_name:40           if self.cart_items[i].item_name == itemToPurchase.item_name:
43               tmodify_item = True41               tmodify_item = True
44               self.cart_items[i].item_quantity = itemToPurchase.item_quantity42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
45               break43               break
46       if not tmodify_item:      44       if not tmodify_item:      
47           print('Item not found in cart. Nothing modified.')  45           print('Item not found in cart. Nothing modified.')  
48   def get_num_items_in_cart(self):46   def get_num_items_in_cart(self):
49       num_items = 047       num_items = 0
50       for item in self.cart_items:48       for item in self.cart_items:
51           num_items = num_items + item.item_quantity49           num_items = num_items + item.item_quantity
52       return num_items50       return num_items
53   def get_cost_of_cart(self):51   def get_cost_of_cart(self):
54       total_cost = 052       total_cost = 0
55       cost = 053       cost = 0
56       for item in self.cart_items:54       for item in self.cart_items:
57           cost = (item.item_quantity * item.item_price)55           cost = (item.item_quantity * item.item_price)
58           total_cost += cost56           total_cost += cost
59       return total_cost57       return total_cost
60   def print_total(self):58   def print_total(self):
61       total_cost = self.get_cost_of_cart()59       total_cost = self.get_cost_of_cart()
62       if (total_cost == 0):60       if (total_cost == 0):
63           print('SHOPPING CART IS EMPTY')61           print('SHOPPING CART IS EMPTY')
64       else:62       else:
65           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
66           print('Number of Items: %d\n' %self.get_num_items_in_cart())64           print('Number of Items: %d\n' %self.get_num_items_in_cart())
67           for item in self.cart_items:65           for item in self.cart_items:
68               total = item.item_price * item.item_quantity66               total = item.item_price * item.item_quantity
69               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
70           print('\nTotal: $%d' %(total_cost))68           print('\nTotal: $%d' %(total_cost))
71   def print_descriptions(self):69   def print_descriptions(self):
72       if len(self.cart_items) == 0:70       if len(self.cart_items) == 0:
73           print('SHOPPING CART IS EMPTY')71           print('SHOPPING CART IS EMPTY')
74       else:  72       else:  
75           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
76           print('\nItem Descriptions')74           print('\nItem Descriptions')
77           for item in self.cart_items:75           for item in self.cart_items:
78               item.print_item_description()  76               item.print_item_description()  
79def print_menu(newCart):77def print_menu(newCart):
80   customer_Cart = newCart78   customer_Cart = newCart
81   menu = ('\nMENU\n'79   menu = ('\nMENU\n'
82       'a - Add item to cart\n'80       'a - Add item to cart\n'
83       'r - Remove item from cart\n'81       'r - Remove item from cart\n'
84       'c - Change item quantity\n'82       'c - Change item quantity\n'
85       "i - Output items' descriptions\n"83       "i - Output items' descriptions\n"
86       'o - Output shopping cart\n'84       'o - Output shopping cart\n'
87       'q - Quit\n')85       'q - Quit\n')
88   command = ''86   command = ''
89   while(command != 'q'):87   while(command != 'q'):
90       print(menu)88       print(menu)
91       command = input('Choose an option:')89       command = input('Choose an option:')
92       while(command != 'a' and command != 'o' and command != 'i' and command !=90       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
n93           command = input('\nChoose an option:')n91           command = input('Choose an option\n:')
94       if(command == 'a'):92       if(command == 'a'):
95           print("\nADD ITEM TO CART")93           print("\nADD ITEM TO CART")
n96           item_name = input('Enter item name:\n')n94           item_name = input('Enter the item name:\n')
97           item_description = input('Enter item description:\n')95           item_description = input('Enter the item description:\n')
98           item_price = int(input('Enter the item price:\n'))96           item_price = int(input('Enter the item price:\n'))
99           item_quantity = int(input('Enter the item quantity:\n'))97           item_quantity = int(input('Enter the item quantity:\n'))
100           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
101           customer_Cart.add_item(itemtoPurchase)99           customer_Cart.add_item(itemtoPurchase)
102       elif(command == 'o'):100       elif(command == 'o'):
103           print('\nOUTPUT SHOPPING CART')101           print('\nOUTPUT SHOPPING CART')
104           customer_Cart.print_total()  102           customer_Cart.print_total()  
105       elif(command == 'i'):103       elif(command == 'i'):
106           print('\nOUTPUT ITEMS\' DESCRIPTIONS')104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
107           customer_Cart.print_descriptions()105           customer_Cart.print_descriptions()
108       elif(command == 'r'):106       elif(command == 'r'):
109           print('REMOVE ITEM FROM CART')107           print('REMOVE ITEM FROM CART')
110           itemName = input('Enter name of item to remove:\n')108           itemName = input('Enter name of item to remove:\n')
111           customer_Cart.remove_item(itemName)109           customer_Cart.remove_item(itemName)
112       elif(command == 'c'):110       elif(command == 'c'):
113           print('\nCHANGE ITEM QUANTITY')111           print('\nCHANGE ITEM QUANTITY')
n114           itemName = input('Enter name of item:\n')n112           itemName = input('Enter the item name:\n')
115           quantity = int(input('Enter the new quantity:\n'))113           qty = int(input('Enter the new quantity:\n'))
116           itemToPurchase = ItemToPurchase(itemName,0,quantity)114           itemToPurchase = ItemToPurchase(itemName,0,qty)
117           customer_Cart.modify_item(itemToPurchase)115           customer_Cart.modify_item(itemToPurchase)
118if __name__ == "__main__":116if __name__ == "__main__":
119   customer_name = input("Enter customer's name:\n")117   customer_name = input("Enter customer's name:\n")
120   current_date = input("Enter today's date:\n")118   current_date = input("Enter today's date:\n")
121   print("\nCustomer name: %s" %customer_name)119   print("\nCustomer name: %s" %customer_name)
122   print("Today's date: %s" %current_date)120   print("Today's date: %s" %current_date)
123   newCart = ShoppingCart(customer_name, current_date)121   newCart = ShoppingCart(customer_name, current_date)
124   print_menu(newCart)  122   print_menu(newCart)  
125   print()import math123   print()import math
126class pt3d:124class pt3d:
127    def __init__(self,x=0,y=0,z=0):125    def __init__(self,x=0,y=0,z=0):
n128        self.x=xn126        self.x = x
129        self.y=y127        self.y = y
130        self.z=z128        self.z = z
131    def __add__(self,point):129    def __add__(self,point):
t132        x1 = self.x+point.xt130        x1 = self.x + point.x
133        y1 = self.y+point.y131        y1 = self.y + point.y
134        z1 = self.z+point.z132        z1 = self.z + point.z
135        return pt3d(x1, y1, z1)133        return pt3d(x1,y1,z1)
136    def __sub__(self,point):134    def __sub__(self,point):  
137        x1 = (self.x-point.x)**2135        x1 = (self.x-point.x)**2
138        y1 = (self.y-point.y)**2136        y1 = (self.y-point.y)**2
139        z1 = (self.z-point.z)**2137        z1 = (self.z-point.z)**2
140        return math.sqrt(x1+y1+z1)138        return math.sqrt(x1+y1+z1)
141    def __str__(self):139    def __str__(self):
142        return f"<{self.x},{self.y},{self.z}>"140        return f"<{self.x},{self.y},{self.z}>"
143    def __eq__(self,point):141    def __eq__(self,point):
144        if (self.x == point.x) and (self.y == point.y) and (self.x == point.x):142        if (self.x == point.x) and (self.y == point.y) and (self.x == point.x):
145            return True143            return True
146        else:144        else:
147            return False145            return False
148a = pt3d(1,1,1)146a = pt3d(1,1,1)
149b = pt3d(2,2,2)147b = pt3d(2,2,2)
150print(a-b)148print(a-b)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 29

Student ID: 414, P-Value: 1.28e-03

Nearest Neighbor ID: 478

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle:n2class Circle :
3    def __init__(self,radius):3    def __init__(self,radius):
n4        self.radius=radiusn4        self.radius = radius
5    def area(self):5    def area(self):
6        return math.pi*self.radius*self.radius6        return math.pi*self.radius*self.radius
7    def perimeter(self):7    def perimeter(self):
n8        return math.pi*2*self.radiusn8        return 2*math.pi*self.radius
9if __name__=='__main__':9if __name__ == '__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
n13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:n13    print('{:.5f}'.format(NewCircle.perimeter()))
14class ItemToPurchase:
14   def __init__(self, name='none', price=0, quantity=0, description="none"):15   def __init__(self, name='none', price=0, quantity=0, description='none'):
15       self.item_name=name16       self.item_name=name
16       self.item_description=description17       self.item_description=description
nn18       self.item_price=price
17       self.item_quantity=quantity19       self.item_quantity=quantity
n18       self.item_price=pricen
19   def print_item_description(self):20   def print_item_description(self):
20       print('%s: %s' % (self.item_name, self.item_description))21       print('%s: %s' % (self.item_name, self.item_description))
21class ShoppingCart:22class ShoppingCart:
22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 23   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
23       self.customer_name = customer_name24       self.customer_name = customer_name
24       self.current_date = current_date25       self.current_date = current_date
25       self.cart_items = cart_items  26       self.cart_items = cart_items  
26   def add_item(self, itemToPurchase):27   def add_item(self, itemToPurchase):
27       self.cart_items.append(itemToPurchase)  28       self.cart_items.append(itemToPurchase)  
28   def remove_item(self, itemName):29   def remove_item(self, itemName):
29       tremove_item = False30       tremove_item = False
30       for item in self.cart_items:31       for item in self.cart_items:
31           if item.item_name == itemName:32           if item.item_name == itemName:
32               self.cart_items.remove(item)33               self.cart_items.remove(item)
33               tremove_item = True34               tremove_item = True
34               break35               break
35       if not tremove_item:          36       if not tremove_item:          
36           print('Item not found in the cart. Nothing removed')37           print('Item not found in the cart. Nothing removed')
37   def modify_item(self, itemToPurchase):  38   def modify_item(self, itemToPurchase):  
38       tmodify_item = False39       tmodify_item = False
n39       for x in range(len(self.cart_items)):n40       for i in range(len(self.cart_items)):
40           if self.cart_items[x].item_name == itemToPurchase.item_name:41           if self.cart_items[i].item_name == itemToPurchase.item_name:
41               tmodify_item = True42               tmodify_item = True
n42               self.cart_items[x].item_quantity = itemToPurchase.item_quantityn43               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43               break44               break
44       if not tmodify_item:      45       if not tmodify_item:      
45           print('Item not found in the cart. Nothing modified')  46           print('Item not found in the cart. Nothing modified')  
46   def get_num_items_in_cart(self):47   def get_num_items_in_cart(self):
47       num_items = 048       num_items = 0
48       for item in self.cart_items:49       for item in self.cart_items:
49           num_items = num_items + item.item_quantity50           num_items = num_items + item.item_quantity
50       return num_items51       return num_items
51   def get_cost_of_cart(self):52   def get_cost_of_cart(self):
52       total_cost = 053       total_cost = 0
53       cost = 054       cost = 0
54       for item in self.cart_items:55       for item in self.cart_items:
55           cost = (item.item_quantity * item.item_price)56           cost = (item.item_quantity * item.item_price)
n56           total_cost = total_cost+ costn57           total_cost += cost
57       return total_cost58       return total_cost
58   def print_total(self):59   def print_total(self):
59       total_cost = self.get_cost_of_cart()60       total_cost = self.get_cost_of_cart()
60       if (total_cost == 0):61       if (total_cost == 0):
61           print('SHOPPING CART IS EMPTY')62           print('SHOPPING CART IS EMPTY')
62       else:63       else:
63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr64           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
64           print('Number of Items: %d\n' %self.get_num_items_in_cart())65           print('Number of Items: %d\n' %self.get_num_items_in_cart())
65           for item in self.cart_items:66           for item in self.cart_items:
66               total = item.item_price * item.item_quantity67               total = item.item_price * item.item_quantity
67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 68               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
68           print('\nTotal: $%d' %(total_cost))69           print('\nTotal: $%d' %(total_cost))
69   def print_descriptions(self):70   def print_descriptions(self):
70       if len(self.cart_items) == 0:71       if len(self.cart_items) == 0:
71           print('SHOPPING CART IS EMPTY')72           print('SHOPPING CART IS EMPTY')
72       else:  73       else:  
73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr74           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
74           print('\nItem Descriptions')75           print('\nItem Descriptions')
75           for item in self.cart_items:76           for item in self.cart_items:
76               item.print_item_description()  77               item.print_item_description()  
n77def print_menu(finalcart):n78def print_menu(newCart):
78   customer_Cart = finalcart79   customer_Cart = newCart
79   menu = ('\nMENU\n'80   menu = ('\nMENU\n'
80       'a - Add item to cart\n'81       'a - Add item to cart\n'
n81       'r - Remove item from the cart\n'n82       'r - Remove item from cart\n'
82       'c - Change item quantity\n'83       'c - Change item quantity\n'
n83       "i - Output item's descriptions\n"n84       "i - Output items' descriptions\n"
84       'o - Output shopping cart\n'85       'o - Output shopping cart\n'
85       'q - Quit\n')86       'q - Quit\n')
86   command = ''87   command = ''
87   while(command != 'q'):88   while(command != 'q'):
88       print(menu)89       print(menu)
n89       command = input('Choose an option:')n90       command = input('Choose an option:\n')
90       while(command != 'a' and command != 'o' and command != 'i' and command !=91       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
91           command = input('Choose an option:\n')92           command = input('Choose an option:\n')
92       if(command == 'a'):93       if(command == 'a'):
93           print("\nADD ITEM TO CART")94           print("\nADD ITEM TO CART")
94           item_name = input('Enter the item name:\n')95           item_name = input('Enter the item name:\n')
nn96           item_description = input('Enter the item description:\n')
95           item_price = int(input('Enter the item price:\n'))97           item_price = int(input('Enter the item price:\n'))
n96           item_description = input('Enter the item description:\n')n
97           item_quantity = int(input('Enter the item quantity:\n'))98           item_quantity = int(input('Enter the item quantity:\n'))
98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,99           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
99           customer_Cart.add_item(itemtoPurchase)100           customer_Cart.add_item(itemtoPurchase)
n100       elif(command =='o'):n101       elif(command == 'o'):
101           print('\nOUTPUT SHOPPING CART')102           print('\nOUTPUT SHOPPING CART')
102           customer_Cart.print_total()  103           customer_Cart.print_total()  
n103       elif(command =='i'):n104       elif(command == 'i'):
104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')105           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
105           customer_Cart.print_descriptions()106           customer_Cart.print_descriptions()
n106       elif(command =='r'):n107       elif(command == 'r'):
107           print('REMOVE ITEM FROM CART')108           print('REMOVE ITEM FROM CART')
108           itemName = input('Enter the name of the item to remove :\n')109           itemName = input('Enter the name of the item to remove :\n')
109           customer_Cart.remove_item(itemName)110           customer_Cart.remove_item(itemName)
n110       elif(command =='c'):n111       elif(command == 'c'):
111           print('\nCHANGE ITEM QUANTITY')112           print('\nCHANGE ITEM QUANTITY')
112           itemName = input('Enter the name of the item :\n')113           itemName = input('Enter the name of the item :\n')
113           qty = int(input('Enter the new quantity :\n'))114           qty = int(input('Enter the new quantity :\n'))
114           itemToPurchase = ItemToPurchase(itemName,0,qty)115           itemToPurchase = ItemToPurchase(itemName,0,qty)
115           customer_Cart.modify_item(itemToPurchase)116           customer_Cart.modify_item(itemToPurchase)
116if __name__ == "__main__":117if __name__ == "__main__":
117   customer_name = input("Enter customer's name:\n")118   customer_name = input("Enter customer's name:\n")
118   current_date = input("Enter today's date:\n")119   current_date = input("Enter today's date:\n")
119   print("\nCustomer name: %s" %customer_name)120   print("\nCustomer name: %s" %customer_name)
120   print("Today's date: %s" %current_date)121   print("Today's date: %s" %current_date)
n121   finalcart = ShoppingCart(customer_name, current_date)n122   newCart = ShoppingCart(customer_name, current_date)
122   print_menu(finalcart)  import math123   print_menu(newCart)import math
123class pt3d:124class pt3d:
124    def __init__(self,x=0,y=0,z=0):125    def __init__(self,x=0,y=0,z=0):
125        self.x= x126        self.x= x
126        self.y= y127        self.y= y
127        self.z= z128        self.z= z
128    def __add__(self, other):129    def __add__(self, other):
129        x = self.x + other.x130        x = self.x + other.x
130        y = self.y + other.y131        y = self.y + other.y
131        z = self.z + other.z132        z = self.z + other.z
132        return pt3d(x, y,z)133        return pt3d(x, y,z)
133    def __sub__(self, other):134    def __sub__(self, other):
134        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 135        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>2)+math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
135    def __eq__(self, other):136    def __eq__(self, other):
136        return other.x==self.x and other.y==self.y and other.z==self.z137        return other.x==self.x and other.y==self.y and other.z==self.z
137    def __str__(self):138    def __str__(self):
n138        return '<{0},{1},{2}>'.format(self.x, self.y, self.z)n139        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
139if __name__ == '__main__':140if __name__ == '__main__':
t140    p1 = pt3d(1, 23)t141    p1 = pt3d(1, 11)
141    p2 = pt3d(456)142    p2 = pt3d(222)
142    print(p1+p2)143    print(p1+p2)
143    print(p1-p2)144    print(p1-p2)
144    print(p1==p2)145    print(p1==p2)
145    print(p1+p1==p2)146    print(p1+p1==p2)
146    print(p1==p2+pt3d(-1,-1,-1))147    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 30

Student ID: 464, P-Value: 1.31e-03

Nearest Neighbor ID: 478

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle:n2class Circle :
3    def __init__(self,my_radius):3    def __init__(self,radius):
4        self.radius=my_radius  4        self.radius = radius
5    def area(self):5    def area(self):
n6        return (math.pi*(self.radius**2))n6        return math.pi*self.radius*self.radius
7    def perimeter(self):7    def perimeter(self):
n8        return(2*math.pi*self.radius)n8        return 2*math.pi*self.radius
9if __name__=='__main__':9if __name__ == '__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
n13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:n13    print('{:.5f}'.format(NewCircle.perimeter()))
14class ItemToPurchase:
14   def __init__(self, name='none', price=0, quantity=0, description='none'):15   def __init__(self, name='none', price=0, quantity=0, description='none'):
15       self.item_name=name16       self.item_name=name
16       self.item_description=description17       self.item_description=description
17       self.item_price=price18       self.item_price=price
18       self.item_quantity=quantity19       self.item_quantity=quantity
19   def print_item_description(self):20   def print_item_description(self):
20       print('%s: %s' % (self.item_name, self.item_description))21       print('%s: %s' % (self.item_name, self.item_description))
21class ShoppingCart:22class ShoppingCart:
22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 23   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
23       self.customer_name = customer_name24       self.customer_name = customer_name
24       self.current_date = current_date25       self.current_date = current_date
25       self.cart_items = cart_items  26       self.cart_items = cart_items  
26   def add_item(self, itemToPurchase):27   def add_item(self, itemToPurchase):
27       self.cart_items.append(itemToPurchase)  28       self.cart_items.append(itemToPurchase)  
n28   def remove_item(self, Nameitem):n29   def remove_item(self, itemName):
29       removeIt = False30       tremove_item = False
30       for item in self.cart_items:31       for item in self.cart_items:
n31           if item.item_name == Nameitem:n32           if item.item_name == itemName:
32               self.cart_items.remove(item)33               self.cart_items.remove(item)
n33               removeIt = Truen34               tremove_item = True
34               break35               break
n35       if not removeIt:          n36       if not tremove_item:          
36           print('Item not found in the cart. Nothing removed')37           print('Item not found in the cart. Nothing removed')
37   def modify_item(self, itemToPurchase):  38   def modify_item(self, itemToPurchase):  
n38       modifyIt = Falsen39       tmodify_item = False
39       for i in range(len(self.cart_items)):40       for i in range(len(self.cart_items)):
40           if self.cart_items[i].item_name == itemToPurchase.item_name:41           if self.cart_items[i].item_name == itemToPurchase.item_name:
n41               modifyIt = Truen42               tmodify_item = True
42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity43               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43               break44               break
n44       if not modifyIt:      n45       if not tmodify_item:      
45           print('Item not found in the cart. Nothing modified')  46           print('Item not found in the cart. Nothing modified')  
46   def get_num_items_in_cart(self):47   def get_num_items_in_cart(self):
47       num_items = 048       num_items = 0
48       for item in self.cart_items:49       for item in self.cart_items:
49           num_items = num_items + item.item_quantity50           num_items = num_items + item.item_quantity
50       return num_items51       return num_items
51   def get_cost_of_cart(self):52   def get_cost_of_cart(self):
52       total_cost = 053       total_cost = 0
53       cost = 054       cost = 0
54       for item in self.cart_items:55       for item in self.cart_items:
55           cost = (item.item_quantity * item.item_price)56           cost = (item.item_quantity * item.item_price)
56           total_cost += cost57           total_cost += cost
57       return total_cost58       return total_cost
58   def print_total(self):59   def print_total(self):
59       total_cost = self.get_cost_of_cart()60       total_cost = self.get_cost_of_cart()
60       if (total_cost == 0):61       if (total_cost == 0):
61           print('SHOPPING CART IS EMPTY')62           print('SHOPPING CART IS EMPTY')
62       else:63       else:
63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr64           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
64           print('Number of Items: %d\n' %self.get_num_items_in_cart())65           print('Number of Items: %d\n' %self.get_num_items_in_cart())
65           for item in self.cart_items:66           for item in self.cart_items:
66               total = item.item_price * item.item_quantity67               total = item.item_price * item.item_quantity
67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 68               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
68           print('\nTotal: $%d' %(total_cost))69           print('\nTotal: $%d' %(total_cost))
69   def print_descriptions(self):70   def print_descriptions(self):
70       if len(self.cart_items) == 0:71       if len(self.cart_items) == 0:
71           print('SHOPPING CART IS EMPTY')72           print('SHOPPING CART IS EMPTY')
72       else:  73       else:  
73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr74           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
74           print('\nItem Descriptions')75           print('\nItem Descriptions')
75           for item in self.cart_items:76           for item in self.cart_items:
76               item.print_item_description()  77               item.print_item_description()  
77def print_menu(newCart):78def print_menu(newCart):
78   customer_Cart = newCart79   customer_Cart = newCart
79   menu = ('\nMENU\n'80   menu = ('\nMENU\n'
80       'a - Add item to cart\n'81       'a - Add item to cart\n'
81       'r - Remove item from cart\n'82       'r - Remove item from cart\n'
82       'c - Change item quantity\n'83       'c - Change item quantity\n'
83       "i - Output items' descriptions\n"84       "i - Output items' descriptions\n"
84       'o - Output shopping cart\n'85       'o - Output shopping cart\n'
85       'q - Quit\n')86       'q - Quit\n')
86   command = ''87   command = ''
87   while(command != 'q'):88   while(command != 'q'):
88       print(menu)89       print(menu)
n89       command = input('Choose an option:')n90       command = input('Choose an option:\n')
90       while(command != 'a' and command != 'o' and command != 'i' and command !=91       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
91           command = input('Choose an option:\n')92           command = input('Choose an option:\n')
92       if(command == 'a'):93       if(command == 'a'):
93           print("\nADD ITEM TO CART")94           print("\nADD ITEM TO CART")
94           item_name = input('Enter the item name:\n')95           item_name = input('Enter the item name:\n')
95           item_description = input('Enter the item description:\n')96           item_description = input('Enter the item description:\n')
96           item_price = int(input('Enter the item price:\n'))97           item_price = int(input('Enter the item price:\n'))
97           item_quantity = int(input('Enter the item quantity:\n'))98           item_quantity = int(input('Enter the item quantity:\n'))
98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,99           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
99           customer_Cart.add_item(itemtoPurchase)100           customer_Cart.add_item(itemtoPurchase)
100       elif(command == 'o'):101       elif(command == 'o'):
101           print('\nOUTPUT SHOPPING CART')102           print('\nOUTPUT SHOPPING CART')
102           customer_Cart.print_total()  103           customer_Cart.print_total()  
103       elif(command == 'i'):104       elif(command == 'i'):
104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')105           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
105           customer_Cart.print_descriptions()106           customer_Cart.print_descriptions()
106       elif(command == 'r'):107       elif(command == 'r'):
107           print('REMOVE ITEM FROM CART')108           print('REMOVE ITEM FROM CART')
108           itemName = input('Enter the name of the item to remove :\n')109           itemName = input('Enter the name of the item to remove :\n')
109           customer_Cart.remove_item(itemName)110           customer_Cart.remove_item(itemName)
110       elif(command == 'c'):111       elif(command == 'c'):
111           print('\nCHANGE ITEM QUANTITY')112           print('\nCHANGE ITEM QUANTITY')
112           itemName = input('Enter the name of the item :\n')113           itemName = input('Enter the name of the item :\n')
113           qty = int(input('Enter the new quantity :\n'))114           qty = int(input('Enter the new quantity :\n'))
114           itemToPurchase = ItemToPurchase(itemName,0,qty)115           itemToPurchase = ItemToPurchase(itemName,0,qty)
115           customer_Cart.modify_item(itemToPurchase)116           customer_Cart.modify_item(itemToPurchase)
116if __name__ == "__main__":117if __name__ == "__main__":
117   customer_name = input("Enter customer's name:\n")118   customer_name = input("Enter customer's name:\n")
118   current_date = input("Enter today's date:\n")119   current_date = input("Enter today's date:\n")
119   print("\nCustomer name: %s" %customer_name)120   print("\nCustomer name: %s" %customer_name)
120   print("Today's date: %s" %current_date)121   print("Today's date: %s" %current_date)
121   newCart = ShoppingCart(customer_name, current_date)122   newCart = ShoppingCart(customer_name, current_date)
122   print_menu(newCart)import math123   print_menu(newCart)import math
123class pt3d:124class pt3d:
n124    def __init__(self, x=0, y=0, z=0):n125    def __init__(self,x=0,y=0,z=0):
125        self.x=x126        self.x= x
126        self.y=y127        self.y= y
127        self.z=z128        self.z= z
128    def __add__(self, other):129    def __add__(self, other):
129        x = self.x + other.x130        x = self.x + other.x
130        y = self.y + other.y131        y = self.y + other.y
131        z = self.z + other.z132        z = self.z + other.z
n132        return pt3d(x, y, z)n133        return pt3d(x, y,z)
133    def __sub__(self, other):134    def __sub__(self, other):
n134        return math.sqrt(math.pow(other.x-self.x, 2)+ math.pow(other.y-self.y, 2n135        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>)+ math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
135    def __equal__(self, other):136    def __eq__(self, other):
136        return other.x==self.x and other.y==self.y and other.z==self.z137        return other.x==self.x and other.y==self.y and other.z==self.z
137    def __str__(self):138    def __str__(self):
n138        return '<{0},{1},{2}>'.format(self.x, self.y, self.z)n139        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
139if __name__ == '__main__':140if __name__ == '__main__':
t140    p1 = pt3d(1,1,1)t141    p1 = pt3d(1, 1, 1)
141    p2 = pt3d(2,2,2)142    p2 = pt3d(2, 2, 2)
142    print(p1+p2)143    print(p1+p2)
143    print(p1-p2)144    print(p1-p2)
144    print(p1==p2)145    print(p1==p2)
145    print(p1+p1==p2)146    print(p1+p1==p2)
146    print(p1==p2+pt3d(-1,-1,-1))147    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 31

Student ID: 419, P-Value: 1.64e-03

Nearest Neighbor ID: 299

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self,radius):n3    def __init__(self,x):
4        self.radius = radius4        self.x= x
5    def area(self):5    def area(self):
n6        return math.pi * self.radius**2n6        area=(math.pi*(self.x**2))
7        return area
7    def perimeter(self):8    def perimeter(self):
n8        return 2 * math.pi * self.radiusn9        perimeter =2*math.pi*self.x
10        return perimeter
9if __name__=='__main__':11if __name__=='__main__':
10    x = int(input())12    x = int(input())
11    NewCircle = Circle(x)13    NewCircle = Circle(x)
n12    print('{:.5f}'.format(NewCircle.area()))n14    print(NewCircle.area())
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:15    print(NewCircle.perimeter())class ItemToPurchase:
14    def __init__(self, name='none', price=0, quantity=0, description='none'):16    def __init__(self, name='none', price=0, quantity=0, description='none'):
15        self.item_name=name17        self.item_name=name
16        self.item_description=description18        self.item_description=description
17        self.item_price=price19        self.item_price=price
18        self.item_quantity=quantity20        self.item_quantity=quantity
19    def print_item_description(self):21    def print_item_description(self):
n20        print('%s: %s' % (self.item_name, self.item_description))n22       print('%s: %s' % (self.item_name, self.item_description))
21class ShoppingCart:23class ShoppingCart:
22    def __init__(self, customer_name = 'none', current_date = 'January 1, 2016',24    def __init__(self, customer_name = 'none', current_date = 'January 1, 2016',
> cart_items = []):> cart_items = []):
23        self.customer_name = customer_name25        self.customer_name = customer_name
24        self.current_date = current_date26        self.current_date = current_date
25        self.cart_items = cart_items  27        self.cart_items = cart_items  
26    def add_item(self, itemToPurchase):28    def add_item(self, itemToPurchase):
27        self.cart_items.append(itemToPurchase)  29        self.cart_items.append(itemToPurchase)  
28    def remove_item(self, itemName):30    def remove_item(self, itemName):
n29        tremove_item = Falsen
30        for item in self.cart_items:31        for item in self.cart_items:
31            if item.item_name == itemName:32            if item.item_name == itemName:
32                self.cart_items.remove(item)33                self.cart_items.remove(item)
33                tremove_item = True34                tremove_item = True
34                break35                break
35        if not tremove_item:          36        if not tremove_item:          
n36            print('Item not found in cart. Nothing removed.')n37            print('Item not found in the cart. Nothing removed')
37    def modify_item(self, itemToPurchase):  38    def modify_item(self, itemToPurchase):  
38        tmodify_item = False39        tmodify_item = False
39        for i in range(len(self.cart_items)):40        for i in range(len(self.cart_items)):
40            if self.cart_items[i].item_name == itemToPurchase.item_name:41            if self.cart_items[i].item_name == itemToPurchase.item_name:
41                tmodify_item = True42                tmodify_item = True
42                self.cart_items[i].item_quantity = itemToPurchase.item_quantity43                self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43                break44                break
44        if not tmodify_item:      45        if not tmodify_item:      
n45            print('Item not found in cart. Nothing modified.')  n46            print('Item not found in the cart. Nothing modified')  
46    def get_num_items_in_cart(self):47    def get_num_items_in_cart(self):
47        num_items = 048        num_items = 0
48        for item in self.cart_items:49        for item in self.cart_items:
49            num_items = num_items + item.item_quantity50            num_items = num_items + item.item_quantity
50        return num_items51        return num_items
51    def get_cost_of_cart(self):52    def get_cost_of_cart(self):
52        total_cost = 053        total_cost = 0
53        cost = 054        cost = 0
54        for item in self.cart_items:55        for item in self.cart_items:
55            cost = (item.item_quantity * item.item_price)56            cost = (item.item_quantity * item.item_price)
56            total_cost += cost57            total_cost += cost
57        return total_cost58        return total_cost
58    def print_total(self):59    def print_total(self):
59        total_cost = self.get_cost_of_cart()60        total_cost = self.get_cost_of_cart()
60        if (total_cost == 0):61        if (total_cost == 0):
61            print('SHOPPING CART IS EMPTY')62            print('SHOPPING CART IS EMPTY')
62        else:63        else:
63            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur64            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur
>rent_date))>rent_date))
64            print('Number of Items: %d\n' %self.get_num_items_in_cart())65            print('Number of Items: %d\n' %self.get_num_items_in_cart())
65            for item in self.cart_items:66            for item in self.cart_items:
66                total = item.item_price * item.item_quantity67                total = item.item_price * item.item_quantity
67                print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity,68                print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity,
> item.item_price, total))> item.item_price, total))
68            print('\nTotal: $%d' %(total_cost))69            print('\nTotal: $%d' %(total_cost))
69    def print_descriptions(self):70    def print_descriptions(self):
70        if len(self.cart_items) == 0:71        if len(self.cart_items) == 0:
71            print('SHOPPING CART IS EMPTY')72            print('SHOPPING CART IS EMPTY')
72        else:  73        else:  
73            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur74            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur
>rent_date))>rent_date))
74            print('\nItem Descriptions')75            print('\nItem Descriptions')
75            for item in self.cart_items:76            for item in self.cart_items:
n76                item.print_item_description()  n77               item.print_item_description()  
77def print_menu(newCart=' '):78def print_menu(newCart):
78    customer_Cart = newCart79    customer_Cart = newCart
79    menu = ('\nMENU\n'80    menu = ('\nMENU\n'
80        'a - Add item to cart\n'81        'a - Add item to cart\n'
n81        'r - Remove item from cart\n'n82        'r - Remove item from the cart\n'
82        'c - Change item quantity\n'83        'c - Change item quantity\n'
n83        "i - Output items' descriptions\n"n84        "i - Output item's descriptions\n"
84        'o - Output shopping cart\n'85        'o - Output shopping cart\n'
85        'q - Quit\n')86        'q - Quit\n')
86    command = ''87    command = ''
87    while(command != 'q'):88    while(command != 'q'):
88        print(menu)89        print(menu)
n89        command = input('Choose an option:\n')n90        command = input('Choose an option:')
90        while(command != 'a' and command != 'o' and command != 'i' and command !91        while(command != 'a' and command != 'o' and command != 'i' and command !
>= 'q' and command != 'r' and command != 'c'):>= 'q' and command != 'r' and command != 'c'):
91            command = input('Choose an option:\n')92            command = input('Choose an option:\n')
92        if(command == 'a'):93        if(command == 'a'):
93            print("\nADD ITEM TO CART")94            print("\nADD ITEM TO CART")
94            item_name = input('Enter the item name:\n')95            item_name = input('Enter the item name:\n')
95            item_description = input('Enter the item description:\n')96            item_description = input('Enter the item description:\n')
96            item_price = int(input('Enter the item price:\n'))97            item_price = int(input('Enter the item price:\n'))
97            item_quantity = int(input('Enter the item quantity:\n'))98            item_quantity = int(input('Enter the item quantity:\n'))
98            itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity99            itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity
>, item_description)>, item_description)
99            customer_Cart.add_item(itemtoPurchase)100            customer_Cart.add_item(itemtoPurchase)
100        elif(command == 'o'):101        elif(command == 'o'):
n101            print('OUTPUT SHOPPING CART')n102            print('\nOUTPUT SHOPPING CART')
102            customer_Cart.print_total()  103            customer_Cart.print_total()  
103        elif(command == 'i'):104        elif(command == 'i'):
104            print('\nOUTPUT ITEMS\' DESCRIPTIONS')105            print('\nOUTPUT ITEMS\' DESCRIPTIONS')
105            customer_Cart.print_descriptions()106            customer_Cart.print_descriptions()
106        elif(command == 'r'):107        elif(command == 'r'):
107            print('REMOVE ITEM FROM CART')108            print('REMOVE ITEM FROM CART')
n108            itemName = input('Enter name of item to remove:\n')n109            itemName = input('Enter the name of the item to remove :\n')
109            customer_Cart.remove_item(itemName)110            customer_Cart.remove_item(itemName)
110        elif(command == 'c'):111        elif(command == 'c'):
111            print('\nCHANGE ITEM QUANTITY')112            print('\nCHANGE ITEM QUANTITY')
n112            itemName = input('Enter the item name:\n')n113            itemName = input('Enter the name of the item :\n')
113            qty = int(input('Enter the new quantity:\n'))114            qty = int(input('Enter the new quantity :\n'))
114            itemToPurchase = ItemToPurchase(itemName,0,qty)115            itemToPurchase = ItemToPurchase(itemName,0,qty)
115            customer_Cart.modify_item(itemToPurchase)116            customer_Cart.modify_item(itemToPurchase)
116if __name__ == "__main__":117if __name__ == "__main__":
117    customer_name = input("Enter customer's name:\n")118    customer_name = input("Enter customer's name:\n")
118    current_date = input("Enter today's date:\n")119    current_date = input("Enter today's date:\n")
119    print("\nCustomer name: %s" %customer_name)120    print("\nCustomer name: %s" %customer_name)
120    print("Today's date: %s" %current_date)121    print("Today's date: %s" %current_date)
121    newCart = ShoppingCart(customer_name, current_date)122    newCart = ShoppingCart(customer_name, current_date)
n122    print_menu(newCart)  from math import sqrtn123    print_menu(newCart)  
124from math import sqrt
123class pt3d:125class pt3d:
n124    def __init__(self, x=0, y=0, z=0):n126    def __init__(self, x, y, z):
125        self.x = x127        self.x = x
126        self.y = y128        self.y = y
127        self.z = z129        self.z = z
128    def __add__(self, other):130    def __add__(self, other):
129        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)131        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
130    def __sub__(self, other):132    def __sub__(self, other):
131        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot133        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>her.z)**2)>her.z)**2)
132    def __eq__(self, other):134    def __eq__(self, other):
n133        return self.x == other.x and self.y == other.y and self.z == other.zn135        return self.x == other.x & self.y == other.y & self.z == other.z
134    def __str__(self):136    def __str__(self):
t135        return '<{},{},{}>'.format(self.x, self.y, self.z)t137        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
136p1 = pt3d(1, 1, 1)138p1 = pt3d(1, 1, 1)
137p2 = pt3d(2, 2, 2)139p2 = pt3d(2, 2, 2)
138print(p1 + p2)140print(p1 + p2)
139print(p1 - p2)141print(p1 - p2)
140print(p1 == p2)142print(p1 == p2)
141print(p1+p1 == p2)143print(p1+p1 == p2)
142print(p1==p2+pt3d(-1, -1, -1))144print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 32

Student ID: 384, P-Value: 1.64e-03

Nearest Neighbor ID: 478

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle:n2class Circle :
3    def __init__(self,radius):3    def __init__(self,radius):
n4        self.radius=radiusn4        self.radius = radius
5    def area(self):5    def area(self):
n6        return math.pi *self.radius * self.radiusn6        return math.pi*self.radius*self.radius
7    def perimeter(self):7    def perimeter(self):
n8        return 2* math.pi*self.radiusn8        return 2*math.pi*self.radius
9if __name__=='__main__':9if __name__ == '__main__':
10    x = float(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
n13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:n13    print('{:.5f}'.format(NewCircle.perimeter()))
14class ItemToPurchase:
14   def __init__(self, name='none', price=0, quantity=0, description='none'):15   def __init__(self, name='none', price=0, quantity=0, description='none'):
15       self.item_name=name16       self.item_name=name
16       self.item_description=description17       self.item_description=description
17       self.item_price=price18       self.item_price=price
18       self.item_quantity=quantity19       self.item_quantity=quantity
19   def print_item_description(self):20   def print_item_description(self):
20       print('%s: %s' % (self.item_name, self.item_description))21       print('%s: %s' % (self.item_name, self.item_description))
21class ShoppingCart:22class ShoppingCart:
22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 23   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
23       self.customer_name = customer_name24       self.customer_name = customer_name
24       self.current_date = current_date25       self.current_date = current_date
25       self.cart_items = cart_items  26       self.cart_items = cart_items  
26   def add_item(self, itemToPurchase):27   def add_item(self, itemToPurchase):
27       self.cart_items.append(itemToPurchase)  28       self.cart_items.append(itemToPurchase)  
28   def remove_item(self, itemName):29   def remove_item(self, itemName):
29       tremove_item = False30       tremove_item = False
30       for item in self.cart_items:31       for item in self.cart_items:
31           if item.item_name == itemName:32           if item.item_name == itemName:
32               self.cart_items.remove(item)33               self.cart_items.remove(item)
33               tremove_item = True34               tremove_item = True
34               break35               break
35       if not tremove_item:          36       if not tremove_item:          
n36           print('Item not found in cart. Nothing removed.')n37           print('Item not found in the cart. Nothing removed')
37   def modify_item(self, itemToPurchase):  38   def modify_item(self, itemToPurchase):  
38       tmodify_item = False39       tmodify_item = False
39       for i in range(len(self.cart_items)):40       for i in range(len(self.cart_items)):
40           if self.cart_items[i].item_name == itemToPurchase.item_name:41           if self.cart_items[i].item_name == itemToPurchase.item_name:
41               tmodify_item = True42               tmodify_item = True
42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity43               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43               break44               break
44       if not tmodify_item:      45       if not tmodify_item:      
n45           print('Item not found in cart. Nothing modified.')  n46           print('Item not found in the cart. Nothing modified')  
46   def get_num_items_in_cart(self):47   def get_num_items_in_cart(self):
47       num_items = 048       num_items = 0
48       for item in self.cart_items:49       for item in self.cart_items:
49           num_items = num_items + item.item_quantity50           num_items = num_items + item.item_quantity
50       return num_items51       return num_items
51   def get_cost_of_cart(self):52   def get_cost_of_cart(self):
52       total_cost = 053       total_cost = 0
53       cost = 054       cost = 0
54       for item in self.cart_items:55       for item in self.cart_items:
55           cost = (item.item_quantity * item.item_price)56           cost = (item.item_quantity * item.item_price)
56           total_cost += cost57           total_cost += cost
57       return total_cost58       return total_cost
58   def print_total(self):59   def print_total(self):
59       total_cost = self.get_cost_of_cart()60       total_cost = self.get_cost_of_cart()
60       if (total_cost == 0):61       if (total_cost == 0):
61           print('SHOPPING CART IS EMPTY')62           print('SHOPPING CART IS EMPTY')
62       else:63       else:
63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr64           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
64           print('Number of Items: %d\n' %self.get_num_items_in_cart())65           print('Number of Items: %d\n' %self.get_num_items_in_cart())
65           for item in self.cart_items:66           for item in self.cart_items:
66               total = item.item_price * item.item_quantity67               total = item.item_price * item.item_quantity
67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 68               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
68           print('\nTotal: $%d' %(total_cost))69           print('\nTotal: $%d' %(total_cost))
69   def print_descriptions(self):70   def print_descriptions(self):
70       if len(self.cart_items) == 0:71       if len(self.cart_items) == 0:
71           print('SHOPPING CART IS EMPTY')72           print('SHOPPING CART IS EMPTY')
72       else:  73       else:  
73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr74           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
74           print('\nItem Descriptions')75           print('\nItem Descriptions')
75           for item in self.cart_items:76           for item in self.cart_items:
76               item.print_item_description()  77               item.print_item_description()  
77def print_menu(newCart):78def print_menu(newCart):
n78    customer_Cart= newCartn79   customer_Cart = newCart
79    menu = ('\nMENU\n'80   menu = ('\nMENU\n'
80       'a - Add item to cart\n'81       'a - Add item to cart\n'
81       'r - Remove item from cart\n'82       'r - Remove item from cart\n'
82       'c - Change item quantity\n'83       'c - Change item quantity\n'
83       "i - Output items' descriptions\n"84       "i - Output items' descriptions\n"
84       'o - Output shopping cart\n'85       'o - Output shopping cart\n'
85       'q - Quit\n')86       'q - Quit\n')
n86    command = ''n87   command = ''
87    while(command != 'q'):88   while(command != 'q'):
88       print(menu)89       print(menu)
89       command = input('Choose an option:\n')90       command = input('Choose an option:\n')
90       while(command != 'a' and command != 'o' and command != 'i' and command !=91       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
91           command = input('Choose an option:\n')92           command = input('Choose an option:\n')
92       if(command == 'a'):93       if(command == 'a'):
93           print("\nADD ITEM TO CART")94           print("\nADD ITEM TO CART")
94           item_name = input('Enter the item name:\n')95           item_name = input('Enter the item name:\n')
95           item_description = input('Enter the item description:\n')96           item_description = input('Enter the item description:\n')
96           item_price = int(input('Enter the item price:\n'))97           item_price = int(input('Enter the item price:\n'))
97           item_quantity = int(input('Enter the item quantity:\n'))98           item_quantity = int(input('Enter the item quantity:\n'))
98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,99           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
99           customer_Cart.add_item(itemtoPurchase)100           customer_Cart.add_item(itemtoPurchase)
100       elif(command == 'o'):101       elif(command == 'o'):
n101           print('OUTPUT SHOPPING CART')n102           print('\nOUTPUT SHOPPING CART')
102           customer_Cart.print_total()  103           customer_Cart.print_total()  
103       elif(command == 'i'):104       elif(command == 'i'):
104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')105           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
105           customer_Cart.print_descriptions()106           customer_Cart.print_descriptions()
106       elif(command == 'r'):107       elif(command == 'r'):
107           print('REMOVE ITEM FROM CART')108           print('REMOVE ITEM FROM CART')
n108           itemName = input('Enter name of item to remove:\n')n109           itemName = input('Enter the name of the item to remove :\n')
109           customer_Cart.remove_item(itemName)110           customer_Cart.remove_item(itemName)
110       elif(command == 'c'):111       elif(command == 'c'):
111           print('\nCHANGE ITEM QUANTITY')112           print('\nCHANGE ITEM QUANTITY')
n112           itemName = input('Enter the item name:\n')n113           itemName = input('Enter the name of the item :\n')
113           qty = int(input('Enter the new quantity:\n'))114           qty = int(input('Enter the new quantity :\n'))
114           itemToPurchase = ItemToPurchase(itemName,0,qty)115           itemToPurchase = ItemToPurchase(itemName,0,qty)
115           customer_Cart.modify_item(itemToPurchase)116           customer_Cart.modify_item(itemToPurchase)
116if __name__ == "__main__":117if __name__ == "__main__":
117   customer_name = input("Enter customer's name:\n")118   customer_name = input("Enter customer's name:\n")
118   current_date = input("Enter today's date:\n")119   current_date = input("Enter today's date:\n")
119   print("\nCustomer name: %s" %customer_name)120   print("\nCustomer name: %s" %customer_name)
120   print("Today's date: %s" %current_date)121   print("Today's date: %s" %current_date)
121   newCart = ShoppingCart(customer_name, current_date)122   newCart = ShoppingCart(customer_name, current_date)
n122   print_menu(newCart)  import math n123   print_menu(newCart)import math
123class pt3d:124class pt3d:
124    def __init__(self,x=0,y=0,z=0):125    def __init__(self,x=0,y=0,z=0):
n125        self.x = xn126        self.x= x
126        self.y = y127        self.y= y
127        self.z = z128        self.z= z
128    def __add__(self, other):129    def __add__(self, other):
129        x = self.x + other.x130        x = self.x + other.x
130        y = self.y + other.y131        y = self.y + other.y
131        z = self.z + other.z132        z = self.z + other.z
n132        return pt3d(x,y,z)n133        return pt3d(x, y,z)
133    def __sub__(self, other):134    def __sub__(self, other):
134        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 135        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>2)+math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
135    def __eq__(self, other):136    def __eq__(self, other):
136        return other.x==self.x and other.y==self.y and other.z==self.z137        return other.x==self.x and other.y==self.y and other.z==self.z
137    def __str__(self):138    def __str__(self):
t138        return '<{0},{1},{2}>'.format(self.x, self.y, self.z)t139        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
140if __name__ == '__main__':
139p1 = pt3d(1, 1, 1)141    p1 = pt3d(1, 1, 1)
140p2 = pt3d(2, 2, 2)142    p2 = pt3d(2, 2, 2)
141print(p1 + p2)143    print(p1+p2)
142print(p1 - p2)144    print(p1-p2)
143print(p1 == p2)145    print(p1==p2)
144print(p1+p1 == p2)146    print(p1+p1==p2)
145print(p1==p2+pt3d(-1, -1, -1))147    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 33

Student ID: 299, P-Value: 1.64e-03

Nearest Neighbor ID: 419

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self,x):n3    def __init__(self,radius):
4        self.x= x4        self.radius = radius
5    def area(self):5    def area(self):
n6        area=(math.pi*(self.x**2))n6        return math.pi * self.radius**2
7        return area
8    def perimeter(self):7    def perimeter(self):
n9        perimeter =2*math.pi*self.xn8        return 2 * math.pi * self.radius
10        return perimeter
11if __name__=='__main__':9if __name__=='__main__':
12    x = int(input())10    x = int(input())
13    NewCircle = Circle(x)11    NewCircle = Circle(x)
n14    print(NewCircle.area())n12    print('{:.5f}'.format(NewCircle.area()))
15    print(NewCircle.perimeter())class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
16    def __init__(self, name='none', price=0, quantity=0, description='none'):14    def __init__(self, name='none', price=0, quantity=0, description='none'):
17        self.item_name=name15        self.item_name=name
18        self.item_description=description16        self.item_description=description
19        self.item_price=price17        self.item_price=price
20        self.item_quantity=quantity18        self.item_quantity=quantity
21    def print_item_description(self):19    def print_item_description(self):
n22       print('%s: %s' % (self.item_name, self.item_description))n20        print('%s: %s' % (self.item_name, self.item_description))
23class ShoppingCart:21class ShoppingCart:
24    def __init__(self, customer_name = 'none', current_date = 'January 1, 2016',22    def __init__(self, customer_name = 'none', current_date = 'January 1, 2016',
> cart_items = []):> cart_items = []):
25        self.customer_name = customer_name23        self.customer_name = customer_name
26        self.current_date = current_date24        self.current_date = current_date
27        self.cart_items = cart_items  25        self.cart_items = cart_items  
28    def add_item(self, itemToPurchase):26    def add_item(self, itemToPurchase):
29        self.cart_items.append(itemToPurchase)  27        self.cart_items.append(itemToPurchase)  
30    def remove_item(self, itemName):28    def remove_item(self, itemName):
nn29        tremove_item = False
31        for item in self.cart_items:30        for item in self.cart_items:
32            if item.item_name == itemName:31            if item.item_name == itemName:
33                self.cart_items.remove(item)32                self.cart_items.remove(item)
34                tremove_item = True33                tremove_item = True
35                break34                break
36        if not tremove_item:          35        if not tremove_item:          
n37            print('Item not found in the cart. Nothing removed')n36            print('Item not found in cart. Nothing removed.')
38    def modify_item(self, itemToPurchase):  37    def modify_item(self, itemToPurchase):  
39        tmodify_item = False38        tmodify_item = False
40        for i in range(len(self.cart_items)):39        for i in range(len(self.cart_items)):
41            if self.cart_items[i].item_name == itemToPurchase.item_name:40            if self.cart_items[i].item_name == itemToPurchase.item_name:
42                tmodify_item = True41                tmodify_item = True
43                self.cart_items[i].item_quantity = itemToPurchase.item_quantity42                self.cart_items[i].item_quantity = itemToPurchase.item_quantity
44                break43                break
45        if not tmodify_item:      44        if not tmodify_item:      
n46            print('Item not found in the cart. Nothing modified')  n45            print('Item not found in cart. Nothing modified.')  
47    def get_num_items_in_cart(self):46    def get_num_items_in_cart(self):
48        num_items = 047        num_items = 0
49        for item in self.cart_items:48        for item in self.cart_items:
50            num_items = num_items + item.item_quantity49            num_items = num_items + item.item_quantity
51        return num_items50        return num_items
52    def get_cost_of_cart(self):51    def get_cost_of_cart(self):
53        total_cost = 052        total_cost = 0
54        cost = 053        cost = 0
55        for item in self.cart_items:54        for item in self.cart_items:
56            cost = (item.item_quantity * item.item_price)55            cost = (item.item_quantity * item.item_price)
57            total_cost += cost56            total_cost += cost
58        return total_cost57        return total_cost
59    def print_total(self):58    def print_total(self):
60        total_cost = self.get_cost_of_cart()59        total_cost = self.get_cost_of_cart()
61        if (total_cost == 0):60        if (total_cost == 0):
62            print('SHOPPING CART IS EMPTY')61            print('SHOPPING CART IS EMPTY')
63        else:62        else:
64            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur63            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur
>rent_date))>rent_date))
65            print('Number of Items: %d\n' %self.get_num_items_in_cart())64            print('Number of Items: %d\n' %self.get_num_items_in_cart())
66            for item in self.cart_items:65            for item in self.cart_items:
67                total = item.item_price * item.item_quantity66                total = item.item_price * item.item_quantity
68                print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity,67                print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity,
> item.item_price, total))> item.item_price, total))
69            print('\nTotal: $%d' %(total_cost))68            print('\nTotal: $%d' %(total_cost))
70    def print_descriptions(self):69    def print_descriptions(self):
71        if len(self.cart_items) == 0:70        if len(self.cart_items) == 0:
72            print('SHOPPING CART IS EMPTY')71            print('SHOPPING CART IS EMPTY')
73        else:  72        else:  
74            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur73            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur
>rent_date))>rent_date))
75            print('\nItem Descriptions')74            print('\nItem Descriptions')
76            for item in self.cart_items:75            for item in self.cart_items:
n77               item.print_item_description()  n76                item.print_item_description()  
78def print_menu(newCart):77def print_menu(newCart=' '):
79    customer_Cart = newCart78    customer_Cart = newCart
80    menu = ('\nMENU\n'79    menu = ('\nMENU\n'
81        'a - Add item to cart\n'80        'a - Add item to cart\n'
n82        'r - Remove item from the cart\n'n81        'r - Remove item from cart\n'
83        'c - Change item quantity\n'82        'c - Change item quantity\n'
n84        "i - Output item's descriptions\n"n83        "i - Output items' descriptions\n"
85        'o - Output shopping cart\n'84        'o - Output shopping cart\n'
86        'q - Quit\n')85        'q - Quit\n')
87    command = ''86    command = ''
88    while(command != 'q'):87    while(command != 'q'):
89        print(menu)88        print(menu)
n90        command = input('Choose an option:')n89        command = input('Choose an option:\n')
91        while(command != 'a' and command != 'o' and command != 'i' and command !90        while(command != 'a' and command != 'o' and command != 'i' and command !
>= 'q' and command != 'r' and command != 'c'):>= 'q' and command != 'r' and command != 'c'):
92            command = input('Choose an option:\n')91            command = input('Choose an option:\n')
93        if(command == 'a'):92        if(command == 'a'):
94            print("\nADD ITEM TO CART")93            print("\nADD ITEM TO CART")
95            item_name = input('Enter the item name:\n')94            item_name = input('Enter the item name:\n')
96            item_description = input('Enter the item description:\n')95            item_description = input('Enter the item description:\n')
97            item_price = int(input('Enter the item price:\n'))96            item_price = int(input('Enter the item price:\n'))
98            item_quantity = int(input('Enter the item quantity:\n'))97            item_quantity = int(input('Enter the item quantity:\n'))
99            itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity98            itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity
>, item_description)>, item_description)
100            customer_Cart.add_item(itemtoPurchase)99            customer_Cart.add_item(itemtoPurchase)
101        elif(command == 'o'):100        elif(command == 'o'):
n102            print('\nOUTPUT SHOPPING CART')n101            print('OUTPUT SHOPPING CART')
103            customer_Cart.print_total()  102            customer_Cart.print_total()  
104        elif(command == 'i'):103        elif(command == 'i'):
105            print('\nOUTPUT ITEMS\' DESCRIPTIONS')104            print('\nOUTPUT ITEMS\' DESCRIPTIONS')
106            customer_Cart.print_descriptions()105            customer_Cart.print_descriptions()
107        elif(command == 'r'):106        elif(command == 'r'):
108            print('REMOVE ITEM FROM CART')107            print('REMOVE ITEM FROM CART')
n109            itemName = input('Enter the name of the item to remove :\n')n108            itemName = input('Enter name of item to remove:\n')
110            customer_Cart.remove_item(itemName)109            customer_Cart.remove_item(itemName)
111        elif(command == 'c'):110        elif(command == 'c'):
112            print('\nCHANGE ITEM QUANTITY')111            print('\nCHANGE ITEM QUANTITY')
n113            itemName = input('Enter the name of the item :\n')n112            itemName = input('Enter the item name:\n')
114            qty = int(input('Enter the new quantity :\n'))113            qty = int(input('Enter the new quantity:\n'))
115            itemToPurchase = ItemToPurchase(itemName,0,qty)114            itemToPurchase = ItemToPurchase(itemName,0,qty)
116            customer_Cart.modify_item(itemToPurchase)115            customer_Cart.modify_item(itemToPurchase)
117if __name__ == "__main__":116if __name__ == "__main__":
118    customer_name = input("Enter customer's name:\n")117    customer_name = input("Enter customer's name:\n")
119    current_date = input("Enter today's date:\n")118    current_date = input("Enter today's date:\n")
120    print("\nCustomer name: %s" %customer_name)119    print("\nCustomer name: %s" %customer_name)
121    print("Today's date: %s" %current_date)120    print("Today's date: %s" %current_date)
122    newCart = ShoppingCart(customer_name, current_date)121    newCart = ShoppingCart(customer_name, current_date)
n123    print_menu(newCart)  n122    print_menu(newCart)  from math import sqrt
124from math import sqrt
125class pt3d:123class pt3d:
n126    def __init__(self, x, y, z):n124    def __init__(self, x=0, y=0, z=0):
127        self.x = x125        self.x = x
128        self.y = y126        self.y = y
129        self.z = z127        self.z = z
130    def __add__(self, other):128    def __add__(self, other):
131        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)129        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
132    def __sub__(self, other):130    def __sub__(self, other):
133        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot131        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>her.z)**2)>her.z)**2)
134    def __eq__(self, other):132    def __eq__(self, other):
n135        return self.x == other.x & self.y == other.y & self.z == other.zn133        return self.x == other.x and self.y == other.y and self.z == other.z
136    def __str__(self):134    def __str__(self):
t137        return '<{}, {}, {}>'.format(self.x, self.y, self.z)t135        return '<{},{},{}>'.format(self.x, self.y, self.z)
138p1 = pt3d(1, 1, 1)136p1 = pt3d(1, 1, 1)
139p2 = pt3d(2, 2, 2)137p2 = pt3d(2, 2, 2)
140print(p1 + p2)138print(p1 + p2)
141print(p1 - p2)139print(p1 - p2)
142print(p1 == p2)140print(p1 == p2)
143print(p1+p1 == p2)141print(p1+p1 == p2)
144print(p1==p2+pt3d(-1, -1, -1))142print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 34

Student ID: 73, P-Value: 2.08e-03

Nearest Neighbor ID: 492

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self, radius):n3    def __init__(self, rad):
4        self.radius = radius4        self.radius = rad
5    def area(self):5    def area(self):
n6        return math.pi * self.radius * self.radiusn6        return (self.radius**2)*math.pi
7    def perimeter(self):7    def perimeter(self):
n8        return 2 * math.pi * self.radiusn8        return self.radius*2*math.pi
9if __name__=='__main__':9if __name__ == '__main__':
10    x = int(input(''))10    x = int(input(""))
11    NewCircle = Circle(x)11    NewCircle = circle(x)
12    print(NewCircle.area())12    print(NewCircle.area())
13    print(NewCircle.perimeter())class ItemToPurchase:13    print(NewCircle.perimeter())class ItemToPurchase:
14   def __init__(self, name='none', price=0, quantity=0, description='none'):14   def __init__(self, name='none', price=0, quantity=0, description='none'):
15       self.item_name=name15       self.item_name=name
16       self.item_description=description16       self.item_description=description
17       self.item_price=price17       self.item_price=price
18       self.item_quantity=quantity18       self.item_quantity=quantity
19   def print_item_description(self):19   def print_item_description(self):
20       print('%s: %s' % (self.item_name, self.item_description))20       print('%s: %s' % (self.item_name, self.item_description))
21class ShoppingCart:21class ShoppingCart:
22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
23       self.customer_name = customer_name23       self.customer_name = customer_name
24       self.current_date = current_date24       self.current_date = current_date
25       self.cart_items = cart_items  25       self.cart_items = cart_items  
26   def add_item(self, itemToPurchase):26   def add_item(self, itemToPurchase):
27       self.cart_items.append(itemToPurchase)  27       self.cart_items.append(itemToPurchase)  
28   def remove_item(self, itemName):28   def remove_item(self, itemName):
29       tremove_item = False29       tremove_item = False
30       for item in self.cart_items:30       for item in self.cart_items:
31           if item.item_name == itemName:31           if item.item_name == itemName:
32               self.cart_items.remove(item)32               self.cart_items.remove(item)
33               tremove_item = True33               tremove_item = True
34               break34               break
35       if not tremove_item:          35       if not tremove_item:          
36           print('Item not found in cart. Nothing removed.')36           print('Item not found in cart. Nothing removed.')
37   def modify_item(self, itemToPurchase):  37   def modify_item(self, itemToPurchase):  
38       tmodify_item = False38       tmodify_item = False
39       for i in range(len(self.cart_items)):39       for i in range(len(self.cart_items)):
40           if self.cart_items[i].item_name == itemToPurchase.item_name:40           if self.cart_items[i].item_name == itemToPurchase.item_name:
41               tmodify_item = True41               tmodify_item = True
42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43               break43               break
44       if not tmodify_item:      44       if not tmodify_item:      
45           print('Item not found in cart. Nothing modified.')  45           print('Item not found in cart. Nothing modified.')  
46   def get_num_items_in_cart(self):46   def get_num_items_in_cart(self):
47       num_items = 047       num_items = 0
48       for item in self.cart_items:48       for item in self.cart_items:
49           num_items = num_items + item.item_quantity49           num_items = num_items + item.item_quantity
50       return num_items50       return num_items
51   def get_cost_of_cart(self):51   def get_cost_of_cart(self):
52       total_cost = 052       total_cost = 0
53       cost = 053       cost = 0
54       for item in self.cart_items:54       for item in self.cart_items:
55           cost = (item.item_quantity * item.item_price)55           cost = (item.item_quantity * item.item_price)
56           total_cost += cost56           total_cost += cost
57       return total_cost57       return total_cost
58   def print_total(self):58   def print_total(self):
59       total_cost = self.get_cost_of_cart()59       total_cost = self.get_cost_of_cart()
60       if (total_cost == 0):60       if (total_cost == 0):
61           print('SHOPPING CART IS EMPTY')61           print('SHOPPING CART IS EMPTY')
62       else:62       else:
63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
64           print('Number of Items: %d\n' %self.get_num_items_in_cart())64           print('Number of Items: %d\n' %self.get_num_items_in_cart())
65           for item in self.cart_items:65           for item in self.cart_items:
66               total = item.item_price * item.item_quantity66               total = item.item_price * item.item_quantity
67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
68           print('\nTotal: $%d' %(total_cost))68           print('\nTotal: $%d' %(total_cost))
69   def print_descriptions(self):69   def print_descriptions(self):
70       if len(self.cart_items) == 0:70       if len(self.cart_items) == 0:
71           print('SHOPPING CART IS EMPTY')71           print('SHOPPING CART IS EMPTY')
72       else:  72       else:  
73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
74           print('\nItem Descriptions')74           print('\nItem Descriptions')
75           for item in self.cart_items:75           for item in self.cart_items:
76               item.print_item_description()  76               item.print_item_description()  
77def print_menu(newCart):77def print_menu(newCart):
78   customer_Cart = newCart78   customer_Cart = newCart
79   menu = ('\nMENU\n'79   menu = ('\nMENU\n'
80       'a - Add item to cart\n'80       'a - Add item to cart\n'
81       'r - Remove item from cart\n'81       'r - Remove item from cart\n'
82       'c - Change item quantity\n'82       'c - Change item quantity\n'
83       "i - Output items' descriptions\n"83       "i - Output items' descriptions\n"
84       'o - Output shopping cart\n'84       'o - Output shopping cart\n'
85       'q - Quit\n')85       'q - Quit\n')
86   command = ''86   command = ''
87   while(command != 'q'):87   while(command != 'q'):
88       print(menu)88       print(menu)
89       command = input('Choose an option:\n')89       command = input('Choose an option:\n')
90       while(command != 'a' and command != 'o' and command != 'i' and command !=90       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
91           command = input('Choose an option:\n')91           command = input('Choose an option:\n')
92       if(command == 'a'):92       if(command == 'a'):
93           print("\nADD ITEM TO CART")93           print("\nADD ITEM TO CART")
94           item_name = input('Enter the item name:\n')94           item_name = input('Enter the item name:\n')
95           item_description = input('Enter the item description:\n')95           item_description = input('Enter the item description:\n')
96           item_price = int(input('Enter the item price:\n'))96           item_price = int(input('Enter the item price:\n'))
97           item_quantity = int(input('Enter the item quantity:\n'))97           item_quantity = int(input('Enter the item quantity:\n'))
98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
99           customer_Cart.add_item(itemtoPurchase)99           customer_Cart.add_item(itemtoPurchase)
100       elif(command == 'o'):100       elif(command == 'o'):
101           print('OUTPUT SHOPPING CART')101           print('OUTPUT SHOPPING CART')
102           customer_Cart.print_total()  102           customer_Cart.print_total()  
103       elif(command == 'i'):103       elif(command == 'i'):
104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
105           customer_Cart.print_descriptions()105           customer_Cart.print_descriptions()
106       elif(command == 'r'):106       elif(command == 'r'):
107           print('REMOVE ITEM FROM CART')107           print('REMOVE ITEM FROM CART')
108           itemName = input('Enter name of item to remove:\n')108           itemName = input('Enter name of item to remove:\n')
109           customer_Cart.remove_item(itemName)109           customer_Cart.remove_item(itemName)
110       elif(command == 'c'):110       elif(command == 'c'):
111           print('\nCHANGE ITEM QUANTITY')111           print('\nCHANGE ITEM QUANTITY')
n112           itemName = input('Enter the item name:\n')n112           itemName = input('Enter name of item :\n')
113           qty = int(input('Enter the new quantity:\n'))113           qty = int(input('Enter the new quantity :\n'))
114           itemToPurchase = ItemToPurchase(itemName,0,qty)114           itemToPurchase = ItemToPurchase(itemName,0,qty)
115           customer_Cart.modify_item(itemToPurchase)115           customer_Cart.modify_item(itemToPurchase)
116if __name__ == "__main__":116if __name__ == "__main__":
117   customer_name = input("Enter customer's name:\n")117   customer_name = input("Enter customer's name:\n")
118   current_date = input("Enter today's date:\n")118   current_date = input("Enter today's date:\n")
119   print("\nCustomer name: %s" %customer_name)119   print("\nCustomer name: %s" %customer_name)
120   print("Today's date: %s" %current_date)120   print("Today's date: %s" %current_date)
121   newCart = ShoppingCart(customer_name, current_date)121   newCart = ShoppingCart(customer_name, current_date)
122   print_menu(newCart)  import math122   print_menu(newCart)  import math
123class pt3d:123class pt3d:
124    def __init__(self,x=0,y=0,z=0):124    def __init__(self,x=0,y=0,z=0):
n125        self.x=xn125        self.x= x
126        self.y=y126        self.y= y
127        self.z=z127        self.z= z
128    def __add__(self, ab):128    def __add__(self, other):
129        x =self.x +ab.x129        x = self.x + other.x
130        y =self.y +ab.y130        y = self.y + other.y
131        z =self.z +ab.z131        z = self.z + other.z
132        return pt3d(x,y,z)132        return pt3d(x, y,z)
133    def __sub__(self, ap):133    def __sub__(self, other):
134        return math.sqrt(math.pow(ap.x-self.x, 2) + math.pow(ap.y-self.y, 2) + m134        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>ath.pow(ap.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
135    def __eq__(self, ap):135    def __eq__(self, other):
136        return ap.x==self.x and ap.y==self.y and ap.z==self.z136        return other.x==self.x and other.y==self.y and other.z==self.z
137    def __str__(self):137    def __str__(self):
138        return "<{0},{1},{2}>".format(self.x, self.y, self.z)138        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
t139if __name__== '__main__':t139if __name__ == '__main__':
140    p1 = pt3d(1, 1, 1)140    p1 = pt3d(1, 1, 1)
141    p2 = pt3d(2, 2, 2)141    p2 = pt3d(2, 2, 2)
142    print(p1+p2)142    print(p1+p2)
143    print(p1-p2)143    print(p1-p2)
144    print(p1==p2)144    print(p1==p2)
145    print(p1+p1==p2)145    print(p1+p1==p2)
146    print(p1==p2+pt3d(-1,-1,-1))146    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 35

Student ID: 218, P-Value: 2.19e-03

Nearest Neighbor ID: 88

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
3    def __init__(self, radius):3    def __init__(self, radius):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
n6        area = math.pi*self.radius**2n6        return math.pi*(self.radius**2)
7        return area
8    def perimeter(self):7    def perimeter(self):
n9        perimeter =  2*math.pi*self.radiusn8        return 2*math.pi*self.radius
10        return perimeter
11if __name__=='__main__':9if __name__=='__main__':
12    x = int(input())10    x = int(input())
13    NewCircle = Circle(x)11    NewCircle = Circle(x)
14    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
15    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
16   def __init__(self, name='none', price=0, quantity=0, description='none'):14   def __init__(self, name='none', price=0, quantity=0, description='none'):
17       self.item_name=name15       self.item_name=name
18       self.item_description=description16       self.item_description=description
19       self.item_price=price17       self.item_price=price
20       self.item_quantity=quantity18       self.item_quantity=quantity
21   def print_item_description(self):19   def print_item_description(self):
22       print('%s: %s' % (self.item_name, self.item_description))20       print('%s: %s' % (self.item_name, self.item_description))
23class ShoppingCart:21class ShoppingCart:
24   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
25       self.customer_name = customer_name23       self.customer_name = customer_name
26       self.current_date = current_date24       self.current_date = current_date
27       self.cart_items = cart_items  25       self.cart_items = cart_items  
28   def add_item(self, itemToPurchase):26   def add_item(self, itemToPurchase):
29       self.cart_items.append(itemToPurchase)  27       self.cart_items.append(itemToPurchase)  
30   def remove_item(self, itemName):28   def remove_item(self, itemName):
31       tremove_item = False29       tremove_item = False
32       for item in self.cart_items:30       for item in self.cart_items:
33           if item.item_name == itemName:31           if item.item_name == itemName:
34               self.cart_items.remove(item)32               self.cart_items.remove(item)
35               tremove_item = True33               tremove_item = True
36               break34               break
37       if not tremove_item:          35       if not tremove_item:          
n38           print('Item not found in the cart. Nothing removed')n36           print('Item not found in the cart. Nothing removed.')
39   def modify_item(self, itemToPurchase):  37   def modify_item(self, itemToPurchase):  
40       tmodify_item = False38       tmodify_item = False
41       for i in range(len(self.cart_items)):39       for i in range(len(self.cart_items)):
42           if self.cart_items[i].item_name == itemToPurchase.item_name:40           if self.cart_items[i].item_name == itemToPurchase.item_name:
43               tmodify_item = True41               tmodify_item = True
44               self.cart_items[i].item_quantity = itemToPurchase.item_quantity42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
45               break43               break
46       if not tmodify_item:      44       if not tmodify_item:      
n47           print('Item not found in the cart. Nothing modified')  n45           print('Item not found in the cart. Nothing modified.')  
48   def get_num_items_in_cart(self):46   def get_num_items_in_cart(self):
49       num_items = 047       num_items = 0
50       for item in self.cart_items:48       for item in self.cart_items:
51           num_items = num_items + item.item_quantity49           num_items = num_items + item.item_quantity
52       return num_items50       return num_items
53   def get_cost_of_cart(self):51   def get_cost_of_cart(self):
54       total_cost = 052       total_cost = 0
55       cost = 053       cost = 0
56       for item in self.cart_items:54       for item in self.cart_items:
57           cost = (item.item_quantity * item.item_price)55           cost = (item.item_quantity * item.item_price)
58           total_cost += cost56           total_cost += cost
59       return total_cost57       return total_cost
60   def print_total(self):58   def print_total(self):
61       total_cost = self.get_cost_of_cart()59       total_cost = self.get_cost_of_cart()
62       if (total_cost == 0):60       if (total_cost == 0):
63           print('SHOPPING CART IS EMPTY')61           print('SHOPPING CART IS EMPTY')
64       else:62       else:
65           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
66           print('Number of Items: %d\n' %self.get_num_items_in_cart())64           print('Number of Items: %d\n' %self.get_num_items_in_cart())
67           for item in self.cart_items:65           for item in self.cart_items:
68               total = item.item_price * item.item_quantity66               total = item.item_price * item.item_quantity
69               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
70           print('\nTotal: $%d' %(total_cost))68           print('\nTotal: $%d' %(total_cost))
71   def print_descriptions(self):69   def print_descriptions(self):
72       if len(self.cart_items) == 0:70       if len(self.cart_items) == 0:
73           print('SHOPPING CART IS EMPTY')71           print('SHOPPING CART IS EMPTY')
74       else:  72       else:  
75           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
76           print('\nItem Descriptions')74           print('\nItem Descriptions')
77           for item in self.cart_items:75           for item in self.cart_items:
78               item.print_item_description()  76               item.print_item_description()  
79def print_menu(newCart):77def print_menu(newCart):
80   customer_Cart = newCart78   customer_Cart = newCart
81   menu = ('\nMENU\n'79   menu = ('\nMENU\n'
82       'a - Add item to cart\n'80       'a - Add item to cart\n'
n83       'r - Remove item from the cart\n'n81       'r - Remove item from cart\n'
84       'c - Change item quantity\n'82       'c - Change item quantity\n'
n85       "i - Output item's descriptions\n"n83       "i - Output items' descriptions\n"
86       'o - Output shopping cart\n'84       'o - Output shopping cart\n'
87       'q - Quit\n')85       'q - Quit\n')
88   command = ''86   command = ''
89   while(command != 'q'):87   while(command != 'q'):
90       print(menu)88       print(menu)
n91       command = input('Choose an option:')n89       command = input('Choose an option:\n')
92       while(command != 'a' and command != 'o' and command != 'i' and command !=90       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
93           command = input('Choose an option:\n')91           command = input('Choose an option:\n')
94       if(command == 'a'):92       if(command == 'a'):
95           print("\nADD ITEM TO CART")93           print("\nADD ITEM TO CART")
96           item_name = input('Enter the item name:\n')94           item_name = input('Enter the item name:\n')
97           item_description = input('Enter the item description:\n')95           item_description = input('Enter the item description:\n')
98           item_price = int(input('Enter the item price:\n'))96           item_price = int(input('Enter the item price:\n'))
99           item_quantity = int(input('Enter the item quantity:\n'))97           item_quantity = int(input('Enter the item quantity:\n'))
100           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
101           customer_Cart.add_item(itemtoPurchase)99           customer_Cart.add_item(itemtoPurchase)
102       elif(command == 'o'):100       elif(command == 'o'):
103           print('\nOUTPUT SHOPPING CART')101           print('\nOUTPUT SHOPPING CART')
104           customer_Cart.print_total()  102           customer_Cart.print_total()  
105       elif(command == 'i'):103       elif(command == 'i'):
106           print('\nOUTPUT ITEMS\' DESCRIPTIONS')104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
107           customer_Cart.print_descriptions()105           customer_Cart.print_descriptions()
108       elif(command == 'r'):106       elif(command == 'r'):
109           print('REMOVE ITEM FROM CART')107           print('REMOVE ITEM FROM CART')
n110           itemName = input('Enter the name of the item to remove :\n')n108           itemName = input('Enter name of item to remove :\n')
111           customer_Cart.remove_item(itemName)109           customer_Cart.remove_item(itemName)
112       elif(command == 'c'):110       elif(command == 'c'):
113           print('\nCHANGE ITEM QUANTITY')111           print('\nCHANGE ITEM QUANTITY')
n114           itemName = input('Enter the name of the item :\n')n112           itemName = input('Enter name of item :\n')
115           qty = int(input('Enter the new quantity :\n'))113           qty = int(input('Enter the new quantity :\n'))
116           itemToPurchase = ItemToPurchase(itemName,0,qty)114           itemToPurchase = ItemToPurchase(itemName,0,qty)
117           customer_Cart.modify_item(itemToPurchase)115           customer_Cart.modify_item(itemToPurchase)
118if __name__ == "__main__":116if __name__ == "__main__":
119   customer_name = input("Enter customer's name:\n")117   customer_name = input("Enter customer's name:\n")
120   current_date = input("Enter today's date:\n")118   current_date = input("Enter today's date:\n")
121   print("\nCustomer name: %s" %customer_name)119   print("\nCustomer name: %s" %customer_name)
122   print("Today's date: %s" %current_date)120   print("Today's date: %s" %current_date)
123   newCart = ShoppingCart(customer_name, current_date)121   newCart = ShoppingCart(customer_name, current_date)
n124   print_menu(newCart)  n122   print_menu(newCart)from math import sqrt
125from math import sqrt
126class pt3d: 123class pt3d:
127    def init(self, x=0, y=0, z=0):124    def __init__(self, x, y, z):
128        self.x = x125        self.x = x
129        self.y = y126        self.y = y
t130        self.z = z t127        self.z = z
131    def add(self, other):128    def __add__(self, other):
132        points = pt3d(self.x+other.x,self.y+other.y,self.z+other.z)129        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
133        return points 
134    def sub(self, other):130    def __sub__(self, other):
135        points = sqrt((self.x-other.x)2+(self.y-other.y)2+(self.z-other.z)**2)131        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
 >her.z)**2)
136        return points 
137    def eq(self, other):132    def __eq__(self, other):
138        return self.x == other.x and self.y == other.y and self.z == other.z 133        return self.x == other.x and self.y == other.y and self.z == other.z
139    def str(self):134    def __str__(self):
140        return '<{},{},{}>'.format(self.x, self.y, self.z) 135        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
141p1 = pt3d(1, 1, 1)136p1 = pt3d(1, 1, 1)
142p2 = pt3d(2, 2, 2)137p2 = pt3d(2, 2, 2)
143print(p1 + p2)138print(p1 + p2)
144print(p1 - p2)139print(p1 - p2)
145print(p1 == p2)140print(p1 == p2)
146print(p1+p1 == p2)141print(p1+p1 == p2)
147print(p1==p2+pt3d(-1, -1, -1))142print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 36

Student ID: 105, P-Value: 2.62e-03

Nearest Neighbor ID: 183

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle:n2class Circle():
3def __init__(self, radius):3    def __init__(self, radius):
4self.radius = int(radius)4        self.radius = radius
5def area(self):5    def area(self):
6return round(math.pi*self.radius*self.radius,3)6        return math.pi * self.radius**2
7def perimeter(self):7    def perimeter(self):
8return round(2*math.pi*self.radius,3)8        return 2 * math.pi * self.radius
9circle=Circle(2)9if __name__=='__main__':
10print("Area of circle=",circle.area())10    x = int(input())
11print("Perimeter of circle=",circle.perimeter())class ItemToPurchase:11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
12    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des14    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des
>cription='none'):>cription='none'):
13        self.item_name = item_name15        self.item_name = item_name
14        self.item_price = item_price16        self.item_price = item_price
15        self.item_quantity = item_quantity17        self.item_quantity = item_quantity
16        self.item_description = item_description18        self.item_description = item_description
17    def print_item_cost(self):19    def print_item_cost(self):
18        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, 20        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, 
>self.item_price,>self.item_price,
19                                            (self.item_quantity * self.item_pric21                                            (self.item_quantity * self.item_pric
>e))>e))
20        cost = self.item_quantity * self.item_price22        cost = self.item_quantity * self.item_price
21        return string, cost23        return string, cost
22    def print_item_description(self):24    def print_item_description(self):
23        string = '{}: {}'.format(self.item_name, self.item_description)25        string = '{}: {}'.format(self.item_name, self.item_description)
24        print(string, end='\n')26        print(string, end='\n')
25        return string27        return string
26class ShoppingCart:28class ShoppingCart:
27    def __init__(self, customer_name='none', current_date='January 1, 2016', car29    def __init__(self, customer_name='none', current_date='January 1, 2016', car
>t_items=[]):>t_items=[]):
28        self.customer_name = customer_name30        self.customer_name = customer_name
29        self.current_date = current_date31        self.current_date = current_date
30        self.cart_items = cart_items32        self.cart_items = cart_items
31    def add_item(self, string):33    def add_item(self, string):
32        print('\nADD ITEM TO CART', end='\n')34        print('\nADD ITEM TO CART', end='\n')
33        item_name = str(input('Enter the item name: '))35        item_name = str(input('Enter the item name: '))
34        item_description = str(input('\nEnter the item description: '))36        item_description = str(input('\nEnter the item description: '))
35        item_price = int(input('\nEnter the item price: '))37        item_price = int(input('\nEnter the item price: '))
36        item_quantity = int(input('\nEnter the item quantity: '))38        item_quantity = int(input('\nEnter the item quantity: '))
37        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti39        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti
>ty, item_description))>ty, item_description))
38    def remove_item(self):40    def remove_item(self):
39        print('\nREMOVE ITEM FROM CART', end='\n')41        print('\nREMOVE ITEM FROM CART', end='\n')
40        string = str(input('Enter name of item to remove: '))42        string = str(input('Enter name of item to remove: '))
41        i = 043        i = 0
42        for item in self.cart_items:44        for item in self.cart_items:
43            if (item.item_name == string):45            if (item.item_name == string):
44                del self.cart_items[i]46                del self.cart_items[i]
45                i += 147                i += 1
46                flag = True48                flag = True
47                break49                break
48            else:50            else:
49                flag = False51                flag = False
50        if (flag == False):52        if (flag == False):
51            print('Item not found in cart. Nothing removed')53            print('Item not found in cart. Nothing removed')
52    def modify_item(self):54    def modify_item(self):
53        print('\nCHANGE ITEM QUANTITY', end='\n')55        print('\nCHANGE ITEM QUANTITY', end='\n')
54        name = str(input('Enter the item name: '))56        name = str(input('Enter the item name: '))
55        for item in self.cart_items:57        for item in self.cart_items:
56            if (item.item_name == name):58            if (item.item_name == name):
57                quantity = int(input('Enter the new quantity: '))59                quantity = int(input('Enter the new quantity: '))
58                item.item_quantity = quantity60                item.item_quantity = quantity
59                flag = True61                flag = True
60                break62                break
61            else:63            else:
62                flag = False64                flag = False
63        if (flag == False):65        if (flag == False):
64            print('Item not found in cart. Nothing modified')66            print('Item not found in cart. Nothing modified')
65    def get_num_items_in_cart(self):67    def get_num_items_in_cart(self):
66        num_items = 068        num_items = 0
67        for item in self.cart_items:69        for item in self.cart_items:
68            num_items = num_items + item.item_quantity70            num_items = num_items + item.item_quantity
69        return num_items71        return num_items
70    def get_cost_of_cart(self):72    def get_cost_of_cart(self):
71        total_cost = 073        total_cost = 0
72        cost = 074        cost = 0
73        for item in self.cart_items:75        for item in self.cart_items:
74            cost = (item.item_quantity * item.item_price)76            cost = (item.item_quantity * item.item_price)
75            total_cost += cost77            total_cost += cost
76        return total_cost78        return total_cost
77    def print_total(self):79    def print_total(self):
78        total_cost = self.get_cost_of_cart()80        total_cost = self.get_cost_of_cart()
79        if (total_cost == 0):81        if (total_cost == 0):
80            print('SHOPPING CART IS EMPTY')82            print('SHOPPING CART IS EMPTY')
81        else:83        else:
82            self.output_cart()84            self.output_cart()
83    def print_descriptions(self):85    def print_descriptions(self):
84        print('\nOUTPUT ITEMS\' DESCRIPTIONS')86        print('\nOUTPUT ITEMS\' DESCRIPTIONS')
85        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current87        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date), end='\n')>_date), end='\n')
86        print('\nItem Descriptions', end='\n')88        print('\nItem Descriptions', end='\n')
87        for item in self.cart_items:89        for item in self.cart_items:
88            print('{}: {}'.format(item.item_name, item.item_description), end='\90            print('{}: {}'.format(item.item_name, item.item_description), end='\
>n')>n')
89    def output_cart(self):91    def output_cart(self):
90        new = ShoppingCart()92        new = ShoppingCart()
91        print('\nOUTPUT SHOPPING CART', end='\n')93        print('\nOUTPUT SHOPPING CART', end='\n')
92        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current94        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date), end='\n')>_date), end='\n')
93        print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')95        print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')
94        tc = 096        tc = 0
95        for item in self.cart_items:97        for item in self.cart_items:
96            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,98            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,
97                                             item.item_price, (item.item_quantit99                                             item.item_price, (item.item_quantit
>y * item.item_price)), end='\n')>y * item.item_price)), end='\n')
98            tc += (item.item_quantity * item.item_price)100            tc += (item.item_quantity * item.item_price)
99        print('\nTotal: ${}'.format(tc), end='\n')101        print('\nTotal: ${}'.format(tc), end='\n')
100def print_menu(ShoppingCart):102def print_menu(ShoppingCart):
101    customer_Cart = newCart103    customer_Cart = newCart
102    string = ''104    string = ''
103    menu = ('\nMENU\n'105    menu = ('\nMENU\n'
104            'a - Add item to cart\n'106            'a - Add item to cart\n'
105            'r - Remove item from cart\n'107            'r - Remove item from cart\n'
106            'c - Change item quantity\n'108            'c - Change item quantity\n'
107            'i - Output items\' descriptions\n'109            'i - Output items\' descriptions\n'
108            'o - Output shopping cart\n'110            'o - Output shopping cart\n'
109            'q - Quit\n')111            'q - Quit\n')
110    command = ''112    command = ''
111    while (command != 'q'):113    while (command != 'q'):
112        string = ''114        string = ''
113        print(menu, end='\n')115        print(menu, end='\n')
114        command = input('Choose an option: ')116        command = input('Choose an option: ')
115        while (command != 'a' and command != 'o' and command != 'i' and command 117        while (command != 'a' and command != 'o' and command != 'i' and command 
>!= 'r'>!= 'r'
116               and command != 'c' and command != 'q'):118               and command != 'c' and command != 'q'):
117            command = input('Choose an option: ')119            command = input('Choose an option: ')
118        if (command == 'a'):120        if (command == 'a'):
119            customer_Cart.add_item(string)121            customer_Cart.add_item(string)
120        if (command == 'o'):122        if (command == 'o'):
121            customer_Cart.output_cart()123            customer_Cart.output_cart()
122        if (command == 'i'):124        if (command == 'i'):
123            customer_Cart.print_descriptions()125            customer_Cart.print_descriptions()
124        if (command == 'r'):126        if (command == 'r'):
125            customer_Cart.remove_item()127            customer_Cart.remove_item()
126        if (command == 'c'):128        if (command == 'c'):
127            customer_Cart.modify_item()129            customer_Cart.modify_item()
128customer_name = str(input('Enter customer\'s name: '))130customer_name = str(input('Enter customer\'s name: '))
129current_date = str(input('\nEnter today\'s date: '))131current_date = str(input('\nEnter today\'s date: '))
130print('Customer name:', customer_name, end='\n')132print('Customer name:', customer_name, end='\n')
131print('Today\'s date:', current_date, end='\n')133print('Today\'s date:', current_date, end='\n')
132newCart = ShoppingCart(customer_name, current_date)134newCart = ShoppingCart(customer_name, current_date)
133print_menu(newCart)from math import sqrt135print_menu(newCart)from math import sqrt
134class pt3d:136class pt3d:
n135    def __init__(self, x, y, z):n137    def __init__(self, x=0, y=0, z=0):
136        self.x = x138        self.x = x
137        self.y = y139        self.y = y
138        self.z = z140        self.z = z
139    def __add__(self, other):141    def __add__(self, other):
140        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)142        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
141    def __sub__(self, other):143    def __sub__(self, other):
142        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot144        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>her.z)**2)>her.z)**2)
143    def __eq__(self, other):145    def __eq__(self, other):
144        return self.x == other.x & self.y == other.y & self.z == other.z146        return self.x == other.x & self.y == other.y & self.z == other.z
145    def __str__(self):147    def __str__(self):
146        return '<{}, {}, {}>'.format(self.x, self.y, self.z)148        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
tt149if __name__ == '__main__':
147p1 = pt3d(1, 1, 1)150    p1 = pt3d(1, 1, 1)
148p2 = pt3d(2, 2, 2)151    p2 = pt3d(2, 2, 2)
149print(p1 + p2)152    print(p1+p2)
150print(p1 - p2)153    print(p1-p2)
151print(p1 == p2)154    print(p1==p2)
152print(p1+p1 == p2)155    print(p1+p1==p2)
153print(p1==p2+pt3d(-1, -1, -1))156    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 37

Student ID: 183, P-Value: 2.62e-03

Nearest Neighbor ID: 105

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle():n2class Circle:
3    def __init__(self, radius):3def __init__(self, radius):
4        self.radius = radius4self.radius = int(radius)
5    def area(self):5def area(self):
6        return math.pi * self.radius**26return round(math.pi*self.radius*self.radius,3)
7    def perimeter(self):7def perimeter(self):
8        return 2 * math.pi * self.radius8return round(2*math.pi*self.radius,3)
9if __name__=='__main__':9circle=Circle(2)
10    x = int(input())10print("Area of circle=",circle.area())
11    NewCircle = Circle(x)11print("Perimeter of circle=",circle.perimeter())class ItemToPurchase:
12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des12    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des
>cription='none'):>cription='none'):
15        self.item_name = item_name13        self.item_name = item_name
16        self.item_price = item_price14        self.item_price = item_price
17        self.item_quantity = item_quantity15        self.item_quantity = item_quantity
18        self.item_description = item_description16        self.item_description = item_description
19    def print_item_cost(self):17    def print_item_cost(self):
20        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, 18        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, 
>self.item_price,>self.item_price,
21                                            (self.item_quantity * self.item_pric19                                            (self.item_quantity * self.item_pric
>e))>e))
22        cost = self.item_quantity * self.item_price20        cost = self.item_quantity * self.item_price
23        return string, cost21        return string, cost
24    def print_item_description(self):22    def print_item_description(self):
25        string = '{}: {}'.format(self.item_name, self.item_description)23        string = '{}: {}'.format(self.item_name, self.item_description)
26        print(string, end='\n')24        print(string, end='\n')
27        return string25        return string
28class ShoppingCart:26class ShoppingCart:
29    def __init__(self, customer_name='none', current_date='January 1, 2016', car27    def __init__(self, customer_name='none', current_date='January 1, 2016', car
>t_items=[]):>t_items=[]):
30        self.customer_name = customer_name28        self.customer_name = customer_name
31        self.current_date = current_date29        self.current_date = current_date
32        self.cart_items = cart_items30        self.cart_items = cart_items
33    def add_item(self, string):31    def add_item(self, string):
34        print('\nADD ITEM TO CART', end='\n')32        print('\nADD ITEM TO CART', end='\n')
35        item_name = str(input('Enter the item name: '))33        item_name = str(input('Enter the item name: '))
36        item_description = str(input('\nEnter the item description: '))34        item_description = str(input('\nEnter the item description: '))
37        item_price = int(input('\nEnter the item price: '))35        item_price = int(input('\nEnter the item price: '))
38        item_quantity = int(input('\nEnter the item quantity: '))36        item_quantity = int(input('\nEnter the item quantity: '))
39        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti37        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti
>ty, item_description))>ty, item_description))
40    def remove_item(self):38    def remove_item(self):
41        print('\nREMOVE ITEM FROM CART', end='\n')39        print('\nREMOVE ITEM FROM CART', end='\n')
42        string = str(input('Enter name of item to remove: '))40        string = str(input('Enter name of item to remove: '))
43        i = 041        i = 0
44        for item in self.cart_items:42        for item in self.cart_items:
45            if (item.item_name == string):43            if (item.item_name == string):
46                del self.cart_items[i]44                del self.cart_items[i]
47                i += 145                i += 1
48                flag = True46                flag = True
49                break47                break
50            else:48            else:
51                flag = False49                flag = False
52        if (flag == False):50        if (flag == False):
53            print('Item not found in cart. Nothing removed')51            print('Item not found in cart. Nothing removed')
54    def modify_item(self):52    def modify_item(self):
55        print('\nCHANGE ITEM QUANTITY', end='\n')53        print('\nCHANGE ITEM QUANTITY', end='\n')
56        name = str(input('Enter the item name: '))54        name = str(input('Enter the item name: '))
57        for item in self.cart_items:55        for item in self.cart_items:
58            if (item.item_name == name):56            if (item.item_name == name):
59                quantity = int(input('Enter the new quantity: '))57                quantity = int(input('Enter the new quantity: '))
60                item.item_quantity = quantity58                item.item_quantity = quantity
61                flag = True59                flag = True
62                break60                break
63            else:61            else:
64                flag = False62                flag = False
65        if (flag == False):63        if (flag == False):
66            print('Item not found in cart. Nothing modified')64            print('Item not found in cart. Nothing modified')
67    def get_num_items_in_cart(self):65    def get_num_items_in_cart(self):
68        num_items = 066        num_items = 0
69        for item in self.cart_items:67        for item in self.cart_items:
70            num_items = num_items + item.item_quantity68            num_items = num_items + item.item_quantity
71        return num_items69        return num_items
72    def get_cost_of_cart(self):70    def get_cost_of_cart(self):
73        total_cost = 071        total_cost = 0
74        cost = 072        cost = 0
75        for item in self.cart_items:73        for item in self.cart_items:
76            cost = (item.item_quantity * item.item_price)74            cost = (item.item_quantity * item.item_price)
77            total_cost += cost75            total_cost += cost
78        return total_cost76        return total_cost
79    def print_total(self):77    def print_total(self):
80        total_cost = self.get_cost_of_cart()78        total_cost = self.get_cost_of_cart()
81        if (total_cost == 0):79        if (total_cost == 0):
82            print('SHOPPING CART IS EMPTY')80            print('SHOPPING CART IS EMPTY')
83        else:81        else:
84            self.output_cart()82            self.output_cart()
85    def print_descriptions(self):83    def print_descriptions(self):
86        print('\nOUTPUT ITEMS\' DESCRIPTIONS')84        print('\nOUTPUT ITEMS\' DESCRIPTIONS')
87        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current85        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date), end='\n')>_date), end='\n')
88        print('\nItem Descriptions', end='\n')86        print('\nItem Descriptions', end='\n')
89        for item in self.cart_items:87        for item in self.cart_items:
90            print('{}: {}'.format(item.item_name, item.item_description), end='\88            print('{}: {}'.format(item.item_name, item.item_description), end='\
>n')>n')
91    def output_cart(self):89    def output_cart(self):
92        new = ShoppingCart()90        new = ShoppingCart()
93        print('\nOUTPUT SHOPPING CART', end='\n')91        print('\nOUTPUT SHOPPING CART', end='\n')
94        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current92        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date), end='\n')>_date), end='\n')
95        print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')93        print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')
96        tc = 094        tc = 0
97        for item in self.cart_items:95        for item in self.cart_items:
98            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,96            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,
99                                             item.item_price, (item.item_quantit97                                             item.item_price, (item.item_quantit
>y * item.item_price)), end='\n')>y * item.item_price)), end='\n')
100            tc += (item.item_quantity * item.item_price)98            tc += (item.item_quantity * item.item_price)
101        print('\nTotal: ${}'.format(tc), end='\n')99        print('\nTotal: ${}'.format(tc), end='\n')
102def print_menu(ShoppingCart):100def print_menu(ShoppingCart):
103    customer_Cart = newCart101    customer_Cart = newCart
104    string = ''102    string = ''
105    menu = ('\nMENU\n'103    menu = ('\nMENU\n'
106            'a - Add item to cart\n'104            'a - Add item to cart\n'
107            'r - Remove item from cart\n'105            'r - Remove item from cart\n'
108            'c - Change item quantity\n'106            'c - Change item quantity\n'
109            'i - Output items\' descriptions\n'107            'i - Output items\' descriptions\n'
110            'o - Output shopping cart\n'108            'o - Output shopping cart\n'
111            'q - Quit\n')109            'q - Quit\n')
112    command = ''110    command = ''
113    while (command != 'q'):111    while (command != 'q'):
114        string = ''112        string = ''
115        print(menu, end='\n')113        print(menu, end='\n')
116        command = input('Choose an option: ')114        command = input('Choose an option: ')
117        while (command != 'a' and command != 'o' and command != 'i' and command 115        while (command != 'a' and command != 'o' and command != 'i' and command 
>!= 'r'>!= 'r'
118               and command != 'c' and command != 'q'):116               and command != 'c' and command != 'q'):
119            command = input('Choose an option: ')117            command = input('Choose an option: ')
120        if (command == 'a'):118        if (command == 'a'):
121            customer_Cart.add_item(string)119            customer_Cart.add_item(string)
122        if (command == 'o'):120        if (command == 'o'):
123            customer_Cart.output_cart()121            customer_Cart.output_cart()
124        if (command == 'i'):122        if (command == 'i'):
125            customer_Cart.print_descriptions()123            customer_Cart.print_descriptions()
126        if (command == 'r'):124        if (command == 'r'):
127            customer_Cart.remove_item()125            customer_Cart.remove_item()
128        if (command == 'c'):126        if (command == 'c'):
129            customer_Cart.modify_item()127            customer_Cart.modify_item()
130customer_name = str(input('Enter customer\'s name: '))128customer_name = str(input('Enter customer\'s name: '))
131current_date = str(input('\nEnter today\'s date: '))129current_date = str(input('\nEnter today\'s date: '))
132print('Customer name:', customer_name, end='\n')130print('Customer name:', customer_name, end='\n')
133print('Today\'s date:', current_date, end='\n')131print('Today\'s date:', current_date, end='\n')
134newCart = ShoppingCart(customer_name, current_date)132newCart = ShoppingCart(customer_name, current_date)
135print_menu(newCart)from math import sqrt133print_menu(newCart)from math import sqrt
136class pt3d:134class pt3d:
n137    def __init__(self, x=0, y=0, z=0):n135    def __init__(self, x, y, z):
138        self.x = x136        self.x = x
139        self.y = y137        self.y = y
140        self.z = z138        self.z = z
141    def __add__(self, other):139    def __add__(self, other):
142        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)140        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
143    def __sub__(self, other):141    def __sub__(self, other):
144        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot142        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>her.z)**2)>her.z)**2)
145    def __eq__(self, other):143    def __eq__(self, other):
146        return self.x == other.x & self.y == other.y & self.z == other.z144        return self.x == other.x & self.y == other.y & self.z == other.z
147    def __str__(self):145    def __str__(self):
148        return '<{}, {}, {}>'.format(self.x, self.y, self.z)146        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
t149if __name__ == '__main__':t
150    p1 = pt3d(1, 1, 1)147p1 = pt3d(1, 1, 1)
151    p2 = pt3d(2, 2, 2)148p2 = pt3d(2, 2, 2)
152    print(p1+p2)149print(p1 + p2)
153    print(p1-p2)150print(p1 - p2)
154    print(p1==p2)151print(p1 == p2)
155    print(p1+p1==p2)152print(p1+p1 == p2)
156    print(p1==p2+pt3d(-1,-1,-1))153print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 38

Student ID: 322, P-Value: 2.68e-03

Nearest Neighbor ID: 88

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self,radius):n3    def __init__(self, radius):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
n6        return math.pi*self.radius**2n6        return math.pi*(self.radius**2)
7    def perimeter(self):7    def perimeter(self):
n8        return math.pi*2*self.radiusn8        return 2*math.pi*self.radius
9if __name__=='__main__':9if __name__=='__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14   def __init__(self, name='none', price=0, quantity=0, description='none'):14   def __init__(self, name='none', price=0, quantity=0, description='none'):
15       self.item_name=name15       self.item_name=name
16       self.item_description=description16       self.item_description=description
17       self.item_price=price17       self.item_price=price
18       self.item_quantity=quantity18       self.item_quantity=quantity
19   def print_item_description(self):19   def print_item_description(self):
n20       print('{}{}'.format(self.item_name,self.item_description))n20       print('%s%s' % (self.item_name, self.item_description))
21class ShoppingCart:21class ShoppingCart:
22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
23       self.customer_name = customer_name23       self.customer_name = customer_name
24       self.current_date = current_date24       self.current_date = current_date
25       self.cart_items = cart_items  25       self.cart_items = cart_items  
26   def add_item(self, itemToPurchase):26   def add_item(self, itemToPurchase):
27       self.cart_items.append(itemToPurchase)  27       self.cart_items.append(itemToPurchase)  
28   def remove_item(self, itemName):28   def remove_item(self, itemName):
29       tremove_item = False29       tremove_item = False
30       for item in self.cart_items:30       for item in self.cart_items:
31           if item.item_name == itemName:31           if item.item_name == itemName:
32               self.cart_items.remove(item)32               self.cart_items.remove(item)
33               tremove_item = True33               tremove_item = True
34               break34               break
35       if not tremove_item:          35       if not tremove_item:          
n36           print('Item not found in the cart. Nothing removed')        n36           print('Item not found in the cart. Nothing removed.')
37   def modify_item(self, itemToPurchase):  37   def modify_item(self, itemToPurchase):  
38       tmodify_item = False38       tmodify_item = False
n39       for n in range(len(self.cart_items)):n39       for i in range(len(self.cart_items)):
40           if self.cart_items[n].item_name == itemToPurchase.item_name:40           if self.cart_items[i].item_name == itemToPurchase.item_name:
41               tmodify_item = True41               tmodify_item = True
n42               self.cart_items[n].item_quantity = itemToPurchase.item_quantityn42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43               break43               break
44       if not tmodify_item:      44       if not tmodify_item:      
n45           print('Item not found in the cart. Nothing modified')        n45           print('Item not found in the cart. Nothing modified.')  
46   def get_num_items_in_cart(self):46   def get_num_items_in_cart(self):
47       num_items = 047       num_items = 0
48       for item in self.cart_items:48       for item in self.cart_items:
n49           num_items += item.item_quantityn49           num_items = num_items + item.item_quantity
50       return num_items50       return num_items
51   def get_cost_of_cart(self):51   def get_cost_of_cart(self):
52       total_cost = 052       total_cost = 0
53       cost = 053       cost = 0
54       for item in self.cart_items:54       for item in self.cart_items:
55           cost = (item.item_quantity * item.item_price)55           cost = (item.item_quantity * item.item_price)
56           total_cost += cost56           total_cost += cost
n57       return total_cost       n57       return total_cost
58   def print_total(self):58   def print_total(self):
59       total_cost = self.get_cost_of_cart()59       total_cost = self.get_cost_of_cart()
60       if (total_cost == 0):60       if (total_cost == 0):
61           print('SHOPPING CART IS EMPTY')61           print('SHOPPING CART IS EMPTY')
62       else:62       else:
n63           print("{}'s Shopping Cart - {}".format(self.customer_name, self.curren63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>nt_date))>ent_date))
64           print("Number of Items: {} ".format(self.get_num_items_in_cart()))64           print('Number of Items: %d\n' %self.get_num_items_in_cart())
65           for item in self.cart_items:65           for item in self.cart_items:
66               total = item.item_price * item.item_quantity66               total = item.item_price * item.item_quantity
n67               print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantin67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>ty, item.item_price, total))>item.item_price, total))
68           print("Total: ${}".format(total_cost))    68           print('\nTotal: $%d' %(total_cost))
69   def print_descriptions(self):69   def print_descriptions(self):
70       if len(self.cart_items) == 0:70       if len(self.cart_items) == 0:
71           print('SHOPPING CART IS EMPTY')71           print('SHOPPING CART IS EMPTY')
72       else:  72       else:  
n73           print("{}'s Shopping Cart - {}".format(self.customer_name, self.curren73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>nt_date))>ent_date))
74           print()
75           print('Item Descriptions')74           print('\nItem Descriptions')
76           for item in self.cart_items:75           for item in self.cart_items:
77               item.print_item_description()  76               item.print_item_description()  
78def print_menu(newCart):77def print_menu(newCart):
79   customer_Cart = newCart78   customer_Cart = newCart
80   menu = ('\nMENU\n'79   menu = ('\nMENU\n'
81       'a - Add item to cart\n'80       'a - Add item to cart\n'
n82       'r - Remove item from the cart\n'n81       'r - Remove item from cart\n'
83       'c - Change item quantity\n'82       'c - Change item quantity\n'
n84       "i - Output item's descriptions\n"n83       "i - Output items' descriptions\n"
85       'o - Output shopping cart\n'84       'o - Output shopping cart\n'
86       'q - Quit\n')85       'q - Quit\n')
87   command = ''86   command = ''
88   while(command != 'q'):87   while(command != 'q'):
89       print(menu)88       print(menu)
n90       command = input('Choose an option:')n89       command = input('Choose an option:\n')
91       while(command != 'a' and command != 'o' and command != 'i' and command !=90       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
92           command = input('Choose an option:\n')91           command = input('Choose an option:\n')
93       if(command == 'a'):92       if(command == 'a'):
94           print("\nADD ITEM TO CART")93           print("\nADD ITEM TO CART")
95           item_name = input('Enter the item name:\n')94           item_name = input('Enter the item name:\n')
96           item_description = input('Enter the item description:\n')95           item_description = input('Enter the item description:\n')
97           item_price = int(input('Enter the item price:\n'))96           item_price = int(input('Enter the item price:\n'))
98           item_quantity = int(input('Enter the item quantity:\n'))97           item_quantity = int(input('Enter the item quantity:\n'))
99           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
100           customer_Cart.add_item(itemtoPurchase)99           customer_Cart.add_item(itemtoPurchase)
101       elif(command == 'o'):100       elif(command == 'o'):
102           print('\nOUTPUT SHOPPING CART')101           print('\nOUTPUT SHOPPING CART')
103           customer_Cart.print_total()  102           customer_Cart.print_total()  
104       elif(command == 'i'):103       elif(command == 'i'):
105           print('\nOUTPUT ITEMS\' DESCRIPTIONS')104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
106           customer_Cart.print_descriptions()105           customer_Cart.print_descriptions()
107       elif(command == 'r'):106       elif(command == 'r'):
108           print('REMOVE ITEM FROM CART')107           print('REMOVE ITEM FROM CART')
n109           itemName = input('Enter the name of the item to remove :\n')n108           itemName = input('Enter name of item to remove :\n')
110           customer_Cart.remove_item(itemName)109           customer_Cart.remove_item(itemName)
111       elif(command == 'c'):110       elif(command == 'c'):
112           print('\nCHANGE ITEM QUANTITY')111           print('\nCHANGE ITEM QUANTITY')
n113           itemName = input('Enter the name of the item :\n')n112           itemName = input('Enter name of item :\n')
114           qty = int(input('Enter the new quantity :\n'))113           qty = int(input('Enter the new quantity :\n'))
115           itemToPurchase = ItemToPurchase(itemName,0,qty)114           itemToPurchase = ItemToPurchase(itemName,0,qty)
116           customer_Cart.modify_item(itemToPurchase)115           customer_Cart.modify_item(itemToPurchase)
117if __name__ == "__main__":116if __name__ == "__main__":
118   customer_name = input("Enter customer's name:\n")117   customer_name = input("Enter customer's name:\n")
119   current_date = input("Enter today's date:\n")118   current_date = input("Enter today's date:\n")
n120   print()n
121   print("Customer name: {}".format(customer_name))119   print("\nCustomer name: %s" %customer_name)
122   print("Today's date: {}".format(current_date))120   print("Today's date: %s" %current_date)
123   newCart = ShoppingCart(customer_name, current_date)121   newCart = ShoppingCart(customer_name, current_date)
n124   print_menu(newCart)import mathn122   print_menu(newCart)from math import sqrt
125class pt3d:123class pt3d:
n126    def __init__(self, x=0, y=0, z=0):n124    def __init__(self, x, y, z):
127        self.x = x125        self.x = x
128        self.y = y126        self.y = y
129        self.z = z127        self.z = z
130    def __add__(self, other):128    def __add__(self, other):
131        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)129        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
132    def __sub__(self, other):130    def __sub__(self, other):
n133        return math.sqrt((other.x - self.x)**2 + (other.z - self.z)**2 + (other.n131        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>y - self.y)**2)>her.z)**2)
134    def __eq__(self, other):132    def __eq__(self, other):
135        return self.x == other.x and self.y == other.y and self.z == other.z133        return self.x == other.x and self.y == other.y and self.z == other.z
136    def __str__(self):134    def __str__(self):
t137        return '<{},{},{}>'.format(self.x, self.y, self.z)t135        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
138p1 = pt3d(1, 1, 1)136p1 = pt3d(1, 1, 1)
139p2 = pt3d(2, 2, 2)137p2 = pt3d(2, 2, 2)
140print(p1 + p2)138print(p1 + p2)
141print(p1 - p2)139print(p1 - p2)
142print(p1 == p2)140print(p1 == p2)
143print(p1+p1 == p2)141print(p1+p1 == p2)
144print(p1==p2+pt3d(-1, -1, -1))142print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 39

Student ID: 87, P-Value: 2.68e-03

Nearest Neighbor ID: 79

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle:n2class Circle :
3    def __init__(self,radius):3    def __init__(self,radius):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
6        return math.pi*self.radius*self.radius6        return math.pi*self.radius*self.radius
7    def perimeter(self):7    def perimeter(self):
8        return 2*math.pi*self.radius8        return 2*math.pi*self.radius
n9if __name__=='__main__':n9if __name__ == '__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des14    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des
>cription = 'none'):>cription = 'none'):
15        self.item_name = item_name15        self.item_name = item_name
16        self.item_price = item_price16        self.item_price = item_price
17        self.item_quantity = item_quantity17        self.item_quantity = item_quantity
18        self.item_description = item_description18        self.item_description = item_description
19    def print_item_cost(self):19    def print_item_cost(self):
20        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, 20        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, 
>self.item_price,>self.item_price,
21        (self.item_quantity * self.item_price))21        (self.item_quantity * self.item_price))
22        cost = self.item_quantity * self.item_price22        cost = self.item_quantity * self.item_price
23        return string, cost23        return string, cost
24    def print_item_description(self):24    def print_item_description(self):
25        string = '{}: {}, %d oz.'.format(self.item_name, self.item_description, 25        string = '{}: {}, %d oz.'.format(self.item_name, self.item_description, 
>self.item_quantity)>self.item_quantity)
26        print(string)26        print(string)
27        return string27        return string
28class ShoppingCart:28class ShoppingCart:
29    def __init__(self, customer_name = 'none', current_date = 'January 1, 2016',29    def __init__(self, customer_name = 'none', current_date = 'January 1, 2016',
> cart_items = []):> cart_items = []):
30        self.customer_name = customer_name30        self.customer_name = customer_name
31        self.current_date = current_date31        self.current_date = current_date
32        self.cart_items = cart_items32        self.cart_items = cart_items
33    def add_item(self):33    def add_item(self):
34        print('ADD ITEM TO CART')34        print('ADD ITEM TO CART')
35        item_name = str(input('Enter the item name:'))35        item_name = str(input('Enter the item name:'))
36        print()36        print()
37        item_description = str(input('Enter the item description:'))37        item_description = str(input('Enter the item description:'))
38        print()38        print()
39        item_price = int(input('Enter the item price:'))39        item_price = int(input('Enter the item price:'))
40        print()40        print()
41        item_quantity = int(input('Enter the item quantity:'))41        item_quantity = int(input('Enter the item quantity:'))
42        print()42        print()
43        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti43        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti
>ty, item_description))>ty, item_description))
44    def remove_item(self):44    def remove_item(self):
45        print('REMOVE ITEM FROM CART')45        print('REMOVE ITEM FROM CART')
46        string = str(input('Enter name of item to remove:'))46        string = str(input('Enter name of item to remove:'))
47        print()47        print()
48        i = 048        i = 0
49        for item in self.cart_items:49        for item in self.cart_items:
50            if(item.item_name == string):               50            if(item.item_name == string):               
51                del self.cart_items[i]51                del self.cart_items[i]
52                flag=True52                flag=True
53                break53                break
54            else:54            else:
55                flag=False55                flag=False
56            i += 156            i += 1
57        if(flag==False):57        if(flag==False):
58            print('Item not found in cart. Nothing removed.')58            print('Item not found in cart. Nothing removed.')
59    def modify_item(self):59    def modify_item(self):
60        print('CHANGE ITEM QUANTITY')60        print('CHANGE ITEM QUANTITY')
61        name = str(input('Enter the item name:'))61        name = str(input('Enter the item name:'))
62        print()62        print()
63        for item in self.cart_items:63        for item in self.cart_items:
64            if(item.item_name == name):64            if(item.item_name == name):
65                quantity = int(input('Enter the new quantity:'))65                quantity = int(input('Enter the new quantity:'))
66                print()66                print()
67                item.item_quantity = quantity67                item.item_quantity = quantity
68                flag=True68                flag=True
69                break69                break
70            else:70            else:
71                flag=False71                flag=False
72        if(flag==False):72        if(flag==False):
73            print('Item not found in cart. Nothing modified.')73            print('Item not found in cart. Nothing modified.')
74        print()74        print()
75    def get_num_items_in_cart(self):75    def get_num_items_in_cart(self):
76        num_items=076        num_items=0
77        for item in self.cart_items:77        for item in self.cart_items:
78            num_items= num_items+item.item_quantity78            num_items= num_items+item.item_quantity
79        return num_items79        return num_items
80    def get_cost_of_cart(self):80    def get_cost_of_cart(self):
81        total_cost = 081        total_cost = 0
82        cost = 082        cost = 0
83        for item in self.cart_items:83        for item in self.cart_items:
84            cost = (item.item_quantity * item.item_price)84            cost = (item.item_quantity * item.item_price)
85            total_cost += cost85            total_cost += cost
86        return total_cost86        return total_cost
87    def print_total(self):87    def print_total(self):
88        total_cost = self.get_cost_of_cart()88        total_cost = self.get_cost_of_cart()
89        if (total_cost == 0):89        if (total_cost == 0):
90            print('SHOPPING CART IS EMPTY')90            print('SHOPPING CART IS EMPTY')
91        else:91        else:
92            self.output_cart()92            self.output_cart()
93    def print_descriptions(self):93    def print_descriptions(self):
94        print('OUTPUT ITEMS\' DESCRIPTIONS')94        print('OUTPUT ITEMS\' DESCRIPTIONS')
95        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current95        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date),end='\n')>_date),end='\n')
96        print('\nItem Descriptions')96        print('\nItem Descriptions')
97        for item in self.cart_items:97        for item in self.cart_items:
98            print('{}: {}'.format(item.item_name, item.item_description))98            print('{}: {}'.format(item.item_name, item.item_description))
99    def output_cart(self):99    def output_cart(self):
100        print('OUTPUT SHOPPING CART')100        print('OUTPUT SHOPPING CART')
101        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current101        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date))      >_date))      
102        print('Number of Items:', self.get_num_items_in_cart())102        print('Number of Items:', self.get_num_items_in_cart())
103        print()103        print()
104        tc = 0104        tc = 0
105        for item in self.cart_items:105        for item in self.cart_items:
106            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,106            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,
107              item.item_price, (item.item_quantity * item.item_price)))107              item.item_price, (item.item_quantity * item.item_price)))
108            tc += (item.item_quantity * item.item_price)108            tc += (item.item_quantity * item.item_price)
109        if len(self.cart_items) == 0:109        if len(self.cart_items) == 0:
110            print('SHOPPING CART IS EMPTY')110            print('SHOPPING CART IS EMPTY')
111        print()111        print()
112        print('Total: ${}'.format(tc))112        print('Total: ${}'.format(tc))
113def print_menu(customer_Cart):113def print_menu(customer_Cart):
114    menu = ('\nMENU\n'114    menu = ('\nMENU\n'
115    'a - Add item to cart\n'115    'a - Add item to cart\n'
116    'r - Remove item from cart\n'116    'r - Remove item from cart\n'
117    'c - Change item quantity\n'117    'c - Change item quantity\n'
118    'i - Output items\' descriptions\n'118    'i - Output items\' descriptions\n'
119    'o - Output shopping cart\n'119    'o - Output shopping cart\n'
120    'q - Quit\n')120    'q - Quit\n')
121    command = ''121    command = ''
122    while(command != 'q'):122    while(command != 'q'):
123        print(menu)123        print(menu)
124        command = input('Choose an option:')124        command = input('Choose an option:')
125        print()125        print()
126        while(command != 'a' and command != 'o' and command != 'i' and command !126        while(command != 'a' and command != 'o' and command != 'i' and command !
>= 'r'>= 'r'
127              and command != 'c' and command != 'q'):127              and command != 'c' and command != 'q'):
128            command = input('Choose an option:')128            command = input('Choose an option:')
129            print()129            print()
130        if(command == 'a'):130        if(command == 'a'):
131            customer_Cart.add_item()131            customer_Cart.add_item()
132        if(command == 'o'):132        if(command == 'o'):
133            customer_Cart.output_cart()133            customer_Cart.output_cart()
134        if(command == 'i'):134        if(command == 'i'):
135            customer_Cart.print_descriptions()135            customer_Cart.print_descriptions()
136        if(command == 'r'):136        if(command == 'r'):
137            customer_Cart.remove_item()137            customer_Cart.remove_item()
138        if(command == 'c'):138        if(command == 'c'):
139            customer_Cart.modify_item()139            customer_Cart.modify_item()
140def main():140def main():
141    customer_name = str(input('Enter customer\'s name:'))141    customer_name = str(input('Enter customer\'s name:'))
142    print()142    print()
143    current_date = str(input('Enter today\'s date:'))143    current_date = str(input('Enter today\'s date:'))
144    print('\n')144    print('\n')
145    print('Customer name:', customer_name, end='\n')145    print('Customer name:', customer_name, end='\n')
146    print('Today\'s date:', current_date, end='\n')146    print('Today\'s date:', current_date, end='\n')
147    newCart = ShoppingCart(customer_name, current_date)147    newCart = ShoppingCart(customer_name, current_date)
148    print_menu(newCart)148    print_menu(newCart)
149if __name__ == '__main__':149if __name__ == '__main__':
n150    main()from math import sqrtn150    main()import math
151class pt3d:151class pt3d:
n152    def __init__(self, x=0, y=0, z=0):n152    def __init__(self,x=0,y=0,z=0):
153        self.x = x153        self.x= x
154        self.y = y154        self.y= y
155        self.z = z155        self.z= z
156    def __add__(self, other):156    def __add__(self, other):
n157        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)n157        x = self.x + other.x
158        y = self.y + other.y
159        z = self.z + other.z
160        return pt3d(x, y,z)
158    def __sub__(self, other):161    def __sub__(self, other):
n159        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - otn162        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>her.z)**2)>2)+math.pow(other.z-self.z, 2))
160    def __eq__(self, other):163    def __eq__(self, other):
n161        return self.x == other.x & self.y == other.y & self.z == other.zn164        return other.x==self.x and other.y==self.y and other.z==self.z
162    def __str__(self):165    def __str__(self):
t163        return (f'<{self.x}, {self.y}, {self.z}>')t166        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
167if __name__ == '__main__':
164p1 = pt3d(1, 1, 1)168    p1 = pt3d(1, 1, 1)
165p2 = pt3d(2, 2, 2)169    p2 = pt3d(2, 2, 2)
166print(p1 + p2)170    print(p1+p2)
167print(p1 - p2)171    print(p1-p2)
168print(p1 == p2)172    print(p1==p2)
169print(p1+p1 == p2)173    print(p1+p1==p2)
170print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 40

Student ID: 495, P-Value: 3.51e-03

Nearest Neighbor ID: 258

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self,radius): n3    def __init__(self,r):
4        self.radius = radius  4        self.rad=r
5    def area(self):5    def area(self):
n6        return math.pi * self.radius * self.radiusn6        return self.rad*self.rad*3.14159265359
7    def perimeter(self):7    def perimeter(self):
n8        return 2 * math.pi * self.radiusn8        return self.rad*2*3.14159265359
9if __name__=='__main__':9if __name__=='__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14   def __init__(self, name='none', price=0, quantity=0, description='none'):14   def __init__(self, name='none', price=0, quantity=0, description='none'):
15       self.item_name=name15       self.item_name=name
16       self.item_description=description16       self.item_description=description
17       self.item_price=price17       self.item_price=price
18       self.item_quantity=quantity18       self.item_quantity=quantity
n19   def print_item_cost(self):n
20       total = self.item_price * self.item_quantity
21       print('%s %d @ $%d = $%d' % (self.item_name, self.item_quantity, self.ite
>m_price, total)) 
22   def print_item_description(self):  19   def print_item_description(self):
23       print('%s: %s' % (self.item_name, self.item_description))20       print('%s: %s' % (self.item_name, self.item_description))
24class ShoppingCart:21class ShoppingCart:
25   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
26       self.customer_name = customer_name23       self.customer_name = customer_name
27       self.current_date = current_date24       self.current_date = current_date
n28       self.cart_items = cart_itemsn25       self.cart_items = cart_items  
29   def add_item(self, itemToPurchase):26   def add_item(self, itemToPurchase):
n30       self.cart_items.append(itemToPurchase)n27       self.cart_items.append(itemToPurchase)  
31   def remove_item(self, itemName):28   def remove_item(self, itemName):
32       tremove_item = False29       tremove_item = False
33       for item in self.cart_items:30       for item in self.cart_items:
34           if item.item_name == itemName:31           if item.item_name == itemName:
35               self.cart_items.remove(item)32               self.cart_items.remove(item)
36               tremove_item = True33               tremove_item = True
37               break34               break
n38       if not tremove_item:n35       if not tremove_item:          
39           print('Item not found in cart. Nothing removed.')      36           print('Item not found in cart. Nothing removed.')
40   def modify_item(self, itemToPurchase):37   def modify_item(self, itemToPurchase):  
41       tmodify_item = False38       tmodify_item = False
42       for i in range(len(self.cart_items)):39       for i in range(len(self.cart_items)):
43           if self.cart_items[i].item_name == itemToPurchase.item_name:40           if self.cart_items[i].item_name == itemToPurchase.item_name:
44               tmodify_item = True41               tmodify_item = True
45               self.cart_items[i].item_quantity = itemToPurchase.item_quantity42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
46               break43               break
n47       if not tmodify_item:n44       if not tmodify_item:      
48           print('Item not found in cart. Nothing modified.')45           print('Item not found in cart. Nothing modified.')  
49   def get_num_items_in_cart(self):46   def get_num_items_in_cart(self):
50       num_items = 047       num_items = 0
51       for item in self.cart_items:48       for item in self.cart_items:
52           num_items = num_items + item.item_quantity49           num_items = num_items + item.item_quantity
n53       return num_items      n50       return num_items
54   def get_cost_of_cart(self):51   def get_cost_of_cart(self):
55       total_cost = 052       total_cost = 0
56       cost = 053       cost = 0
57       for item in self.cart_items:54       for item in self.cart_items:
58           cost = (item.item_quantity * item.item_price)55           cost = (item.item_quantity * item.item_price)
59           total_cost += cost56           total_cost += cost
60       return total_cost57       return total_cost
61   def print_total(self):58   def print_total(self):
n62       print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current_n
>date)) 
63       print('Number of Items: %d\n' %self.get_num_items_in_cart())
64       total_cost = self.get_cost_of_cart()59       total_cost = self.get_cost_of_cart()
n65       if (total_cost == 0): n60       if (total_cost == 0):
66           print('SHOPPING CART IS EMPTY')61           print('SHOPPING CART IS EMPTY')
67       else:62       else:
nn63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
 >ent_date))
64           print('Number of Items: %d\n' %self.get_num_items_in_cart())
68           for item in self.cart_items:65           for item in self.cart_items:
n69               item.print_item_cost()n66               total = item.item_price * item.item_quantity
67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
 >item.item_price, total))
70       print('\nTotal: $%d' %(total_cost))      68           print('\nTotal: $%d' %(total_cost))
71   def print_descriptions(self):69   def print_descriptions(self):
72       if len(self.cart_items) == 0:70       if len(self.cart_items) == 0:
73           print('SHOPPING CART IS EMPTY')71           print('SHOPPING CART IS EMPTY')
n74       else:n72       else:  
75           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
76           print('\nItem Descriptions')74           print('\nItem Descriptions')
77           for item in self.cart_items:75           for item in self.cart_items:
n78               item.print_item_description()              n76               item.print_item_description()  
79def print_menu(newCart):77def print_menu(newCart):
80   customer_Cart = newCart78   customer_Cart = newCart
81   menu = ('\nMENU\n'79   menu = ('\nMENU\n'
n82   'a - Add item to cart\n'n80       'a - Add item to cart\n'
83   'r - Remove item from cart\n'81       'r - Remove item from cart\n'
84   'c - Change item quantity\n'82       'c - Change item quantity\n'
85   "i - Output items' descriptions\n"83       "i - Output items' descriptions\n"
86   'o - Output shopping cart\n'84       'o - Output shopping cart\n'
87   'q - Quit\n')          85       'q - Quit\n')
88   command = ''86   command = ''
89   while(command != 'q'):87   while(command != 'q'):
90       print(menu)88       print(menu)
91       command = input('Choose an option:\n')89       command = input('Choose an option:\n')
92       while(command != 'a' and command != 'o' and command != 'i' and command !=90       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
93           command = input('Choose an option:\n')91           command = input('Choose an option:\n')
94       if(command == 'a'):92       if(command == 'a'):
95           print("\nADD ITEM TO CART")93           print("\nADD ITEM TO CART")
96           item_name = input('Enter the item name:\n')94           item_name = input('Enter the item name:\n')
97           item_description = input('Enter the item description:\n')95           item_description = input('Enter the item description:\n')
98           item_price = int(input('Enter the item price:\n'))96           item_price = int(input('Enter the item price:\n'))
99           item_quantity = int(input('Enter the item quantity:\n'))97           item_quantity = int(input('Enter the item quantity:\n'))
100           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
101           customer_Cart.add_item(itemtoPurchase)99           customer_Cart.add_item(itemtoPurchase)
102       elif(command == 'o'):100       elif(command == 'o'):
103           print('OUTPUT SHOPPING CART')101           print('OUTPUT SHOPPING CART')
n104           customer_Cart.print_total()n102           customer_Cart.print_total()  
105       elif(command == 'i'):103       elif(command == 'i'):
106           print('\nOUTPUT ITEMS\' DESCRIPTIONS')104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
107           customer_Cart.print_descriptions()105           customer_Cart.print_descriptions()
108       elif(command == 'r'):106       elif(command == 'r'):
109           print('REMOVE ITEM FROM CART')107           print('REMOVE ITEM FROM CART')
110           itemName = input('Enter name of item to remove:\n')108           itemName = input('Enter name of item to remove:\n')
111           customer_Cart.remove_item(itemName)109           customer_Cart.remove_item(itemName)
112       elif(command == 'c'):110       elif(command == 'c'):
113           print('\nCHANGE ITEM QUANTITY')111           print('\nCHANGE ITEM QUANTITY')
n114           itemName = input('Enter the item name:\n')n112           itemName = input('Enter name of item :\n')
115           qty = int(input('Enter the new quantity:\n'))113           qty = int(input('Enter the new quantity :\n'))
116           itemToPurchase = ItemToPurchase(itemName,0,qty)114           itemToPurchase = ItemToPurchase(itemName,0,qty)
n117           customer_Cart.modify_item(itemToPurchase)      n115           customer_Cart.modify_item(itemToPurchase)
118if __name__ == "__main__":116if __name__ == "__main__":
t119    customer_name = input("Enter customer's name:\n")t117   customer_name = input("Enter customer's name:\n")
120    current_date = input("Enter today's date:\n")118   current_date = input("Enter today's date:\n")
121    print("\nCustomer name: %s" %customer_name)119   print("\nCustomer name: %s" %customer_name)
122    print("Today's date: %s" %current_date)120   print("Today's date: %s" %current_date)
123    newCart = ShoppingCart(customer_name, current_date)121   newCart = ShoppingCart(customer_name, current_date)
124    print_menu(newCart)import math122   print_menu(newCart)  import math
125class pt3d:123class pt3d:
126    def __init__(self,x=0,y=0,z=0):124    def __init__(self,x=0,y=0,z=0):
127        self.x= x125        self.x= x
128        self.y= y126        self.y= y
129        self.z= z127        self.z= z
130    def __add__(self, other):128    def __add__(self, other):
131        x = self.x + other.x129        x = self.x + other.x
132        y = self.y + other.y130        y = self.y + other.y
133        z = self.z + other.z131        z = self.z + other.z
134        return pt3d(x, y,z)132        return pt3d(x, y,z)
135    def __sub__(self, other):133    def __sub__(self, other):
136        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 134        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>2)+math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
137    def __eq__(self, other):135    def __eq__(self, other):
138        return other.x==self.x and other.y==self.y and other.z==self.z136        return other.x==self.x and other.y==self.y and other.z==self.z
139    def __str__(self):137    def __str__(self):
140        return "<{0},{1},{2}>".format(self.x, self.y, self.z)138        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
141if __name__ == '__main__':139if __name__ == '__main__':
142    p1 = pt3d(1, 1, 1)140    p1 = pt3d(1, 1, 1)
143    p2 = pt3d(2, 2, 2)141    p2 = pt3d(2, 2, 2)
144    print(p1+p2)142    print(p1+p2)
145    print(p1-p2)143    print(p1-p2)
146    print(p1==p2)144    print(p1==p2)
147    print(p1+p1==p2)145    print(p1+p1==p2)
148    print(p1==p2+pt3d(-1,-1,-1))146    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 41

Student ID: 239, P-Value: 4.05e-03

Nearest Neighbor ID: 258

Student (left) and Nearest Neighbor (right).


n1from cmath import pin
2import math1import math
3class Circle:2class Circle:
n4    def __init__ (self, r=0):n3    def __init__(self,r):
5        self.r = r4        self.rad=r
6    def area(self):5    def area(self):
n7        area = (math.pi * (self.r**2))n6        return self.rad*self.rad*3.14159265359
8        return area
9    def perimeter(self):7    def perimeter(self):
n10        circum = (2*math.pi* self.r)n8        return self.rad*2*3.14159265359
11        return circum
12if __name__=="__main__":9if __name__=='__main__':
13    r= int (input())10    = int(input())
14    NewCircle = Circle(r)11    NewCircle = Circle(x)
15    print(' {:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
16    print(' {:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
17   def __init__(self, name='none', price=0, quantity=0, description='none'):14   def __init__(self, name='none', price=0, quantity=0, description='none'):
18       self.item_name=name15       self.item_name=name
19       self.item_description=description16       self.item_description=description
20       self.item_price=price17       self.item_price=price
21       self.item_quantity=quantity18       self.item_quantity=quantity
22   def print_item_description(self):19   def print_item_description(self):
23       print('%s: %s' % (self.item_name, self.item_description))20       print('%s: %s' % (self.item_name, self.item_description))
24class ShoppingCart:21class ShoppingCart:
25   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
26       self.customer_name = customer_name23       self.customer_name = customer_name
27       self.current_date = current_date24       self.current_date = current_date
28       self.cart_items = cart_items  25       self.cart_items = cart_items  
29   def add_item(self, itemToPurchase):26   def add_item(self, itemToPurchase):
30       self.cart_items.append(itemToPurchase)  27       self.cart_items.append(itemToPurchase)  
31   def remove_item(self, itemName):28   def remove_item(self, itemName):
32       tremove_item = False29       tremove_item = False
33       for item in self.cart_items:30       for item in self.cart_items:
34           if item.item_name == itemName:31           if item.item_name == itemName:
35               self.cart_items.remove(item)32               self.cart_items.remove(item)
36               tremove_item = True33               tremove_item = True
37               break34               break
38       if not tremove_item:          35       if not tremove_item:          
39           print('Item not found in cart. Nothing removed.')36           print('Item not found in cart. Nothing removed.')
40   def modify_item(self, itemToPurchase):  37   def modify_item(self, itemToPurchase):  
41       tmodify_item = False38       tmodify_item = False
42       for i in range(len(self.cart_items)):39       for i in range(len(self.cart_items)):
43           if self.cart_items[i].item_name == itemToPurchase.item_name:40           if self.cart_items[i].item_name == itemToPurchase.item_name:
44               tmodify_item = True41               tmodify_item = True
45               self.cart_items[i].item_quantity = itemToPurchase.item_quantity42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
46               break43               break
47       if not tmodify_item:      44       if not tmodify_item:      
48           print('Item not found in cart. Nothing modified.')  45           print('Item not found in cart. Nothing modified.')  
49   def get_num_items_in_cart(self):46   def get_num_items_in_cart(self):
50       num_items = 047       num_items = 0
51       for item in self.cart_items:48       for item in self.cart_items:
52           num_items = num_items + item.item_quantity49           num_items = num_items + item.item_quantity
53       return num_items50       return num_items
54   def get_cost_of_cart(self):51   def get_cost_of_cart(self):
55       total_cost = 052       total_cost = 0
56       cost = 053       cost = 0
57       for item in self.cart_items:54       for item in self.cart_items:
58           cost = (item.item_quantity * item.item_price)55           cost = (item.item_quantity * item.item_price)
59           total_cost += cost56           total_cost += cost
60       return total_cost57       return total_cost
61   def print_total(self):58   def print_total(self):
62       total_cost = self.get_cost_of_cart()59       total_cost = self.get_cost_of_cart()
63       if (total_cost == 0):60       if (total_cost == 0):
64           print('SHOPPING CART IS EMPTY')61           print('SHOPPING CART IS EMPTY')
65       else:62       else:
66           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
67           print('Number of Items: %d\n' %self.get_num_items_in_cart())64           print('Number of Items: %d\n' %self.get_num_items_in_cart())
68           for item in self.cart_items:65           for item in self.cart_items:
69               total = item.item_price * item.item_quantity66               total = item.item_price * item.item_quantity
70               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
71           print('\nTotal: $%d' %(total_cost))68           print('\nTotal: $%d' %(total_cost))
72   def print_descriptions(self):69   def print_descriptions(self):
73       if len(self.cart_items) == 0:70       if len(self.cart_items) == 0:
74           print('SHOPPING CART IS EMPTY')71           print('SHOPPING CART IS EMPTY')
75       else:  72       else:  
76           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
77           print('\nItem Descriptions')74           print('\nItem Descriptions')
78           for item in self.cart_items:75           for item in self.cart_items:
79               item.print_item_description()  76               item.print_item_description()  
80def print_menu(newCart):77def print_menu(newCart):
81   customer_Cart = newCart78   customer_Cart = newCart
82   menu = ('\nMENU\n'79   menu = ('\nMENU\n'
83       'a - Add item to cart\n'80       'a - Add item to cart\n'
84       'r - Remove item from cart\n'81       'r - Remove item from cart\n'
85       'c - Change item quantity\n'82       'c - Change item quantity\n'
86       "i - Output items' descriptions\n"83       "i - Output items' descriptions\n"
87       'o - Output shopping cart\n'84       'o - Output shopping cart\n'
88       'q - Quit\n')85       'q - Quit\n')
89   command = ''86   command = ''
90   while(command != 'q'):87   while(command != 'q'):
91       print(menu)88       print(menu)
92       command = input('Choose an option:\n')89       command = input('Choose an option:\n')
93       while(command != 'a' and command != 'o' and command != 'i' and command !=90       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
94           command = input('Choose an option:\n')91           command = input('Choose an option:\n')
95       if(command == 'a'):92       if(command == 'a'):
96           print("\nADD ITEM TO CART")93           print("\nADD ITEM TO CART")
97           item_name = input('Enter the item name:\n')94           item_name = input('Enter the item name:\n')
98           item_description = input('Enter the item description:\n')95           item_description = input('Enter the item description:\n')
99           item_price = int(input('Enter the item price:\n'))96           item_price = int(input('Enter the item price:\n'))
100           item_quantity = int(input('Enter the item quantity:\n'))97           item_quantity = int(input('Enter the item quantity:\n'))
101           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
102           customer_Cart.add_item(itemtoPurchase)99           customer_Cart.add_item(itemtoPurchase)
103       elif(command == 'o'):100       elif(command == 'o'):
n104           print('\nOUTPUT SHOPPING CART')n101           print('OUTPUT SHOPPING CART')
105           customer_Cart.print_total()  102           customer_Cart.print_total()  
106       elif(command == 'i'):103       elif(command == 'i'):
107           print('\nOUTPUT ITEMS\' DESCRIPTIONS')104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
108           customer_Cart.print_descriptions()105           customer_Cart.print_descriptions()
109       elif(command == 'r'):106       elif(command == 'r'):
110           print('REMOVE ITEM FROM CART')107           print('REMOVE ITEM FROM CART')
111           itemName = input('Enter name of item to remove:\n')108           itemName = input('Enter name of item to remove:\n')
112           customer_Cart.remove_item(itemName)109           customer_Cart.remove_item(itemName)
113       elif(command == 'c'):110       elif(command == 'c'):
114           print('\nCHANGE ITEM QUANTITY')111           print('\nCHANGE ITEM QUANTITY')
n115           itemName = input('Enter the item name:\n')n112           itemName = input('Enter name of item :\n')
116           qty = int(input('Enter the new quantity:\n'))113           qty = int(input('Enter the new quantity :\n'))
117           itemToPurchase = ItemToPurchase(itemName,0,qty)114           itemToPurchase = ItemToPurchase(itemName,0,qty)
118           customer_Cart.modify_item(itemToPurchase)115           customer_Cart.modify_item(itemToPurchase)
119if __name__ == "__main__":116if __name__ == "__main__":
120   customer_name = input("Enter customer's name:\n")117   customer_name = input("Enter customer's name:\n")
121   current_date = input("Enter today's date:\n")118   current_date = input("Enter today's date:\n")
122   print("\nCustomer name: %s" %customer_name)119   print("\nCustomer name: %s" %customer_name)
123   print("Today's date: %s" %current_date)120   print("Today's date: %s" %current_date)
124   newCart = ShoppingCart(customer_name, current_date)121   newCart = ShoppingCart(customer_name, current_date)
125   print_menu(newCart)  import math122   print_menu(newCart)  import math
126class pt3d:123class pt3d:
n127def __init__(self,x,y,z):n124    def __init__(self,x=0,y=0,z=0):
128self.x= x125        self.x= x
129self.y= y126        self.y= y
130self.z= z127        self.z= z
131def __add__(self, other):128    def __add__(self, other):
132x = self.x + other.x129        x = self.x + other.x
133y = self.y + other.y130        y = self.y + other.y
134z = self.z + other.z131        z = self.z + other.z
135return pt3d(x, y,z)132        return pt3d(x, y,z)
136def __sub__(self, other):133    def __sub__(self, other):
137return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 2)+math.134        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
138def __eq__(self, other):135    def __eq__(self, other):
139return other.x==self.x and other.y==self.y and other.z==self.z136        return other.x==self.x and other.y==self.y and other.z==self.z
140def __str__(self):137    def __str__(self):
141return "<{0},{1},{2}>".format(self.x, self.y, self.z)138        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
142if __name__ == '__main__':139if __name__ == '__main__':
t143p1 = pt3d(1, 1, 1)t140    p1 = pt3d(1, 1, 1)
144p2 = pt3d(2, 2, 2)141    p2 = pt3d(2, 2, 2)
145print(p1+p2)142    print(p1+p2)
146print(p1-p2)143    print(p1-p2)
147print(p1==p2)144    print(p1==p2)
148print(p1+p1==p2)145    print(p1+p1==p2)
149print(p1==p2+pt3d(-1,-1,-1))146    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 42

Student ID: 476, P-Value: 4.54e-03

Nearest Neighbor ID: 149

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
3    def __init__(self,x):3    def __init__(self,x):
n4        self.x= xn4        self.x = x
5    def area(self):5    def area(self):
n6        area=(math.pi*(self.x**2))n6        area = math.pi*((self.x)**2)
7        return area7        return area
8    def perimeter(self):8    def perimeter(self):
n9        perimeter =2*math.pi*self.xn9        perimeter = 2*math.pi*self.x
10        return perimeter10        return perimeter
11if __name__=='__main__':11if __name__=='__main__':
12    x = int(input())12    x = int(input())
13    NewCircle = Circle(x)13    NewCircle = Circle(x)
n14    print(NewCircle.area())n14    print('{:.5f}'.format(NewCircle.area()))
15    print(NewCircle.perimeter())class ItemToPurchase:15    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
16   def __init__(self, name='none', price=0, quantity=0, description='none'):16   def __init__(self, name='none', price=0, quantity=0, description='none'):
17       self.item_name=name17       self.item_name=name
18       self.item_description=description18       self.item_description=description
19       self.item_price=price19       self.item_price=price
20       self.item_quantity=quantity20       self.item_quantity=quantity
21   def print_item_description(self):21   def print_item_description(self):
22       print('%s: %s' % (self.item_name, self.item_description))22       print('%s: %s' % (self.item_name, self.item_description))
23class ShoppingCart:23class ShoppingCart:
24   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 24   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
25       self.customer_name = customer_name25       self.customer_name = customer_name
26       self.current_date = current_date26       self.current_date = current_date
27       self.cart_items = cart_items  27       self.cart_items = cart_items  
28   def add_item(self, itemToPurchase):28   def add_item(self, itemToPurchase):
29       self.cart_items.append(itemToPurchase)  29       self.cart_items.append(itemToPurchase)  
30   def remove_item(self, itemName):30   def remove_item(self, itemName):
31       tremove_item = False31       tremove_item = False
32       for item in self.cart_items:32       for item in self.cart_items:
33           if item.item_name == itemName:33           if item.item_name == itemName:
34               self.cart_items.remove(item)34               self.cart_items.remove(item)
35               tremove_item = True35               tremove_item = True
36               break36               break
37       if not tremove_item:          37       if not tremove_item:          
n38           print('Item not found in the cart. Nothing removed')n38           print('Item not found in cart. Nothing removed.')
39   def modify_item(self, itemToPurchase):  39   def modify_item(self, itemToPurchase):  
40       tmodify_item = False40       tmodify_item = False
41       for i in range(len(self.cart_items)):41       for i in range(len(self.cart_items)):
42           if self.cart_items[i].item_name == itemToPurchase.item_name:42           if self.cart_items[i].item_name == itemToPurchase.item_name:
43               tmodify_item = True43               tmodify_item = True
44               self.cart_items[i].item_quantity = itemToPurchase.item_quantity44               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
45               break45               break
46       if not tmodify_item:      46       if not tmodify_item:      
n47           print('Item not found in the cart. Nothing modified')  n47           print('Item not found in cart. Nothing modified.')  
48   def get_num_items_in_cart(self):48   def get_num_items_in_cart(self):
49       num_items = 049       num_items = 0
50       for item in self.cart_items:50       for item in self.cart_items:
51           num_items = num_items + item.item_quantity51           num_items = num_items + item.item_quantity
52       return num_items52       return num_items
53   def get_cost_of_cart(self):53   def get_cost_of_cart(self):
54       total_cost = 054       total_cost = 0
55       cost = 055       cost = 0
56       for item in self.cart_items:56       for item in self.cart_items:
57           cost = (item.item_quantity * item.item_price)57           cost = (item.item_quantity * item.item_price)
58           total_cost += cost58           total_cost += cost
59       return total_cost59       return total_cost
60   def print_total(self):60   def print_total(self):
61       total_cost = self.get_cost_of_cart()61       total_cost = self.get_cost_of_cart()
62       if (total_cost == 0):62       if (total_cost == 0):
63           print('SHOPPING CART IS EMPTY')63           print('SHOPPING CART IS EMPTY')
64       else:64       else:
65           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr65           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
66           print('Number of Items: %d\n' %self.get_num_items_in_cart())66           print('Number of Items: %d\n' %self.get_num_items_in_cart())
67           for item in self.cart_items:67           for item in self.cart_items:
68               total = item.item_price * item.item_quantity68               total = item.item_price * item.item_quantity
69               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 69               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
70           print('\nTotal: $%d' %(total_cost))70           print('\nTotal: $%d' %(total_cost))
71   def print_descriptions(self):71   def print_descriptions(self):
72       if len(self.cart_items) == 0:72       if len(self.cart_items) == 0:
73           print('SHOPPING CART IS EMPTY')73           print('SHOPPING CART IS EMPTY')
74       else:  74       else:  
75           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr75           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
76           print('\nItem Descriptions')76           print('\nItem Descriptions')
77           for item in self.cart_items:77           for item in self.cart_items:
78               item.print_item_description()  78               item.print_item_description()  
79def print_menu(newCart):79def print_menu(newCart):
80   customer_Cart = newCart80   customer_Cart = newCart
81   menu = ('\nMENU\n'81   menu = ('\nMENU\n'
82       'a - Add item to cart\n'82       'a - Add item to cart\n'
83       'r - Remove item from cart\n'83       'r - Remove item from cart\n'
84       'c - Change item quantity\n'84       'c - Change item quantity\n'
85       "i - Output items' descriptions\n"85       "i - Output items' descriptions\n"
86       'o - Output shopping cart\n'86       'o - Output shopping cart\n'
87       'q - Quit\n')87       'q - Quit\n')
88   command = ''88   command = ''
89   while(command != 'q'):89   while(command != 'q'):
90       print(menu)90       print(menu)
91       command = input('Choose an option:')91       command = input('Choose an option:')
92       while(command != 'a' and command != 'o' and command != 'i' and command !=92       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
n93           command = input('Choose an option:\n')n93           command = input('\nChoose an option:')
94       if(command == 'a'):94       if(command == 'a'):
95           print("\nADD ITEM TO CART")95           print("\nADD ITEM TO CART")
n96           item_name = input('Enter the item name:\n')n96           item_name = input('Enter item name:\n')
97           item_description = input('Enter the item description:\n')97           item_description = input('Enter item description:\n')
98           item_price = int(input('Enter the item price:\n'))98           item_price = int(input('Enter the item price:\n'))
99           item_quantity = int(input('Enter the item quantity:\n'))99           item_quantity = int(input('Enter the item quantity:\n'))
100           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,100           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
101           customer_Cart.add_item(itemtoPurchase)101           customer_Cart.add_item(itemtoPurchase)
102       elif(command == 'o'):102       elif(command == 'o'):
103           print('\nOUTPUT SHOPPING CART')103           print('\nOUTPUT SHOPPING CART')
104           customer_Cart.print_total()  104           customer_Cart.print_total()  
105       elif(command == 'i'):105       elif(command == 'i'):
106           print('\nOUTPUT ITEMS\' DESCRIPTIONS')106           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
107           customer_Cart.print_descriptions()107           customer_Cart.print_descriptions()
108       elif(command == 'r'):108       elif(command == 'r'):
109           print('REMOVE ITEM FROM CART')109           print('REMOVE ITEM FROM CART')
n110           itemName = input('Enter the name of the item to remove :\n')n110           itemName = input('Enter name of item to remove:\n')
111           customer_Cart.remove_item(itemName)111           customer_Cart.remove_item(itemName)
112       elif(command == 'c'):112       elif(command == 'c'):
113           print('\nCHANGE ITEM QUANTITY')113           print('\nCHANGE ITEM QUANTITY')
n114           itemName = input('Enter the name of the item :\n')n114           itemName = input('Enter name of item:\n')
115           qty = int(input('Enter the new quantity :\n'))115           quantity = int(input('Enter the new quantity:\n'))
116           itemToPurchase = ItemToPurchase(itemName,0,qty)116           itemToPurchase = ItemToPurchase(itemName,0,quantity)
117           customer_Cart.modify_item(itemToPurchase)117           customer_Cart.modify_item(itemToPurchase)
118if __name__ == "__main__":118if __name__ == "__main__":
119   customer_name = input("Enter customer's name:\n")119   customer_name = input("Enter customer's name:\n")
120   current_date = input("Enter today's date:\n")120   current_date = input("Enter today's date:\n")
121   print("\nCustomer name: %s" %customer_name)121   print("\nCustomer name: %s" %customer_name)
122   print("Today's date: %s" %current_date)122   print("Today's date: %s" %current_date)
123   newCart = ShoppingCart(customer_name, current_date)123   newCart = ShoppingCart(customer_name, current_date)
124   print_menu(newCart)  124   print_menu(newCart)  
n125   print()n125   print()import math
126import math
127class pt3d:126class pt3d:
t128   def __init__(self,x=0,y=0,z=0):t127    def __init__(self,x=0,y=0,z=0):
129       self.x=x128        self.x=x
130       self.y=y129        self.y=y
131       self.z=z130        self.z=z
132   def __add__(self,A):131    def __add__(self,point):
133       x1 = self.x+A.x132        x1 = self.x+point.x
134       y1 = self.y+A.y133        y1 = self.y+point.y
135       z1 = self.z+A.z134        z1 = self.z+point.z
136       return pt3d(x1, y1, z1)135        return pt3d(x1, y1, z1)
137   def __sub__(self,A):136    def __sub__(self,point):
138       x1 = (self.x-A.x)**2137        x1 = (self.x-point.x)**2
139       y1 = (self.y-A.y)**2138        y1 = (self.y-point.y)**2
140       z1 = (self.z-A.z)**2139        z1 = (self.z-point.z)**2
141       return math.sqrt(x1+y1+z1)140        return math.sqrt(x1+y1+z1)
142   def __str__(self):141    def __str__(self):
143       return f"<{self.x},{self.y},{self.z}>"142        return f"<{self.x},{self.y},{self.z}>"
144   def __eq__(self,A):143    def __eq__(self,point):
145       if (self.x == A.x) and (self.y == A.y) and (self.x == A.x):144        if (self.x == point.x) and (self.y == point.y) and (self.x == point.x):
146           return True145            return True
147       else:146        else:
148           return False147            return False
149a = pt3d(1,1,1)148a = pt3d(1,1,1)
150b = pt3d(2,2,2)149b = pt3d(2,2,2)
151print(a-b)150print(a-b)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 43

Student ID: 254, P-Value: 5.69e-03

Nearest Neighbor ID: 279

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2pi=3.14159265359n
3class Circle():2class Circle():
n4    def __init__(self,radius):n3    def __init__(self, radius):
5        self.radius=radius4        self.radius = radius
6    def area(self):5    def area(self):
n7        return pi*self.radius*self.radiusn6        return math.pi * self.radius**2
8    def perimeter(self):7    def perimeter(self):
n9        return pi*2*self.radiusn8        return 2*math.pi*self.radius
10if __name__=='__main__':9if __name__ == '__main__':
11    x = int(input())10    x = int(input())
12    NewCircle = Circle(x)11    NewCircle = Circle(x)
13    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
n14    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:n13    print('{:.5f}'.format(NewCircle.perimeter()))
14class ItemToPurchase:
15   def __init__(self, name='none', price=0, quantity=0, description='none'):15   def __init__(self, name='none', price=0, quantity=0, description='none'):
16       self.item_name=name16       self.item_name=name
17       self.item_description=description17       self.item_description=description
18       self.item_price=price18       self.item_price=price
19       self.item_quantity=quantity19       self.item_quantity=quantity
20   def print_item_description(self):20   def print_item_description(self):
21       print('%s: %s' % (self.item_name, self.item_description))21       print('%s: %s' % (self.item_name, self.item_description))
22class ShoppingCart:22class ShoppingCart:
23   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 23   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
24       self.customer_name = customer_name24       self.customer_name = customer_name
25       self.current_date = current_date25       self.current_date = current_date
26       self.cart_items = cart_items  26       self.cart_items = cart_items  
27   def add_item(self, itemToPurchase):27   def add_item(self, itemToPurchase):
28       self.cart_items.append(itemToPurchase)  28       self.cart_items.append(itemToPurchase)  
29   def remove_item(self, itemName):29   def remove_item(self, itemName):
30       tremove_item = False30       tremove_item = False
31       for item in self.cart_items:31       for item in self.cart_items:
32           if item.item_name == itemName:32           if item.item_name == itemName:
33               self.cart_items.remove(item)33               self.cart_items.remove(item)
34               tremove_item = True34               tremove_item = True
35               break35               break
36       if not tremove_item:          36       if not tremove_item:          
37           print('Item not found in the cart. Nothing removed')37           print('Item not found in the cart. Nothing removed')
38   def modify_item(self, itemToPurchase):  38   def modify_item(self, itemToPurchase):  
39       tmodify_item = False39       tmodify_item = False
40       for i in range(len(self.cart_items)):40       for i in range(len(self.cart_items)):
41           if self.cart_items[i].item_name == itemToPurchase.item_name:41           if self.cart_items[i].item_name == itemToPurchase.item_name:
42               tmodify_item = True42               tmodify_item = True
43               self.cart_items[i].item_quantity = itemToPurchase.item_quantity43               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
44               break44               break
45       if not tmodify_item:      45       if not tmodify_item:      
46           print('Item not found in the cart. Nothing modified')  46           print('Item not found in the cart. Nothing modified')  
47   def get_num_items_in_cart(self):47   def get_num_items_in_cart(self):
48       num_items = 048       num_items = 0
49       for item in self.cart_items:49       for item in self.cart_items:
50           num_items = num_items + item.item_quantity50           num_items = num_items + item.item_quantity
51       return num_items51       return num_items
52   def get_cost_of_cart(self):52   def get_cost_of_cart(self):
53       total_cost = 053       total_cost = 0
54       cost = 054       cost = 0
55       for item in self.cart_items:55       for item in self.cart_items:
56           cost = (item.item_quantity * item.item_price)56           cost = (item.item_quantity * item.item_price)
57           total_cost += cost57           total_cost += cost
58       return total_cost58       return total_cost
59   def print_total(self):59   def print_total(self):
60       total_cost = self.get_cost_of_cart()60       total_cost = self.get_cost_of_cart()
61       if (total_cost == 0):61       if (total_cost == 0):
62           print('SHOPPING CART IS EMPTY')62           print('SHOPPING CART IS EMPTY')
63       else:63       else:
64           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr64           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
65           print('Number of Items: %d\n' %self.get_num_items_in_cart())65           print('Number of Items: %d\n' %self.get_num_items_in_cart())
66           for item in self.cart_items:66           for item in self.cart_items:
67               total = item.item_price * item.item_quantity67               total = item.item_price * item.item_quantity
68               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 68               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
69           print('\nTotal: $%d' %(total_cost))69           print('\nTotal: $%d' %(total_cost))
70   def print_descriptions(self):70   def print_descriptions(self):
71       if len(self.cart_items) == 0:71       if len(self.cart_items) == 0:
72           print('SHOPPING CART IS EMPTY')72           print('SHOPPING CART IS EMPTY')
73       else:  73       else:  
74           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr74           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
75           print('\nItem Descriptions')75           print('\nItem Descriptions')
76           for item in self.cart_items:76           for item in self.cart_items:
77               item.print_item_description()  77               item.print_item_description()  
78def print_menu(newCart):78def print_menu(newCart):
79   customer_Cart = newCart79   customer_Cart = newCart
80   menu = ('\nMENU\n'80   menu = ('\nMENU\n'
81       'a - Add item to cart\n'81       'a - Add item to cart\n'
82       'r - Remove item from the cart\n'82       'r - Remove item from the cart\n'
83       'c - Change item quantity\n'83       'c - Change item quantity\n'
84       "i - Output item's descriptions\n"84       "i - Output item's descriptions\n"
85       'o - Output shopping cart\n'85       'o - Output shopping cart\n'
86       'q - Quit\n')86       'q - Quit\n')
87   command = ''87   command = ''
88   while(command != 'q'):88   while(command != 'q'):
89       print(menu)89       print(menu)
90       command = input('Choose an option:')90       command = input('Choose an option:')
91       while(command != 'a' and command != 'o' and command != 'i' and command !=91       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
92           command = input('Choose an option:\n')92           command = input('Choose an option:\n')
93       if(command == 'a'):93       if(command == 'a'):
94           print("\nADD ITEM TO CART")94           print("\nADD ITEM TO CART")
95           item_name = input('Enter the item name:\n')95           item_name = input('Enter the item name:\n')
96           item_description = input('Enter the item description:\n')96           item_description = input('Enter the item description:\n')
97           item_price = int(input('Enter the item price:\n'))97           item_price = int(input('Enter the item price:\n'))
98           item_quantity = int(input('Enter the item quantity:\n'))98           item_quantity = int(input('Enter the item quantity:\n'))
99           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,99           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
100           customer_Cart.add_item(itemtoPurchase)100           customer_Cart.add_item(itemtoPurchase)
101       elif(command == 'o'):101       elif(command == 'o'):
102           print('\nOUTPUT SHOPPING CART')102           print('\nOUTPUT SHOPPING CART')
103           customer_Cart.print_total()  103           customer_Cart.print_total()  
104       elif(command == 'i'):104       elif(command == 'i'):
105           print('\nOUTPUT ITEMS\' DESCRIPTIONS')105           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
106           customer_Cart.print_descriptions()106           customer_Cart.print_descriptions()
107       elif(command == 'r'):107       elif(command == 'r'):
108           print('REMOVE ITEM FROM CART')108           print('REMOVE ITEM FROM CART')
109           itemName = input('Enter the name of the item to remove :\n')109           itemName = input('Enter the name of the item to remove :\n')
110           customer_Cart.remove_item(itemName)110           customer_Cart.remove_item(itemName)
111       elif(command == 'c'):111       elif(command == 'c'):
112           print('\nCHANGE ITEM QUANTITY')112           print('\nCHANGE ITEM QUANTITY')
113           itemName = input('Enter the name of the item :\n')113           itemName = input('Enter the name of the item :\n')
114           qty = int(input('Enter the new quantity :\n'))114           qty = int(input('Enter the new quantity :\n'))
115           itemToPurchase = ItemToPurchase(itemName,0,qty)115           itemToPurchase = ItemToPurchase(itemName,0,qty)
116           customer_Cart.modify_item(itemToPurchase)116           customer_Cart.modify_item(itemToPurchase)
117if __name__ == "__main__":117if __name__ == "__main__":
118   customer_name = input("Enter customer's name:\n")118   customer_name = input("Enter customer's name:\n")
119   current_date = input("Enter today's date:\n")119   current_date = input("Enter today's date:\n")
120   print("\nCustomer name: %s" %customer_name)120   print("\nCustomer name: %s" %customer_name)
121   print("Today's date: %s" %current_date)121   print("Today's date: %s" %current_date)
122   newCart = ShoppingCart(customer_name, current_date)122   newCart = ShoppingCart(customer_name, current_date)
n123   print_menu(newCart)  n123   print_menu(newCart)from math import sqrt
124from math import sqrt
125class pt3d:124class pt3d:
n126    def __init__(self, abc):n125    def __init__(self, xyz):
127        self.a = a126        self.x = x
128        self.b = b127        self.y = y
129        self.c = c128        self.z = z
130    def __add__(self, other):129    def __add__(self, other):
n131        return pt3d(self.a + other.a, self.b + other.b, self.c + other.c)n130        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
132    def __sub__(self, other):131    def __sub__(self, other):
n133        return sqrt((self.a - other.a)**2 + (self.b - other.b)**2 + (self.c - otn132        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>her.c)**2)>her.z)**2)
134    def __eq__(self, other):133    def __eq__(self, other):
n135        return self.a == other.a & self.b == other.b & self.c == other.cn134        return self.x == other.x & self.y == other.y & self.z == other.z
136    def __str__(self):135    def __str__(self):
t137        return '<{}, {}, {}>'.format(self.a, self.b, self.c)t136        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
138thing1 = pt3d(1, 1, 1)137p1 = pt3d(1, 1, 1)
139thingy2 = pt3d(2, 2, 2)138p2 = pt3d(2, 2, 2)
140    print(thing1 + thingy2)139print(p1 + p2)
141    print(thing1 - thingy2)140print(p1 - p2)
142    print(thing1 == thingy2)141print(p1 == p2)
143    print(thing1*2 == thingy2)142print(p1+p1 == p2)
144    print(thing1==thingy2+pt3d(-1, -1, -1))143print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 44

Student ID: 74, P-Value: 5.81e-03

Nearest Neighbor ID: 88

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self,radius):n3    def __init__(self, radius):
4        self.radius=radius4        self.radius = radius
5    def area(self):5    def area(self):
6        return math.pi*(self.radius**2)6        return math.pi*(self.radius**2)
7    def perimeter(self):7    def perimeter(self):
n8        return 2*self.radius*math.pin8        return 2*math.pi*self.radius
9if __name__=='__main__':9if __name__=='__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14   def __init__(self, name='none', price=0, quantity=0, description='none'):14   def __init__(self, name='none', price=0, quantity=0, description='none'):
15       self.item_name=name15       self.item_name=name
16       self.item_description=description16       self.item_description=description
17       self.item_price=price17       self.item_price=price
18       self.item_quantity=quantity18       self.item_quantity=quantity
n19   def print_item_cost(self):n
20       total = self.item_price * self.item_quantity
21       print('%s %d @ $%d = $%d' % (self.item_name, self.item_quantity, self.ite
>m_price, total)) 
22   def print_item_description(self):  19   def print_item_description(self):
23       print('%s: %s' % (self.item_name, self.item_description))20       print('%s: %s' % (self.item_name, self.item_description))
24class ShoppingCart:21class ShoppingCart:
25   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
26       self.customer_name = customer_name23       self.customer_name = customer_name
27       self.current_date = current_date24       self.current_date = current_date
n28       self.cart_items = cart_itemsn25       self.cart_items = cart_items  
29   def add_item(self, itemToPurchase):26   def add_item(self, itemToPurchase):
n30       self.cart_items.append(itemToPurchase)n27       self.cart_items.append(itemToPurchase)  
31   def remove_item(self, itemName):28   def remove_item(self, itemName):
32       tremove_item = False29       tremove_item = False
33       for item in self.cart_items:30       for item in self.cart_items:
34           if item.item_name == itemName:31           if item.item_name == itemName:
35               self.cart_items.remove(item)32               self.cart_items.remove(item)
36               tremove_item = True33               tremove_item = True
37               break34               break
n38       if not tremove_item:n35       if not tremove_item:          
39           print('Item not found in cart. Nothing removed.')      36           print('Item not found in the cart. Nothing removed.')
40   def modify_item(self, itemToPurchase):37   def modify_item(self, itemToPurchase):  
41       tmodify_item = False38       tmodify_item = False
42       for i in range(len(self.cart_items)):39       for i in range(len(self.cart_items)):
43           if self.cart_items[i].item_name == itemToPurchase.item_name:40           if self.cart_items[i].item_name == itemToPurchase.item_name:
44               tmodify_item = True41               tmodify_item = True
45               self.cart_items[i].item_quantity = itemToPurchase.item_quantity42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
46               break43               break
n47       if not tmodify_item:n44       if not tmodify_item:      
48           print('Item not found in cart. Nothing modified.')45           print('Item not found in the cart. Nothing modified.')  
49   def get_num_items_in_cart(self):46   def get_num_items_in_cart(self):
50       num_items = 047       num_items = 0
51       for item in self.cart_items:48       for item in self.cart_items:
52           num_items = num_items + item.item_quantity49           num_items = num_items + item.item_quantity
n53       return num_items      n50       return num_items
54   def get_cost_of_cart(self):51   def get_cost_of_cart(self):
55       total_cost = 052       total_cost = 0
56       cost = 053       cost = 0
57       for item in self.cart_items:54       for item in self.cart_items:
58           cost = (item.item_quantity * item.item_price)55           cost = (item.item_quantity * item.item_price)
59           total_cost += cost56           total_cost += cost
60       return total_cost57       return total_cost
61   def print_total(self):58   def print_total(self):
n62       print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current_n
>date)) 
63       print('Number of Items: %d\n' %self.get_num_items_in_cart())
64       total_cost = self.get_cost_of_cart()59       total_cost = self.get_cost_of_cart()
n65       if (total_cost == 0): n60       if (total_cost == 0):
66           print('SHOPPING CART IS EMPTY')61           print('SHOPPING CART IS EMPTY')
67       else:62       else:
nn63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
 >ent_date))
64           print('Number of Items: %d\n' %self.get_num_items_in_cart())
68           for item in self.cart_items:65           for item in self.cart_items:
n69               item.print_item_cost()n66               total = item.item_price * item.item_quantity
67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
 >item.item_price, total))
70       print('\nTotal: $%d' %(total_cost))      68           print('\nTotal: $%d' %(total_cost))
71   def print_descriptions(self):69   def print_descriptions(self):
72       if len(self.cart_items) == 0:70       if len(self.cart_items) == 0:
73           print('SHOPPING CART IS EMPTY')71           print('SHOPPING CART IS EMPTY')
n74       else:n72       else:  
75           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
76           print('\nItem Descriptions')74           print('\nItem Descriptions')
77           for item in self.cart_items:75           for item in self.cart_items:
n78               item.print_item_description()              n76               item.print_item_description()  
79def print_menu(newCart):77def print_menu(newCart):
n80    customer_Cart = newCartn78   customer_Cart = newCart
81    menu = ('\nMENU\n'79   menu = ('\nMENU\n'
82    'a - Add item to cart\n'80       'a - Add item to cart\n'
83    'r - Remove item from cart\n'81       'r - Remove item from cart\n'
84    'c - Change item quantity\n'82       'c - Change item quantity\n'
85    'i - Output items\' descriptions\n'83       "i - Output items' descriptions\n"
86    'o - Output shopping cart\n'84       'o - Output shopping cart\n'
87    'q - Quit\n')85       'q - Quit\n')
88    command = ''86   command = ''
89    while(command != 'q'):87   while(command != 'q'):
90       print(menu)88       print(menu)
91       command = input('Choose an option:\n')89       command = input('Choose an option:\n')
92       while(command != 'a' and command != 'o' and command != 'i' and command !=90       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
93           command = input('Choose an option:\n')91           command = input('Choose an option:\n')
94       if(command == 'a'):92       if(command == 'a'):
95           print("\nADD ITEM TO CART")93           print("\nADD ITEM TO CART")
96           item_name = input('Enter the item name:\n')94           item_name = input('Enter the item name:\n')
97           item_description = input('Enter the item description:\n')95           item_description = input('Enter the item description:\n')
n98           item_price = float(input('Enter the item price:\n'))n96           item_price = int(input('Enter the item price:\n'))
99           item_quantity = int(input('Enter the item quantity:\n'))97           item_quantity = int(input('Enter the item quantity:\n'))
100           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
101           customer_Cart.add_item(itemtoPurchase)99           customer_Cart.add_item(itemtoPurchase)
102       elif(command == 'o'):100       elif(command == 'o'):
n103           print('OUTPUT SHOPPING CART')n101           print('\nOUTPUT SHOPPING CART')
104           customer_Cart.print_total()102           customer_Cart.print_total()  
105       elif(command == 'i'):103       elif(command == 'i'):
106           print('\nOUTPUT ITEMS\' DESCRIPTIONS')104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
107           customer_Cart.print_descriptions()105           customer_Cart.print_descriptions()
108       elif(command == 'r'):106       elif(command == 'r'):
109           print('REMOVE ITEM FROM CART')107           print('REMOVE ITEM FROM CART')
n110           itemName = input('Enter name of item to remove:\n')n108           itemName = input('Enter name of item to remove :\n')
111           customer_Cart.remove_item(itemName)109           customer_Cart.remove_item(itemName)
112       elif(command == 'c'):110       elif(command == 'c'):
113           print('\nCHANGE ITEM QUANTITY')111           print('\nCHANGE ITEM QUANTITY')
n114           itemName = input('Enter the item name:\n')n112           itemName = input('Enter name of item :\n')
115           quantity = int(input('Enter the new quantity:\n'))113           qty = int(input('Enter the new quantity :\n'))
116           itemToPurchase = ItemToPurchase(itemName,0,quantity)114           itemToPurchase = ItemToPurchase(itemName,0,qty)
117           customer_Cart.modify_item(itemToPurchase)      115           customer_Cart.modify_item(itemToPurchase)
118def execute_menu(command, my_cart):
119    customer_Cart = my_cart
120if __name__ == "__main__":116if __name__ == "__main__":
121   customer_name = input("Enter customer's name:\n")117   customer_name = input("Enter customer's name:\n")
122   current_date = input("Enter today's date:\n")118   current_date = input("Enter today's date:\n")
123   print("\nCustomer name: %s" %customer_name)119   print("\nCustomer name: %s" %customer_name)
124   print("Today's date: %s" %current_date)120   print("Today's date: %s" %current_date)
125   newCart = ShoppingCart(customer_name, current_date)121   newCart = ShoppingCart(customer_name, current_date)
126   print_menu(newCart)from math import sqrt122   print_menu(newCart)from math import sqrt
127class pt3d:123class pt3d:
n128    def __init__(self, x=0, y=0, z=0):n124    def __init__(self, x, y, z):
129        self.x = x125        self.x = x
130        self.y = y126        self.y = y
131        self.z = z127        self.z = z
132    def __add__(self, other):128    def __add__(self, other):
133        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)129        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
134    def __sub__(self, other):130    def __sub__(self, other):
135        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot131        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>her.z)**2)>her.z)**2)
136    def __eq__(self, other):132    def __eq__(self, other):
137        return self.x == other.x and self.y == other.y and self.z == other.z133        return self.x == other.x and self.y == other.y and self.z == other.z
138    def __str__(self):134    def __str__(self):
t139        return '<{0},{1},{2}>'.format(self.x, self.y, self.z)t135        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
140p1 = pt3d(1,1,1)136p1 = pt3d(1, 1, 1)
141p2 = pt3d(2,2,2)137p2 = pt3d(2, 2, 2)
142print(p1 + p2)138print(p1 + p2)
143print(p1 - p2)139print(p1 - p2)
144print(p1 == p2)140print(p1 == p2)
145print(p1+p1 == p2)141print(p1+p1 == p2)
146print(p1==p2+pt3d(-1, -1, -1))142print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 45

Student ID: 203, P-Value: 6.62e-03

Nearest Neighbor ID: 36

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
3    def __init__(self,radius):3    def __init__(self,radius):
n4       self.radius = radiusn4        self.radius = radius
5    def area(self):5    def area(self):
n6        return math.pi * self.radius**2n6        return (math.pi)*(self.radius**2)
7    def perimeter(self):7    def perimeter(self):
n8        return self.radius * math.pi *2n8        return (2*self.radius)*math.pi
9if __name__=='__main__':9if __name__=='__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14    def __init__(self, item_name = "none", item_price = 0, item_quantity = 0, it14    def __init__(self, item_name = "none", item_price = 0, item_quantity = 0, it
>em_description = "none"):>em_description = "none"):
15        self.item_name = item_name15        self.item_name = item_name
16        self.item_price = item_price16        self.item_price = item_price
17        self.item_quantity = item_quantity17        self.item_quantity = item_quantity
18        self.item_description = item_description18        self.item_description = item_description
19    def print_item_cost(self):19    def print_item_cost(self):
20        print('{} {} @ ${} = ${}'.format(self.item_name,self.item_quantity,self.20        print('{} {} @ ${} = ${}'.format(self.item_name,self.item_quantity,self.
>item_price,(self.item_quantity*self.item_price)))>item_price,(self.item_quantity*self.item_price)))
21    def print_item_description(self):21    def print_item_description(self):
22        print('{}: {}'.format(self.item_name, self.item_description))22        print('{}: {}'.format(self.item_name, self.item_description))
23class ShoppingCart:23class ShoppingCart:
24    def __init__(self, customer_name='none', current_date='January 1, 2016'):24    def __init__(self, customer_name='none', current_date='January 1, 2016'):
25        self.customer_name = customer_name25        self.customer_name = customer_name
26        self.current_date = current_date26        self.current_date = current_date
27        self.cart_items = []27        self.cart_items = []
28    def add_item(self, ItemToPurchase):28    def add_item(self, ItemToPurchase):
29        self.cart_items.append(ItemToPurchase)29        self.cart_items.append(ItemToPurchase)
30    def remove_item(self, itemname):30    def remove_item(self, itemname):
31        Removeitem = False31        Removeitem = False
32        for i in self.cart_items:32        for i in self.cart_items:
33            if i.item_name == itemname:33            if i.item_name == itemname:
34                self.cart_items.remove(i)34                self.cart_items.remove(i)
35                Removeitem = True35                Removeitem = True
36                break36                break
37        if not Removeitem:37        if not Removeitem:
38            print('Item not found in cart. Nothing removed.')38            print('Item not found in cart. Nothing removed.')
39    def modify_item(self, itemToPurchase):39    def modify_item(self, itemToPurchase):
40        Modifyitem = False40        Modifyitem = False
41        for i in range(len(self.cart_items)):41        for i in range(len(self.cart_items)):
42            if self.cart_items[i].item_name == itemToPurchase.item_name:42            if self.cart_items[i].item_name == itemToPurchase.item_name:
43                Modifyitem = True43                Modifyitem = True
44                if (itemToPurchase.item_price == 0 and itemToPurchase.item_quant44                if (itemToPurchase.item_price == 0 and itemToPurchase.item_quant
>ity == 0 and itemToPurchase.item_description == 'none'):>ity == 0 and itemToPurchase.item_description == 'none'):
45                    break45                    break
46                else:46                else:
47                    if (itemToPurchase.item_price != 0):47                    if (itemToPurchase.item_price != 0):
48                        self.cart_items[i].item_price = itemToPurchase.item_pric48                        self.cart_items[i].item_price = itemToPurchase.item_pric
>e>e
49                    if (itemToPurchase.item_quantity != 0):49                    if (itemToPurchase.item_quantity != 0):
50                        self.cart_items[i].item_quantity = itemToPurchase.item_q50                        self.cart_items[i].item_quantity = itemToPurchase.item_q
>uantity>uantity
51                    if (itemToPurchase.item_description != 'none'):51                    if (itemToPurchase.item_description != 'none'):
52                        self.cart_items[i].item_description = itemToPurchase.ite52                        self.cart_items[i].item_description = itemToPurchase.ite
>m_description>m_description
53                    break53                    break
54        if not Modifyitem:54        if not Modifyitem:
55            print('Item not found in cart. Nothing modified.')55            print('Item not found in cart. Nothing modified.')
56    def get_num_items_in_cart(self):56    def get_num_items_in_cart(self):
57        num_items = 057        num_items = 0
58        for i in self.cart_items:58        for i in self.cart_items:
59            num_items = num_items + i.item_quantity59            num_items = num_items + i.item_quantity
60        return num_items60        return num_items
61    def get_cost_of_cart(self):61    def get_cost_of_cart(self):
62        total_cost = 062        total_cost = 0
63        cost = 063        cost = 0
64        for i in self.cart_items:64        for i in self.cart_items:
65            cost = (i.item_quantity * i.item_price)65            cost = (i.item_quantity * i.item_price)
66            total_cost += cost66            total_cost += cost
67        return total_cost67        return total_cost
68    def print_total(self):68    def print_total(self):
69        total_cost = self.get_cost_of_cart()69        total_cost = self.get_cost_of_cart()
70        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current70        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date))>_date))
71        print('Number of Items: {}\n'.format(self.get_num_items_in_cart()))71        print('Number of Items: {}\n'.format(self.get_num_items_in_cart()))
72        for i in self.cart_items:72        for i in self.cart_items:
73            i.print_item_cost()73            i.print_item_cost()
74        if (total_cost == 0):74        if (total_cost == 0):
75            print('SHOPPING CART IS EMPTY')75            print('SHOPPING CART IS EMPTY')
76        print('\nTotal: ${}'.format((total_cost)))76        print('\nTotal: ${}'.format((total_cost)))
77    def print_descriptions(self):77    def print_descriptions(self):
78        if len(self.cart_items) == 0:78        if len(self.cart_items) == 0:
79            print('SHOPPING CART IS EMPTY')79            print('SHOPPING CART IS EMPTY')
80        else:80        else:
81            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur81            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur
>rent_date))>rent_date))
82            print('\nItem Descriptions')82            print('\nItem Descriptions')
83            for i in self.cart_items:83            for i in self.cart_items:
84                i.print_item_description()84                i.print_item_description()
85def print_menu():85def print_menu():
86    print('MENU\n'86    print('MENU\n'
87            'a - Add item to cart\n'87            'a - Add item to cart\n'
88            'r - Remove item from cart\n'88            'r - Remove item from cart\n'
89            'c - Change item quantity\n'89            'c - Change item quantity\n'
90            "i - Output items' descriptions\n"90            "i - Output items' descriptions\n"
91            'o - Output shopping cart\n'91            'o - Output shopping cart\n'
92            'q - Quit\n')92            'q - Quit\n')
93def execute_menu(choice, my_cart):93def execute_menu(choice, my_cart):
94    customer_Cart = my_cart94    customer_Cart = my_cart
95    if choice == 'a':95    if choice == 'a':
96        print("\nADD ITEM TO CART")96        print("\nADD ITEM TO CART")
97        item_name = input('Enter the item name:\n')97        item_name = input('Enter the item name:\n')
98        item_description = input('Enter the item description:\n')98        item_description = input('Enter the item description:\n')
99        item_price = int(input('Enter the item price:\n'))99        item_price = int(input('Enter the item price:\n'))
100        item_quantity = int(input('Enter the item quantity:\n'))100        item_quantity = int(input('Enter the item quantity:\n'))
101        itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity, it101        itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity, it
>em_description)>em_description)
102        customer_Cart.add_item(itemtoPurchase)102        customer_Cart.add_item(itemtoPurchase)
103    elif choice == 'o':103    elif choice == 'o':
104        print('OUTPUT SHOPPING CART')104        print('OUTPUT SHOPPING CART')
105        customer_Cart.print_total()105        customer_Cart.print_total()
106    elif choice == 'i':106    elif choice == 'i':
107        print('\nOUTPUT ITEMS\' DESCRIPTIONS')107        print('\nOUTPUT ITEMS\' DESCRIPTIONS')
108        customer_Cart.print_descriptions()108        customer_Cart.print_descriptions()
109    elif choice == 'r':109    elif choice == 'r':
110        print('REMOVE ITEM FROM CART')110        print('REMOVE ITEM FROM CART')
111        itemName = input('Enter name of item to remove:\n')111        itemName = input('Enter name of item to remove:\n')
112        customer_Cart.remove_item(itemName)112        customer_Cart.remove_item(itemName)
113    elif choice == 'c':113    elif choice == 'c':
114        print('\nCHANGE ITEM QUANTITY')114        print('\nCHANGE ITEM QUANTITY')
115        itemName = input('Enter the item name:\n')115        itemName = input('Enter the item name:\n')
116        qty = int(input('Enter the new quantity:\n'))116        qty = int(input('Enter the new quantity:\n'))
117        itemToPurchase = ItemToPurchase(itemName, 0, qty)117        itemToPurchase = ItemToPurchase(itemName, 0, qty)
118        customer_Cart.modify_item(itemToPurchase)118        customer_Cart.modify_item(itemToPurchase)
119if __name__ == "__main__":119if __name__ == "__main__":
120    customer_name = input("Enter customer's name:\n")120    customer_name = input("Enter customer's name:\n")
121    current_date = input("Enter today's date:\n")121    current_date = input("Enter today's date:\n")
122    print("\nCustomer name: {}".format(customer_name))122    print("\nCustomer name: {}".format(customer_name))
123    print("Today's date: {}".format(current_date))123    print("Today's date: {}".format(current_date))
124    newCart = ShoppingCart(customer_name, current_date)124    newCart = ShoppingCart(customer_name, current_date)
125    choice = ''125    choice = ''
126    while choice != 'q':126    while choice != 'q':
127        print()127        print()
128        print_menu()128        print_menu()
129        choice = input('Choose an option:\n')129        choice = input('Choose an option:\n')
130        while choice != 'a' and choice != 'o' and choice != 'i' and choice != 'q130        while choice != 'a' and choice != 'o' and choice != 'i' and choice != 'q
>' and choice != 'r' and choice != 'c':>' and choice != 'r' and choice != 'c':
131            choice = input('Choose an option:\n')131            choice = input('Choose an option:\n')
132        execute_menu(choice, newCart)import math132        execute_menu(choice, newCart)import math
133class pt3d:133class pt3d:
n134    def __init__(self, x = 0, y = 0, z = 0):n134    def __init__(self,x=0,y=0,z=0):
135        self.x = x135        self.x= x
136        self.y = y136        self.y= y
137        self.z = z137        self.z= z
138    def __add__(self,variable):138    def __add__(self, new):
139        return pt3d((self.x + variable.x),(self.y + variable.y),(self.z + variab139        x = self.x + new.x
>le.z)) 
140        y = self.y + new.y
141        z = self.z + new.z
142        return pt3d(x, y,z)
143    def __sub__(self, new):
144        return math.sqrt(math.pow(new.x-self.x, 2) + math.pow(new.y-self.y, 2)+m
 >ath.pow(new.z-self.z, 2))
145    def __eq__(self, new):
146        return new.x==self.x and new.y==self.y and new.z==self.z
140    def __str__(self):147    def __str__(self):
n141        return "<{},{},{}>".format(self.x,self.y,self.z)n148        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
142    def __sub__(self, variable):
143        return math.sqrt((self.x - variable.x)**2 + (self.y - variable.y)**2 + (
>self.z - variable.z)**2) 
144    def __eq__(self,variable):
145        return ((self.x == variable.x) and (self.y == variable.y) and (self.z ==
> variable.z)) 
146if __name__ == '__main__':149if __name__ == '__main__':
t147    p1 = pt3d(1,1,1)t150    p1 = pt3d(1, 1, 1)
148    p2 = pt3d(2,2,2)151    p2 = pt3d(2, 2, 2)
149    print(p1 + p2)152    print(p1+p2)
150    print(p1 - p2)153    print(p1-p2)
151    print(p1 == p2)154    print(p1==p2)
152    print(p1 + p1 == p2)155    print(p1+p1==p2)
153    print(p1 == p2 + pt3d(-1,-1,-1))156    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 46

Student ID: 36, P-Value: 6.62e-03

Nearest Neighbor ID: 203

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
3    def __init__(self,radius):3    def __init__(self,radius):
n4        self.radius = radiusn4       self.radius = radius
5    def area(self):5    def area(self):
n6        return (math.pi)*(self.radius**2)n6        return math.pi * self.radius**2
7    def perimeter(self):7    def perimeter(self):
n8        return (2*self.radius)*math.pin8        return self.radius * math.pi *2
9if __name__=='__main__':9if __name__=='__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14    def __init__(self, item_name = "none", item_price = 0, item_quantity = 0, it14    def __init__(self, item_name = "none", item_price = 0, item_quantity = 0, it
>em_description = "none"):>em_description = "none"):
15        self.item_name = item_name15        self.item_name = item_name
16        self.item_price = item_price16        self.item_price = item_price
17        self.item_quantity = item_quantity17        self.item_quantity = item_quantity
18        self.item_description = item_description18        self.item_description = item_description
19    def print_item_cost(self):19    def print_item_cost(self):
20        print('{} {} @ ${} = ${}'.format(self.item_name,self.item_quantity,self.20        print('{} {} @ ${} = ${}'.format(self.item_name,self.item_quantity,self.
>item_price,(self.item_quantity*self.item_price)))>item_price,(self.item_quantity*self.item_price)))
21    def print_item_description(self):21    def print_item_description(self):
22        print('{}: {}'.format(self.item_name, self.item_description))22        print('{}: {}'.format(self.item_name, self.item_description))
23class ShoppingCart:23class ShoppingCart:
24    def __init__(self, customer_name='none', current_date='January 1, 2016'):24    def __init__(self, customer_name='none', current_date='January 1, 2016'):
25        self.customer_name = customer_name25        self.customer_name = customer_name
26        self.current_date = current_date26        self.current_date = current_date
27        self.cart_items = []27        self.cart_items = []
28    def add_item(self, ItemToPurchase):28    def add_item(self, ItemToPurchase):
29        self.cart_items.append(ItemToPurchase)29        self.cart_items.append(ItemToPurchase)
30    def remove_item(self, itemname):30    def remove_item(self, itemname):
31        Removeitem = False31        Removeitem = False
32        for i in self.cart_items:32        for i in self.cart_items:
33            if i.item_name == itemname:33            if i.item_name == itemname:
34                self.cart_items.remove(i)34                self.cart_items.remove(i)
35                Removeitem = True35                Removeitem = True
36                break36                break
37        if not Removeitem:37        if not Removeitem:
38            print('Item not found in cart. Nothing removed.')38            print('Item not found in cart. Nothing removed.')
39    def modify_item(self, itemToPurchase):39    def modify_item(self, itemToPurchase):
40        Modifyitem = False40        Modifyitem = False
41        for i in range(len(self.cart_items)):41        for i in range(len(self.cart_items)):
42            if self.cart_items[i].item_name == itemToPurchase.item_name:42            if self.cart_items[i].item_name == itemToPurchase.item_name:
43                Modifyitem = True43                Modifyitem = True
44                if (itemToPurchase.item_price == 0 and itemToPurchase.item_quant44                if (itemToPurchase.item_price == 0 and itemToPurchase.item_quant
>ity == 0 and itemToPurchase.item_description == 'none'):>ity == 0 and itemToPurchase.item_description == 'none'):
45                    break45                    break
46                else:46                else:
47                    if (itemToPurchase.item_price != 0):47                    if (itemToPurchase.item_price != 0):
48                        self.cart_items[i].item_price = itemToPurchase.item_pric48                        self.cart_items[i].item_price = itemToPurchase.item_pric
>e>e
49                    if (itemToPurchase.item_quantity != 0):49                    if (itemToPurchase.item_quantity != 0):
50                        self.cart_items[i].item_quantity = itemToPurchase.item_q50                        self.cart_items[i].item_quantity = itemToPurchase.item_q
>uantity>uantity
51                    if (itemToPurchase.item_description != 'none'):51                    if (itemToPurchase.item_description != 'none'):
52                        self.cart_items[i].item_description = itemToPurchase.ite52                        self.cart_items[i].item_description = itemToPurchase.ite
>m_description>m_description
53                    break53                    break
54        if not Modifyitem:54        if not Modifyitem:
55            print('Item not found in cart. Nothing modified.')55            print('Item not found in cart. Nothing modified.')
56    def get_num_items_in_cart(self):56    def get_num_items_in_cart(self):
57        num_items = 057        num_items = 0
58        for i in self.cart_items:58        for i in self.cart_items:
59            num_items = num_items + i.item_quantity59            num_items = num_items + i.item_quantity
60        return num_items60        return num_items
61    def get_cost_of_cart(self):61    def get_cost_of_cart(self):
62        total_cost = 062        total_cost = 0
63        cost = 063        cost = 0
64        for i in self.cart_items:64        for i in self.cart_items:
65            cost = (i.item_quantity * i.item_price)65            cost = (i.item_quantity * i.item_price)
66            total_cost += cost66            total_cost += cost
67        return total_cost67        return total_cost
68    def print_total(self):68    def print_total(self):
69        total_cost = self.get_cost_of_cart()69        total_cost = self.get_cost_of_cart()
70        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current70        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date))>_date))
71        print('Number of Items: {}\n'.format(self.get_num_items_in_cart()))71        print('Number of Items: {}\n'.format(self.get_num_items_in_cart()))
72        for i in self.cart_items:72        for i in self.cart_items:
73            i.print_item_cost()73            i.print_item_cost()
74        if (total_cost == 0):74        if (total_cost == 0):
75            print('SHOPPING CART IS EMPTY')75            print('SHOPPING CART IS EMPTY')
76        print('\nTotal: ${}'.format((total_cost)))76        print('\nTotal: ${}'.format((total_cost)))
77    def print_descriptions(self):77    def print_descriptions(self):
78        if len(self.cart_items) == 0:78        if len(self.cart_items) == 0:
79            print('SHOPPING CART IS EMPTY')79            print('SHOPPING CART IS EMPTY')
80        else:80        else:
81            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur81            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur
>rent_date))>rent_date))
82            print('\nItem Descriptions')82            print('\nItem Descriptions')
83            for i in self.cart_items:83            for i in self.cart_items:
84                i.print_item_description()84                i.print_item_description()
85def print_menu():85def print_menu():
86    print('MENU\n'86    print('MENU\n'
87            'a - Add item to cart\n'87            'a - Add item to cart\n'
88            'r - Remove item from cart\n'88            'r - Remove item from cart\n'
89            'c - Change item quantity\n'89            'c - Change item quantity\n'
90            "i - Output items' descriptions\n"90            "i - Output items' descriptions\n"
91            'o - Output shopping cart\n'91            'o - Output shopping cart\n'
92            'q - Quit\n')92            'q - Quit\n')
93def execute_menu(choice, my_cart):93def execute_menu(choice, my_cart):
94    customer_Cart = my_cart94    customer_Cart = my_cart
95    if choice == 'a':95    if choice == 'a':
96        print("\nADD ITEM TO CART")96        print("\nADD ITEM TO CART")
97        item_name = input('Enter the item name:\n')97        item_name = input('Enter the item name:\n')
98        item_description = input('Enter the item description:\n')98        item_description = input('Enter the item description:\n')
99        item_price = int(input('Enter the item price:\n'))99        item_price = int(input('Enter the item price:\n'))
100        item_quantity = int(input('Enter the item quantity:\n'))100        item_quantity = int(input('Enter the item quantity:\n'))
101        itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity, it101        itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity, it
>em_description)>em_description)
102        customer_Cart.add_item(itemtoPurchase)102        customer_Cart.add_item(itemtoPurchase)
103    elif choice == 'o':103    elif choice == 'o':
104        print('OUTPUT SHOPPING CART')104        print('OUTPUT SHOPPING CART')
105        customer_Cart.print_total()105        customer_Cart.print_total()
106    elif choice == 'i':106    elif choice == 'i':
107        print('\nOUTPUT ITEMS\' DESCRIPTIONS')107        print('\nOUTPUT ITEMS\' DESCRIPTIONS')
108        customer_Cart.print_descriptions()108        customer_Cart.print_descriptions()
109    elif choice == 'r':109    elif choice == 'r':
110        print('REMOVE ITEM FROM CART')110        print('REMOVE ITEM FROM CART')
111        itemName = input('Enter name of item to remove:\n')111        itemName = input('Enter name of item to remove:\n')
112        customer_Cart.remove_item(itemName)112        customer_Cart.remove_item(itemName)
113    elif choice == 'c':113    elif choice == 'c':
114        print('\nCHANGE ITEM QUANTITY')114        print('\nCHANGE ITEM QUANTITY')
115        itemName = input('Enter the item name:\n')115        itemName = input('Enter the item name:\n')
116        qty = int(input('Enter the new quantity:\n'))116        qty = int(input('Enter the new quantity:\n'))
117        itemToPurchase = ItemToPurchase(itemName, 0, qty)117        itemToPurchase = ItemToPurchase(itemName, 0, qty)
118        customer_Cart.modify_item(itemToPurchase)118        customer_Cart.modify_item(itemToPurchase)
119if __name__ == "__main__":119if __name__ == "__main__":
120    customer_name = input("Enter customer's name:\n")120    customer_name = input("Enter customer's name:\n")
121    current_date = input("Enter today's date:\n")121    current_date = input("Enter today's date:\n")
122    print("\nCustomer name: {}".format(customer_name))122    print("\nCustomer name: {}".format(customer_name))
123    print("Today's date: {}".format(current_date))123    print("Today's date: {}".format(current_date))
124    newCart = ShoppingCart(customer_name, current_date)124    newCart = ShoppingCart(customer_name, current_date)
125    choice = ''125    choice = ''
126    while choice != 'q':126    while choice != 'q':
127        print()127        print()
128        print_menu()128        print_menu()
129        choice = input('Choose an option:\n')129        choice = input('Choose an option:\n')
130        while choice != 'a' and choice != 'o' and choice != 'i' and choice != 'q130        while choice != 'a' and choice != 'o' and choice != 'i' and choice != 'q
>' and choice != 'r' and choice != 'c':>' and choice != 'r' and choice != 'c':
131            choice = input('Choose an option:\n')131            choice = input('Choose an option:\n')
132        execute_menu(choice, newCart)import math132        execute_menu(choice, newCart)import math
133class pt3d:133class pt3d:
n134    def __init__(self,x=0,y=0,z=0):n134    def __init__(self, x = 0, y = 0, z = 0):
135        self.x= x135        self.x = x
136        self.y= y136        self.y = y
137        self.z= z137        self.z = z
138    def __add__(self, new):138    def __add__(self,variable):
139        x = self.x + new.x139        return pt3d((self.x + variable.x),(self.y + variable.y),(self.z + variab
 >le.z))
140        y = self.y + new.y
141        z = self.z + new.z
142        return pt3d(x, y,z)
143    def __sub__(self, new):
144        return math.sqrt(math.pow(new.x-self.x, 2) + math.pow(new.y-self.y, 2)+m
>ath.pow(new.z-self.z, 2)) 
145    def __eq__(self, new):
146        return new.x==self.x and new.y==self.y and new.z==self.z
147    def __str__(self):140    def __str__(self):
n148        return "<{0},{1},{2}>".format(self.x, self.y, self.z)n141        return "<{},{},{}>".format(self.x,self.y,self.z)
142    def __sub__(self, variable):
143        return math.sqrt((self.x - variable.x)**2 + (self.y - variable.y)**2 + (
 >self.z - variable.z)**2)
144    def __eq__(self,variable):
145        return ((self.x == variable.x) and (self.y == variable.y) and (self.z ==
 > variable.z))
149if __name__ == '__main__':146if __name__ == '__main__':
t150    p1 = pt3d(1, 1, 1)t147    p1 = pt3d(1,1,1)
151    p2 = pt3d(2, 2, 2)148    p2 = pt3d(2,2,2)
152    print(p1+p2)149    print(p1 + p2)
153    print(p1-p2)150    print(p1 - p2)
154    print(p1==p2)151    print(p1 == p2)
155    print(p1+p1==p2)152    print(p1 + p1 == p2)
156    print(p1==p2+pt3d(-1,-1,-1))153    print(p1 == p2 + pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 47

Student ID: 125, P-Value: 8.51e-03

Nearest Neighbor ID: 279

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle:n2class Circle():
3    def __init__(self, radius):3    def __init__(self, radius):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
n6        return (math.pi * self.radius * self.radius)n6        return math.pi * self.radius**2
7    def perimeter(self):7    def perimeter(self):
n8        return (2 * math.pi * self.radius)n8        return 2*math.pi*self.radius
9if __name__=='__main__':9if __name__ == '__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
n13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:n13    print('{:.5f}'.format(NewCircle.perimeter()))
14class ItemToPurchase:
14   def __init__(self, name='none', price=0, quantity=0, description='none'):15   def __init__(self, name='none', price=0, quantity=0, description='none'):
15       self.item_name=name16       self.item_name=name
16       self.item_description=description17       self.item_description=description
17       self.item_price=price18       self.item_price=price
18       self.item_quantity=quantity19       self.item_quantity=quantity
19   def print_item_description(self):20   def print_item_description(self):
20       print('%s: %s' % (self.item_name, self.item_description))21       print('%s: %s' % (self.item_name, self.item_description))
21class ShoppingCart:22class ShoppingCart:
22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 23   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
23       self.customer_name = customer_name24       self.customer_name = customer_name
24       self.current_date = current_date25       self.current_date = current_date
25       self.cart_items = cart_items  26       self.cart_items = cart_items  
26   def add_item(self, itemToPurchase):27   def add_item(self, itemToPurchase):
27       self.cart_items.append(itemToPurchase)  28       self.cart_items.append(itemToPurchase)  
28   def remove_item(self, itemName):29   def remove_item(self, itemName):
29       tremove_item = False30       tremove_item = False
30       for item in self.cart_items:31       for item in self.cart_items:
31           if item.item_name == itemName:32           if item.item_name == itemName:
32               self.cart_items.remove(item)33               self.cart_items.remove(item)
33               tremove_item = True34               tremove_item = True
34               break35               break
35       if not tremove_item:          36       if not tremove_item:          
36           print('Item not found in the cart. Nothing removed')37           print('Item not found in the cart. Nothing removed')
37   def modify_item(self, itemToPurchase):  38   def modify_item(self, itemToPurchase):  
38       tmodify_item = False39       tmodify_item = False
39       for i in range(len(self.cart_items)):40       for i in range(len(self.cart_items)):
40           if self.cart_items[i].item_name == itemToPurchase.item_name:41           if self.cart_items[i].item_name == itemToPurchase.item_name:
41               tmodify_item = True42               tmodify_item = True
42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity43               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43               break44               break
44       if not tmodify_item:      45       if not tmodify_item:      
45           print('Item not found in the cart. Nothing modified')  46           print('Item not found in the cart. Nothing modified')  
46   def get_num_items_in_cart(self):47   def get_num_items_in_cart(self):
47       num_items = 048       num_items = 0
48       for item in self.cart_items:49       for item in self.cart_items:
49           num_items = num_items + item.item_quantity50           num_items = num_items + item.item_quantity
50       return num_items51       return num_items
51   def get_cost_of_cart(self):52   def get_cost_of_cart(self):
52       total_cost = 053       total_cost = 0
53       cost = 054       cost = 0
54       for item in self.cart_items:55       for item in self.cart_items:
55           cost = (item.item_quantity * item.item_price)56           cost = (item.item_quantity * item.item_price)
56           total_cost += cost57           total_cost += cost
57       return total_cost58       return total_cost
58   def print_total(self):59   def print_total(self):
59       total_cost = self.get_cost_of_cart()60       total_cost = self.get_cost_of_cart()
60       if (total_cost == 0):61       if (total_cost == 0):
61           print('SHOPPING CART IS EMPTY')62           print('SHOPPING CART IS EMPTY')
62       else:63       else:
63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr64           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
64           print('Number of Items: %d\n' %self.get_num_items_in_cart())65           print('Number of Items: %d\n' %self.get_num_items_in_cart())
65           for item in self.cart_items:66           for item in self.cart_items:
66               total = item.item_price * item.item_quantity67               total = item.item_price * item.item_quantity
67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 68               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
68           print('\nTotal: $%d' %(total_cost))69           print('\nTotal: $%d' %(total_cost))
69   def print_descriptions(self):70   def print_descriptions(self):
70       if len(self.cart_items) == 0:71       if len(self.cart_items) == 0:
71           print('SHOPPING CART IS EMPTY')72           print('SHOPPING CART IS EMPTY')
72       else:  73       else:  
73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr74           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
74           print('\nItem Descriptions')75           print('\nItem Descriptions')
75           for item in self.cart_items:76           for item in self.cart_items:
76               item.print_item_description()  77               item.print_item_description()  
77def print_menu(newCart):78def print_menu(newCart):
78   customer_Cart = newCart79   customer_Cart = newCart
79   menu = ('\nMENU\n'80   menu = ('\nMENU\n'
80       'a - Add item to cart\n'81       'a - Add item to cart\n'
81       'r - Remove item from the cart\n'82       'r - Remove item from the cart\n'
82       'c - Change item quantity\n'83       'c - Change item quantity\n'
83       "i - Output item's descriptions\n"84       "i - Output item's descriptions\n"
84       'o - Output shopping cart\n'85       'o - Output shopping cart\n'
85       'q - Quit\n')86       'q - Quit\n')
86   command = ''87   command = ''
87   while(command != 'q'):88   while(command != 'q'):
88       print(menu)89       print(menu)
89       command = input('Choose an option:')90       command = input('Choose an option:')
90       while(command != 'a' and command != 'o' and command != 'i' and command !=91       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
91           command = input('Choose an option:\n')92           command = input('Choose an option:\n')
92       if(command == 'a'):93       if(command == 'a'):
93           print("\nADD ITEM TO CART")94           print("\nADD ITEM TO CART")
94           item_name = input('Enter the item name:\n')95           item_name = input('Enter the item name:\n')
95           item_description = input('Enter the item description:\n')96           item_description = input('Enter the item description:\n')
96           item_price = int(input('Enter the item price:\n'))97           item_price = int(input('Enter the item price:\n'))
97           item_quantity = int(input('Enter the item quantity:\n'))98           item_quantity = int(input('Enter the item quantity:\n'))
98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,99           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
99           customer_Cart.add_item(itemtoPurchase)100           customer_Cart.add_item(itemtoPurchase)
100       elif(command == 'o'):101       elif(command == 'o'):
101           print('\nOUTPUT SHOPPING CART')102           print('\nOUTPUT SHOPPING CART')
102           customer_Cart.print_total()  103           customer_Cart.print_total()  
103       elif(command == 'i'):104       elif(command == 'i'):
104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')105           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
105           customer_Cart.print_descriptions()106           customer_Cart.print_descriptions()
106       elif(command == 'r'):107       elif(command == 'r'):
107           print('REMOVE ITEM FROM CART')108           print('REMOVE ITEM FROM CART')
108           itemName = input('Enter the name of the item to remove :\n')109           itemName = input('Enter the name of the item to remove :\n')
109           customer_Cart.remove_item(itemName)110           customer_Cart.remove_item(itemName)
110       elif(command == 'c'):111       elif(command == 'c'):
111           print('\nCHANGE ITEM QUANTITY')112           print('\nCHANGE ITEM QUANTITY')
112           itemName = input('Enter the name of the item :\n')113           itemName = input('Enter the name of the item :\n')
113           qty = int(input('Enter the new quantity :\n'))114           qty = int(input('Enter the new quantity :\n'))
114           itemToPurchase = ItemToPurchase(itemName,0,qty)115           itemToPurchase = ItemToPurchase(itemName,0,qty)
115           customer_Cart.modify_item(itemToPurchase)116           customer_Cart.modify_item(itemToPurchase)
116if __name__ == "__main__":117if __name__ == "__main__":
117   customer_name = input("Enter customer's name:\n")118   customer_name = input("Enter customer's name:\n")
118   current_date = input("Enter today's date:\n")119   current_date = input("Enter today's date:\n")
119   print("\nCustomer name: %s" %customer_name)120   print("\nCustomer name: %s" %customer_name)
120   print("Today's date: %s" %current_date)121   print("Today's date: %s" %current_date)
121   newCart = ShoppingCart(customer_name, current_date)122   newCart = ShoppingCart(customer_name, current_date)
n122   print_menu(newCart)  n123   print_menu(newCart)from math import sqrt
123import math
124class pt3d:124class pt3d:
n125    def __init__(self,x=0,y=0,z=0):n125    def __init__(self, x, y, z):
126        self.x = x126        self.x = x
127        self.y = y127        self.y = y
128        self.z = z128        self.z = z
n129    def __add__(self,pt):n129    def __add__(self, other):
130        if isinstance(pt,pt3d):
131            return pt3d(self.x + pt.x , self.y + pt.y , self.z + pt.z)130        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
132    def __sub__(self,pt):131    def __sub__(self, other):
133        if isinstance(pt,pt3d):132        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
 >her.z)**2)
134            A = pow((self.x - pt.x),2)
135            B = pow((self.y - pt.y),2)
136            C = pow((self.z - pt.z),2)         
137            return math.sqrt(A + B + C)
138    def __eq__(self,pt):133    def __eq__(self, other):
139        if self.x == pt.x and self.y == pt.y and self.z == pt.z:134        return self.x == other.x & self.y == other.y & self.z == other.z
140            return True
141        else:
142            return False
143    def __str__(self):135    def __str__(self):
t144        return "<{},{},{}>".format(self.x,self.y,self.z)t136        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
137p1 = pt3d(1, 1, 1)
138p2 = pt3d(2, 2, 2)
139print(p1 + p2)
140print(p1 - p2)
141print(p1 == p2)
142print(p1+p1 == p2)
143print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 48

Student ID: 242, P-Value: 8.68e-03

Nearest Neighbor ID: 88

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self,radius):n3    def __init__(self, radius):
4        self.radius=radius
5    def get_radius(self):
6        return self.radius
7    def set_radius(self,radius):
8        self.radius = radius4        self.radius = radius
9    def area(self):5    def area(self):
n10        return math.pi*self.radius*self.radiusn6        return math.pi*(self.radius**2)
11    def perimeter(self):7    def perimeter(self):
12        return 2*math.pi*self.radius8        return 2*math.pi*self.radius
13if __name__=='__main__':9if __name__=='__main__':
nn10    x = int(input())
14    circle = Circle(5)11    NewCircle = Circle(x)
15    print("Testing Circle methods (radius =5)\n")12    print('{:.5f}'.format(NewCircle.area()))
16    print("get_area():",circle.get_area())13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
17    print("get_perimeter():",circle.get_perimeter())class ItemToPurchase:14   def __init__(self, name='none', price=0, quantity=0, description='none'):
18   def __init__(self, name='none', 
19   price=0, quantity=0, 
20   description='none'):
21       self.item_name=name15       self.item_name=name
22       self.item_description=description16       self.item_description=description
23       self.item_price=price17       self.item_price=price
24       self.item_quantity=quantity18       self.item_quantity=quantity
25   def print_item_description(self):19   def print_item_description(self):
26       print('%s: %s' % (self.item_name, self.item_description))20       print('%s: %s' % (self.item_name, self.item_description))
27class ShoppingCart:21class ShoppingCart:
n28   def __init__(self, customer_name = 'none', n22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
 >cart_items = []):
29   current_date = 'January 1, 2016', 
30   cart_items = []):
31       self.customer_name = customer_name23       self.customer_name = customer_name
32       self.current_date = current_date24       self.current_date = current_date
33       self.cart_items = cart_items  25       self.cart_items = cart_items  
n34   def add_item(self, n26   def add_item(self, itemToPurchase):
35   itemToPurchase):
36       self.cart_items.append(itemToPurchase)  27       self.cart_items.append(itemToPurchase)  
n37   def remove_item(self, n28   def remove_item(self, itemName):
38   itemName):
39       tremove_item = False29       tremove_item = False
40       for item in self.cart_items:30       for item in self.cart_items:
41           if item.item_name == itemName:31           if item.item_name == itemName:
42               self.cart_items.remove(item)32               self.cart_items.remove(item)
43               tremove_item = True33               tremove_item = True
44               break34               break
45       if not tremove_item:          35       if not tremove_item:          
n46           print('Item not found in cart. Nothing removed.')n36           print('Item not found in the cart. Nothing removed.')
47   def modify_item(self, 37   def modify_item(self, itemToPurchase):  
48   itemToPurchase):  
49       tmodify_item = False38       tmodify_item = False
50       for i in range(len(self.cart_items)):39       for i in range(len(self.cart_items)):
51           if self.cart_items[i].item_name == itemToPurchase.item_name:40           if self.cart_items[i].item_name == itemToPurchase.item_name:
52               tmodify_item = True41               tmodify_item = True
53               self.cart_items[i].item_quantity = itemToPurchase.item_quantity42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
54               break43               break
55       if not tmodify_item:      44       if not tmodify_item:      
n56           print('Item not found in cart. Nothing modified.')  n45           print('Item not found in the cart. Nothing modified.')  
57   def get_num_items_in_cart(self):46   def get_num_items_in_cart(self):
58       num_items = 047       num_items = 0
59       for item in self.cart_items:48       for item in self.cart_items:
60           num_items = num_items + item.item_quantity49           num_items = num_items + item.item_quantity
61       return num_items50       return num_items
62   def get_cost_of_cart(self):51   def get_cost_of_cart(self):
63       total_cost = 052       total_cost = 0
64       cost = 053       cost = 0
65       for item in self.cart_items:54       for item in self.cart_items:
66           cost = (item.item_quantity * item.item_price)55           cost = (item.item_quantity * item.item_price)
67           total_cost += cost56           total_cost += cost
68       return total_cost57       return total_cost
69   def print_total(self):58   def print_total(self):
70       total_cost = self.get_cost_of_cart()59       total_cost = self.get_cost_of_cart()
71       if (total_cost == 0):60       if (total_cost == 0):
72           print('SHOPPING CART IS EMPTY')61           print('SHOPPING CART IS EMPTY')
73       else:62       else:
n74           print('{}\'s Shopping Cart - {}'.format(self.customer_name, n63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
 >ent_date))
75           self.current_date))
76           print('Number of Items: %d\n' %self.get_num_items_in_cart())64           print('Number of Items: %d\n' %self.get_num_items_in_cart())
77           for item in self.cart_items:65           for item in self.cart_items:
78               total = item.item_price * item.item_quantity66               total = item.item_price * item.item_quantity
n79               print('%s %d @ $%d = $%d' % (item.item_name, n67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
 >item.item_price, total))
80               item.item_quantity, 
81               item.item_price, total))
82           print('\nTotal: $%d' %(total_cost))68           print('\nTotal: $%d' %(total_cost))
83   def print_descriptions(self):69   def print_descriptions(self):
84       if len(self.cart_items) == 0:70       if len(self.cart_items) == 0:
85           print('SHOPPING CART IS EMPTY')71           print('SHOPPING CART IS EMPTY')
86       else:  72       else:  
n87           print('{}\'s Shopping Cart - {}'.format(self.customer_name, n73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
 >ent_date))
88           self.current_date))
89           print('\nItem Descriptions')74           print('\nItem Descriptions')
90           for item in self.cart_items:75           for item in self.cart_items:
91               item.print_item_description()  76               item.print_item_description()  
92def print_menu(newCart):77def print_menu(newCart):
93   customer_Cart = newCart78   customer_Cart = newCart
94   menu = ('\nMENU\n'79   menu = ('\nMENU\n'
95       'a - Add item to cart\n'80       'a - Add item to cart\n'
96       'r - Remove item from cart\n'81       'r - Remove item from cart\n'
97       'c - Change item quantity\n'82       'c - Change item quantity\n'
98       "i - Output items' descriptions\n"83       "i - Output items' descriptions\n"
99       'o - Output shopping cart\n'84       'o - Output shopping cart\n'
100       'q - Quit\n')85       'q - Quit\n')
101   command = ''86   command = ''
102   while(command != 'q'):87   while(command != 'q'):
103       print(menu)88       print(menu)
104       command = input('Choose an option:\n')89       command = input('Choose an option:\n')
105       while(command != 'a' and command != 'o' and command != 'i' and command !=90       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
106           command = input('Choose an option:\n')91           command = input('Choose an option:\n')
107       if(command == 'a'):92       if(command == 'a'):
108           print("\nADD ITEM TO CART")93           print("\nADD ITEM TO CART")
109           item_name = input('Enter the item name:\n')94           item_name = input('Enter the item name:\n')
110           item_description = input('Enter the item description:\n')95           item_description = input('Enter the item description:\n')
111           item_price = int(input('Enter the item price:\n'))96           item_price = int(input('Enter the item price:\n'))
112           item_quantity = int(input('Enter the item quantity:\n'))97           item_quantity = int(input('Enter the item quantity:\n'))
n113           itemtoPurchase = ItemToPurchase(item_name, n98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
 > item_description)
114           item_price, 
115           item_quantity, 
116           item_description)
117           customer_Cart.add_item(itemtoPurchase)99           customer_Cart.add_item(itemtoPurchase)
118       elif(command == 'o'):100       elif(command == 'o'):
119           print('\nOUTPUT SHOPPING CART')101           print('\nOUTPUT SHOPPING CART')
120           customer_Cart.print_total()  102           customer_Cart.print_total()  
121       elif(command == 'i'):103       elif(command == 'i'):
122           print('\nOUTPUT ITEMS\' DESCRIPTIONS')104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
123           customer_Cart.print_descriptions()105           customer_Cart.print_descriptions()
124       elif(command == 'r'):106       elif(command == 'r'):
125           print('REMOVE ITEM FROM CART')107           print('REMOVE ITEM FROM CART')
n126           itemName = input('Enter name of item to remove:\n')n108           itemName = input('Enter name of item to remove :\n')
127           customer_Cart.remove_item(itemName)109           customer_Cart.remove_item(itemName)
128       elif(command == 'c'):110       elif(command == 'c'):
129           print('\nCHANGE ITEM QUANTITY')111           print('\nCHANGE ITEM QUANTITY')
n130           itemName = input('Enter the item name:\n')n112           itemName = input('Enter name of item :\n')
131           qty = int(input('Enter the new quantity:\n'))113           qty = int(input('Enter the new quantity :\n'))
132           itemToPurchase = ItemToPurchase(itemName,0,qty)114           itemToPurchase = ItemToPurchase(itemName,0,qty)
133           customer_Cart.modify_item(itemToPurchase)115           customer_Cart.modify_item(itemToPurchase)
134if __name__ == "__main__":116if __name__ == "__main__":
135   customer_name = input("Enter customer's name:\n")117   customer_name = input("Enter customer's name:\n")
136   current_date = input("Enter today's date:\n")118   current_date = input("Enter today's date:\n")
137   print("\nCustomer name: %s" %customer_name)119   print("\nCustomer name: %s" %customer_name)
138   print("Today's date: %s" %current_date)120   print("Today's date: %s" %current_date)
n139   newCart = ShoppingCart(customer_name, n121   newCart = ShoppingCart(customer_name, current_date)
140   current_date)
141   print_menu(newCart)  from math import sqrt122   print_menu(newCart)from math import sqrt
142class pt3d: 123class pt3d:
143    def __init__(self,x=0,y=0,z=0):124    def __init__(self, x, y, z):
144        self.x = x125        self.x = x
145        self.y = y126        self.y = y
146        self.z = z127        self.z = z
n147    def __add__(self, other): n128    def __add__(self, other):
148        return pt3d(self.x + other.x, self.y + other.y,self.z + other.z)129        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
149    def __sub__(self,other):130    def __sub__(self, other):
150        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot131        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>her.z)**2)>her.z)**2)
n151    def __eq__(self,other):n132    def __eq__(self, other):
152        return self.x == other.x and self.y == other.y and self.z == other.z133        return self.x == other.x and self.y == other.y and self.z == other.z
153    def __str__(self):134    def __str__(self):
n154        return '<{},{},{}>'.format(self.x, self.y, self.z)n135        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
155p1 = pt3d(1,1,1)136p1 = pt3d(1, 1, 1)
156p2 = pt3d(2,2,2)137p2 = pt3d(2, 2, 2)
157print(p1 + p2)138print(p1 + p2)
n158print(p1-p2)n139print(p1 - p2)
159print(p1 == p2)140print(p1 == p2)
160print(p1+p1 == p2)141print(p1+p1 == p2)
t161print(p1==p2+pt3d(-1,-1,-1))t142print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 49

Student ID: 445, P-Value: 9.60e-03

Nearest Neighbor ID: 133

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self,x):n3    def __init__(self,radius):
4        self.radius = x4        self.radius = radius
5    def area(self):5    def area(self):
n6        area = math.pi * (self.radius)**2n6        return (self.radius)**2 * math.pi
7        return area
8    def perimeter(self):7    def perimeter(self):
n9        perimeter = 2 * math.pi * self.radiusn8        return 2*math.pi * (self.radius)
10        return  perimeter
11if __name__=='__main__':9if __name__=='__main__':
12    x = int(input())10    x = int(input())
13    NewCircle = Circle(x)11    NewCircle = Circle(x)
14    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
15    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
n16    def __init__(self, name='none', price=0, quantity=0, description='none'):n14    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des
 >cription='none'):
17        self.item_name = name15        self.item_name = item_name
18        self.item_price = price16        self.item_price = item_price
19        self.item_quantity = quantity17        self.item_quantity = item_quantity
20        self.item_description = description18        self.item_description = item_description
21    def print_item_cost(self):19    def print_item_cost(self):
n22        total = self.item_quantity*self.item_pricen20        totalCost = self.item_quantity*self.item_price
23        print('{} {} @ ${} = ${}'. format(self.item_name, self.item_quantity,sel21        print('{} {} @ ${} = ${}'. format(self.item_name, self.item_quantity,sel
>f.item_price, Cost))>f.item_price, totalCost))
24    def print_item_description(self):22    def print_item_description(self):
n25        print('{}: {}'.format(self.item_name,self.item_description))n23        print(f'{self.item_name}: {item_description}')
26class ShoppingCart:24class ShoppingCart:
n27    def __init__(self, customer='none', current='January 1, 2016', items=[]):n25    def __init__(self, customer_name='none', current_date='January 1, 2016', car
 >t_items=[]):
28        self.customer_name = customer26        self.customer_name = customer_name
29        self.current_date = current27        self.current_date = current_date
30        self.cart_items = items28        self.cart_items = cart_items
31    def add_item(self, string):29    def add_item(self, string):
32        print('\nADD ITEM TO CART', end='\n')30        print('\nADD ITEM TO CART', end='\n')
33        item_name = str(input('Enter the item name:'))31        item_name = str(input('Enter the item name:'))
34        item_description = str(input('\nEnter the item description:'))32        item_description = str(input('\nEnter the item description:'))
35        item_price = int(input('\nEnter the item price:'))33        item_price = int(input('\nEnter the item price:'))
36        item_quantity = int(input('\nEnter the item quantity:'))34        item_quantity = int(input('\nEnter the item quantity:'))
37        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti35        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti
>ty, item_description))>ty, item_description))
38    def remove_item(self):36    def remove_item(self):
39        print('\nREMOVE ITEM FROM CART', end='\n')37        print('\nREMOVE ITEM FROM CART', end='\n')
40        string = str(input('Enter name of item to remove:'))38        string = str(input('Enter name of item to remove:'))
n41        i = 0n39        n = 0
42        for item in self.cart_items:40        for item in self.cart_items:
43            if (item.item_name == string):41            if (item.item_name == string):
n44                del self.cart_items[i]n42                del self.cart_items[n]
45                i += 143                n += 1
46                jawn = True44                f = True
47                break45                break
48            else:46            else:
n49                jawn = Falsen47                f = False
50        if (jawn == False):48        if (f == False):
51            print('Item not found in cart. Nothing removed')49            print('Item not found in cart. Nothing removed')
52    def modify_item(self):50    def modify_item(self):
53        print('\nCHANGE ITEM QUANTITY', end='\n')51        print('\nCHANGE ITEM QUANTITY', end='\n')
54        name = str(input('Enter the item name:'))52        name = str(input('Enter the item name:'))
55        for item in self.cart_items:53        for item in self.cart_items:
56            if (item.item_name == name):54            if (item.item_name == name):
57                quantity = int(input('Enter the new quantity:'))55                quantity = int(input('Enter the new quantity:'))
58                item.item_quantity = quantity56                item.item_quantity = quantity
n59                jawn = Truen57                f = True
60                break58                break
61            else:59            else:
n62                jawn = Falsen60                f = False
63        if (jawn == False):61        if (f == False):
64            print('Item not found in cart. Nothing modified')62            print('Item not found in cart. Nothing modified')
65    def get_num_items_in_cart(self):63    def get_num_items_in_cart(self):
66        num_items = 064        num_items = 0
67        for item in self.cart_items:65        for item in self.cart_items:
68            num_items = num_items + item.item_quantity66            num_items = num_items + item.item_quantity
69        return num_items67        return num_items
70    def get_cost_of_cart(self):68    def get_cost_of_cart(self):
n71        total_cost = 0n69        Total_Cost = 0
72        cost = 070        cost = 0
73        for item in self.cart_items:71        for item in self.cart_items:
74            cost = (item.item_quantity * item.item_price)72            cost = (item.item_quantity * item.item_price)
n75            total_cost += costn73            Total_Cost += cost
76        return total_cost74        return Total_Cost
77    def print_total(self):75    def print_total(self):
n78        total_cost = self.get_cost_of_cart()n76        Total_Cost = self.get_cost_of_cart()
79        if (total_cost == 0):77        if (Total_Cost == 0):
80            print('SHOPPING CART IS EMPTY')78            print('SHOPPING CART IS EMPTY')
81        else:79        else:
82            self.output_cart()80            self.output_cart()
83    def print_descriptions(self):81    def print_descriptions(self):
84        print('\nOUTPUT ITEMS\' DESCRIPTIONS')82        print('\nOUTPUT ITEMS\' DESCRIPTIONS')
85        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current83        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date), end='\n')>_date), end='\n')
86        print('\nItem Descriptions', end='\n')84        print('\nItem Descriptions', end='\n')
87        for item in self.cart_items:85        for item in self.cart_items:
88            print('{}: {}'.format(item.item_name, item.item_description), end='\86            print('{}: {}'.format(item.item_name, item.item_description), end='\
>n')>n')
89    def output_cart(self):87    def output_cart(self):
90        new = ShoppingCart()88        new = ShoppingCart()
91        print('\nOUTPUT SHOPPING CART', end='\n')89        print('\nOUTPUT SHOPPING CART', end='\n')
92        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current90        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date), end='\n')>_date), end='\n')
93        print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')91        print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')
n94        tc = 0n92        T = 0
95        for item in self.cart_items:93        for item in self.cart_items:
96            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,94            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,
97                                             item.item_price, (item.item_quantit95                                             item.item_price, (item.item_quantit
>y * item.item_price)), end='\n')>y * item.item_price)), end='\n')
n98            tc += (item.item_quantity * item.item_price)n96            T += (item.item_quantity * item.item_price)
99        print('\nTotal: ${}'.format(tc), end='\n')97        print('\nTotal: ${}'.format(T), end='\n')
100    def print_menu(ShoppingCart):98    def print_menu(ShoppingCart):
101        customer_Cart = newCart99        customer_Cart = newCart
102        string = ''100        string = ''
103        menu = ('\nMENU\n'101        menu = ('\nMENU\n'
104            'a - Add item to cart\n'102            'a - Add item to cart\n'
105            'r - Remove item from cart\n'103            'r - Remove item from cart\n'
106            'c - Change item quantity\n'104            'c - Change item quantity\n'
107            'i - Output items\' descriptions\n'105            'i - Output items\' descriptions\n'
108            'o - Output shopping cart\n'106            'o - Output shopping cart\n'
109            'q - Quit\n')107            'q - Quit\n')
110        command = ''108        command = ''
111        while (command != 'q'):109        while (command != 'q'):
112            string = ''110            string = ''
113            print(menu, end='\n')111            print(menu, end='\n')
114            command = input('Choose an option:')112            command = input('Choose an option:')
115            while (command != 'a' and command != 'o' and command != 'i' and comm113            while (command != 'a' and command != 'o' and command != 'i' and comm
>and != 'r'>and != 'r'
116                and command != 'c' and command != 'q'):114                and command != 'c' and command != 'q'):
117                command = input('Choose an option:')115                command = input('Choose an option:')
118                if (command == 'a'):116                if (command == 'a'):
119                    customer_Cart.add_item(string)117                    customer_Cart.add_item(string)
120                if (command == 'o'):118                if (command == 'o'):
121                    customer_Cart.output_cart()119                    customer_Cart.output_cart()
122                if (command == 'i'):120                if (command == 'i'):
123                    customer_Cart.print_descriptions()121                    customer_Cart.print_descriptions()
124                if (command == 'r'):122                if (command == 'r'):
125                    customer_Cart.remove_item()123                    customer_Cart.remove_item()
126                if (command == 'c'):124                if (command == 'c'):
127                    customer_Cart.modify_item()125                    customer_Cart.modify_item()
128        customer_name = str(input('Enter customer\'s name:'))126        customer_name = str(input('Enter customer\'s name:'))
129        current_date = str(input('\nEnter today\'s date:'))127        current_date = str(input('\nEnter today\'s date:'))
130        print()128        print()
131        print('\nCustomer name:', customer_name,)129        print('\nCustomer name:', customer_name,)
132        print('Today\'s date:', current_date,)130        print('Today\'s date:', current_date,)
133        newCart = ShoppingCart(customer_name, current_date)131        newCart = ShoppingCart(customer_name, current_date)
134        print_menu(newCart)import math132        print_menu(newCart)import math
135class pt3d:133class pt3d:
136    def __init__(self,x=0,y=0,z=0):134    def __init__(self,x=0,y=0,z=0):
137        self.x = x135        self.x = x
138        self.y = y136        self.y = y
139        self.z = z137        self.z = z
140    def __eq__(self, other):138    def __eq__(self, other):
141        if self.x == other.x and self.y == other.y and self.z == other.z:139        if self.x == other.x and self.y == other.y and self.z == other.z:
142            return True140            return True
143        else:141        else:
144            return False142            return False
145    def __add__(self,other):143    def __add__(self,other):
146        addition_x = self.x + other.x144        addition_x = self.x + other.x
147        addition_y = self.y + other.y145        addition_y = self.y + other.y
148        addition_z = self.z + other.z146        addition_z = self.z + other.z
149        return pt3d(addition_x,addition_y,addition_z)147        return pt3d(addition_x,addition_y,addition_z)
n150    def __eq__(self, other): n148    def __eq__(self, other):
151        if self.x == other.x and self.y == other.y and self.z == other.z:149        if self.x == other.x and self.y == other.y and self.z == other.z:
152            return True150            return True
153        else:151        else:
154            return False152            return False
155    def __add__(self,other):153    def __add__(self,other):
n156        addition_x = self.x + other.xn154        add_x = self.x + other.x
157        addition_y = self.y + other.y155        add_y = self.y + other.y
158        addition_z = self.z + other.z156        add_z = self.z + other.z
159        return pt3d(addition_x,addition_y,addition_z)157        return pt3d(add_x,add_y,add_z)
160    def __sub__(self, other):158    def __sub__(self, other):
t161        subtraction_x = self.x - other.xt159        sub_x = self.x - other.x
162        subtraction_y = self.y - other.y            160        sub_y = self.y - other.y    
163        subtraction_z = self.z - other.z161        sub_z = self.z - other.z
164        distance = math.sqrt(subtraction_x**2 + subtraction_y**2 + subtraction_z162        dist = math.sqrt(sub_x**2 + sub_y**2 + sub_z**2)
>**2) 
165        return distance163        return dist
166    def __str__(self):164    def __str__(self):
167        return (f'<{self.x},{self.y},{self.z}>')165        return (f'<{self.x},{self.y},{self.z}>')
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 50

Student ID: 133, P-Value: 9.60e-03

Nearest Neighbor ID: 445

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self,radius):n3    def __init__(self,x):
4        self.radius = radius4        self.radius = x
5    def area(self):5    def area(self):
n6        return (self.radius)**2 * math.pin6        area = math.pi * (self.radius)**2
7        return area
7    def perimeter(self):8    def perimeter(self):
n8        return 2*math.pi * (self.radius)n9        perimeter = 2 * math.pi * self.radius
10        return  perimeter
9if __name__=='__main__':11if __name__=='__main__':
10    x = int(input())12    x = int(input())
11    NewCircle = Circle(x)13    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))14    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:15    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
n14    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_desn16    def __init__(self, name='none', price=0, quantity=0, description='none'):
>cription='none'): 
15        self.item_name = item_name17        self.item_name = name
16        self.item_price = item_price18        self.item_price = price
17        self.item_quantity = item_quantity19        self.item_quantity = quantity
18        self.item_description = item_description20        self.item_description = description
19    def print_item_cost(self):21    def print_item_cost(self):
n20        totalCost = self.item_quantity*self.item_pricen22        total = self.item_quantity*self.item_price
21        print('{} {} @ ${} = ${}'. format(self.item_name, self.item_quantity,sel23        print('{} {} @ ${} = ${}'. format(self.item_name, self.item_quantity,sel
>f.item_price, totalCost))>f.item_price, Cost))
22    def print_item_description(self):24    def print_item_description(self):
n23        print(f'{self.item_name}: {item_description}')n25        print('{}: {}'.format(self.item_name,self.item_description))
24class ShoppingCart:26class ShoppingCart:
n25    def __init__(self, customer_name='none', current_date='January 1, 2016', carn27    def __init__(self, customer='none', current='January 1, 2016', items=[]):
>t_items=[]): 
26        self.customer_name = customer_name28        self.customer_name = customer
27        self.current_date = current_date29        self.current_date = current
28        self.cart_items = cart_items30        self.cart_items = items
29    def add_item(self, string):31    def add_item(self, string):
30        print('\nADD ITEM TO CART', end='\n')32        print('\nADD ITEM TO CART', end='\n')
31        item_name = str(input('Enter the item name:'))33        item_name = str(input('Enter the item name:'))
32        item_description = str(input('\nEnter the item description:'))34        item_description = str(input('\nEnter the item description:'))
33        item_price = int(input('\nEnter the item price:'))35        item_price = int(input('\nEnter the item price:'))
34        item_quantity = int(input('\nEnter the item quantity:'))36        item_quantity = int(input('\nEnter the item quantity:'))
35        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti37        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti
>ty, item_description))>ty, item_description))
36    def remove_item(self):38    def remove_item(self):
37        print('\nREMOVE ITEM FROM CART', end='\n')39        print('\nREMOVE ITEM FROM CART', end='\n')
38        string = str(input('Enter name of item to remove:'))40        string = str(input('Enter name of item to remove:'))
n39        n = 0n41        i = 0
40        for item in self.cart_items:42        for item in self.cart_items:
41            if (item.item_name == string):43            if (item.item_name == string):
n42                del self.cart_items[n]n44                del self.cart_items[i]
43                n += 145                i += 1
44                f = True46                jawn = True
45                break47                break
46            else:48            else:
n47                f = Falsen49                jawn = False
48        if (f == False):50        if (jawn == False):
49            print('Item not found in cart. Nothing removed')51            print('Item not found in cart. Nothing removed')
50    def modify_item(self):52    def modify_item(self):
51        print('\nCHANGE ITEM QUANTITY', end='\n')53        print('\nCHANGE ITEM QUANTITY', end='\n')
52        name = str(input('Enter the item name:'))54        name = str(input('Enter the item name:'))
53        for item in self.cart_items:55        for item in self.cart_items:
54            if (item.item_name == name):56            if (item.item_name == name):
55                quantity = int(input('Enter the new quantity:'))57                quantity = int(input('Enter the new quantity:'))
56                item.item_quantity = quantity58                item.item_quantity = quantity
n57                f = Truen59                jawn = True
58                break60                break
59            else:61            else:
n60                f = Falsen62                jawn = False
61        if (f == False):63        if (jawn == False):
62            print('Item not found in cart. Nothing modified')64            print('Item not found in cart. Nothing modified')
63    def get_num_items_in_cart(self):65    def get_num_items_in_cart(self):
64        num_items = 066        num_items = 0
65        for item in self.cart_items:67        for item in self.cart_items:
66            num_items = num_items + item.item_quantity68            num_items = num_items + item.item_quantity
67        return num_items69        return num_items
68    def get_cost_of_cart(self):70    def get_cost_of_cart(self):
n69        Total_Cost = 0n71        total_cost = 0
70        cost = 072        cost = 0
71        for item in self.cart_items:73        for item in self.cart_items:
72            cost = (item.item_quantity * item.item_price)74            cost = (item.item_quantity * item.item_price)
n73            Total_Cost += costn75            total_cost += cost
74        return Total_Cost76        return total_cost
75    def print_total(self):77    def print_total(self):
n76        Total_Cost = self.get_cost_of_cart()n78        total_cost = self.get_cost_of_cart()
77        if (Total_Cost == 0):79        if (total_cost == 0):
78            print('SHOPPING CART IS EMPTY')80            print('SHOPPING CART IS EMPTY')
79        else:81        else:
80            self.output_cart()82            self.output_cart()
81    def print_descriptions(self):83    def print_descriptions(self):
82        print('\nOUTPUT ITEMS\' DESCRIPTIONS')84        print('\nOUTPUT ITEMS\' DESCRIPTIONS')
83        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current85        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date), end='\n')>_date), end='\n')
84        print('\nItem Descriptions', end='\n')86        print('\nItem Descriptions', end='\n')
85        for item in self.cart_items:87        for item in self.cart_items:
86            print('{}: {}'.format(item.item_name, item.item_description), end='\88            print('{}: {}'.format(item.item_name, item.item_description), end='\
>n')>n')
87    def output_cart(self):89    def output_cart(self):
88        new = ShoppingCart()90        new = ShoppingCart()
89        print('\nOUTPUT SHOPPING CART', end='\n')91        print('\nOUTPUT SHOPPING CART', end='\n')
90        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current92        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date), end='\n')>_date), end='\n')
91        print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')93        print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')
n92        T = 0n94        tc = 0
93        for item in self.cart_items:95        for item in self.cart_items:
94            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,96            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,
95                                             item.item_price, (item.item_quantit97                                             item.item_price, (item.item_quantit
>y * item.item_price)), end='\n')>y * item.item_price)), end='\n')
n96            T += (item.item_quantity * item.item_price)n98            tc += (item.item_quantity * item.item_price)
97        print('\nTotal: ${}'.format(T), end='\n')99        print('\nTotal: ${}'.format(tc), end='\n')
98    def print_menu(ShoppingCart):100    def print_menu(ShoppingCart):
99        customer_Cart = newCart101        customer_Cart = newCart
100        string = ''102        string = ''
101        menu = ('\nMENU\n'103        menu = ('\nMENU\n'
102            'a - Add item to cart\n'104            'a - Add item to cart\n'
103            'r - Remove item from cart\n'105            'r - Remove item from cart\n'
104            'c - Change item quantity\n'106            'c - Change item quantity\n'
105            'i - Output items\' descriptions\n'107            'i - Output items\' descriptions\n'
106            'o - Output shopping cart\n'108            'o - Output shopping cart\n'
107            'q - Quit\n')109            'q - Quit\n')
108        command = ''110        command = ''
109        while (command != 'q'):111        while (command != 'q'):
110            string = ''112            string = ''
111            print(menu, end='\n')113            print(menu, end='\n')
112            command = input('Choose an option:')114            command = input('Choose an option:')
113            while (command != 'a' and command != 'o' and command != 'i' and comm115            while (command != 'a' and command != 'o' and command != 'i' and comm
>and != 'r'>and != 'r'
114                and command != 'c' and command != 'q'):116                and command != 'c' and command != 'q'):
115                command = input('Choose an option:')117                command = input('Choose an option:')
116                if (command == 'a'):118                if (command == 'a'):
117                    customer_Cart.add_item(string)119                    customer_Cart.add_item(string)
118                if (command == 'o'):120                if (command == 'o'):
119                    customer_Cart.output_cart()121                    customer_Cart.output_cart()
120                if (command == 'i'):122                if (command == 'i'):
121                    customer_Cart.print_descriptions()123                    customer_Cart.print_descriptions()
122                if (command == 'r'):124                if (command == 'r'):
123                    customer_Cart.remove_item()125                    customer_Cart.remove_item()
124                if (command == 'c'):126                if (command == 'c'):
125                    customer_Cart.modify_item()127                    customer_Cart.modify_item()
126        customer_name = str(input('Enter customer\'s name:'))128        customer_name = str(input('Enter customer\'s name:'))
127        current_date = str(input('\nEnter today\'s date:'))129        current_date = str(input('\nEnter today\'s date:'))
128        print()130        print()
129        print('\nCustomer name:', customer_name,)131        print('\nCustomer name:', customer_name,)
130        print('Today\'s date:', current_date,)132        print('Today\'s date:', current_date,)
131        newCart = ShoppingCart(customer_name, current_date)133        newCart = ShoppingCart(customer_name, current_date)
132        print_menu(newCart)import math134        print_menu(newCart)import math
133class pt3d:135class pt3d:
134    def __init__(self,x=0,y=0,z=0):136    def __init__(self,x=0,y=0,z=0):
135        self.x = x137        self.x = x
136        self.y = y138        self.y = y
137        self.z = z139        self.z = z
138    def __eq__(self, other):140    def __eq__(self, other):
139        if self.x == other.x and self.y == other.y and self.z == other.z:141        if self.x == other.x and self.y == other.y and self.z == other.z:
140            return True142            return True
141        else:143        else:
142            return False144            return False
143    def __add__(self,other):145    def __add__(self,other):
144        addition_x = self.x + other.x146        addition_x = self.x + other.x
145        addition_y = self.y + other.y147        addition_y = self.y + other.y
146        addition_z = self.z + other.z148        addition_z = self.z + other.z
147        return pt3d(addition_x,addition_y,addition_z)149        return pt3d(addition_x,addition_y,addition_z)
n148    def __eq__(self, other):n150    def __eq__(self, other): 
149        if self.x == other.x and self.y == other.y and self.z == other.z:151        if self.x == other.x and self.y == other.y and self.z == other.z:
150            return True152            return True
151        else:153        else:
152            return False154            return False
153    def __add__(self,other):155    def __add__(self,other):
n154        add_x = self.x + other.xn156        addition_x = self.x + other.x
155        add_y = self.y + other.y157        addition_y = self.y + other.y
156        add_z = self.z + other.z158        addition_z = self.z + other.z
157        return pt3d(add_x,add_y,add_z)159        return pt3d(addition_x,addition_y,addition_z)
158    def __sub__(self, other):160    def __sub__(self, other):
t159        sub_x = self.x - other.xt161        subtraction_x = self.x - other.x
160        sub_y = self.y - other.y    162        subtraction_y = self.y - other.y            
161        sub_z = self.z - other.z163        subtraction_z = self.z - other.z
162        dist = math.sqrt(sub_x**2 + sub_y**2 + sub_z**2)164        distance = math.sqrt(subtraction_x**2 + subtraction_y**2 + subtraction_z
 >**2)
163        return dist165        return distance
164    def __str__(self):166    def __str__(self):
165        return (f'<{self.x},{self.y},{self.z}>')167        return (f'<{self.x},{self.y},{self.z}>')
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 51

Student ID: 224, P-Value: 1.72e-02

Nearest Neighbor ID: 87

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self, radius=0):n3    def __init__(self,radius):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
n6        area = math.pi*self.radius**2n6        return math.pi*self.radius*self.radius
7        return area
8    def perimeter(self):7    def perimeter(self):
n9        perimeter = 2*math.pi*self.radiusn8        return 2*math.pi*self.radius
10        return perimeter
11if __name__=='__main__':9if __name__=='__main__':
12    x = int(input())10    x = int(input())
13    NewCircle = Circle(x)11    NewCircle = Circle(x)
14    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
15    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
16    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des14    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des
>cription = 'none'):>cription = 'none'):
17        self.item_name = item_name15        self.item_name = item_name
18        self.item_price = item_price16        self.item_price = item_price
19        self.item_quantity = item_quantity17        self.item_quantity = item_quantity
20        self.item_description = item_description18        self.item_description = item_description
21    def print_item_cost(self):19    def print_item_cost(self):
22        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, 20        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, 
>self.item_price,>self.item_price,
23        (self.item_quantity * self.item_price))21        (self.item_quantity * self.item_price))
24        cost = self.item_quantity * self.item_price22        cost = self.item_quantity * self.item_price
25        return string, cost23        return string, cost
26    def print_item_description(self):24    def print_item_description(self):
27        string = '{}: {}, %d oz.'.format(self.item_name, self.item_description, 25        string = '{}: {}, %d oz.'.format(self.item_name, self.item_description, 
>self.item_quantity)>self.item_quantity)
28        print(string)26        print(string)
29        return string27        return string
30class ShoppingCart:28class ShoppingCart:
n31    def __init__(self, customer_name = 'none', current_date = 'February 1, 2016'n29    def __init__(self, customer_name = 'none', current_date = 'January 1, 2016',
>, cart_items = []):> cart_items = []):
32        self.customer_name = customer_name30        self.customer_name = customer_name
33        self.current_date = current_date31        self.current_date = current_date
34        self.cart_items = cart_items32        self.cart_items = cart_items
35    def add_item(self):33    def add_item(self):
36        print('ADD ITEM TO CART')34        print('ADD ITEM TO CART')
37        item_name = str(input('Enter the item name:'))35        item_name = str(input('Enter the item name:'))
38        print()36        print()
39        item_description = str(input('Enter the item description:'))37        item_description = str(input('Enter the item description:'))
40        print()38        print()
41        item_price = int(input('Enter the item price:'))39        item_price = int(input('Enter the item price:'))
42        print()40        print()
43        item_quantity = int(input('Enter the item quantity:'))41        item_quantity = int(input('Enter the item quantity:'))
44        print()42        print()
45        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti43        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti
>ty, item_description))>ty, item_description))
46    def remove_item(self):44    def remove_item(self):
47        print('REMOVE ITEM FROM CART')45        print('REMOVE ITEM FROM CART')
48        string = str(input('Enter name of item to remove:'))46        string = str(input('Enter name of item to remove:'))
49        print()47        print()
50        i = 048        i = 0
51        for item in self.cart_items:49        for item in self.cart_items:
52            if(item.item_name == string):               50            if(item.item_name == string):               
53                del self.cart_items[i]51                del self.cart_items[i]
54                flag=True52                flag=True
55                break53                break
56            else:54            else:
57                flag=False55                flag=False
58            i += 156            i += 1
59        if(flag==False):57        if(flag==False):
60            print('Item not found in cart. Nothing removed.')58            print('Item not found in cart. Nothing removed.')
61    def modify_item(self):59    def modify_item(self):
62        print('CHANGE ITEM QUANTITY')60        print('CHANGE ITEM QUANTITY')
63        name = str(input('Enter the item name:'))61        name = str(input('Enter the item name:'))
64        print()62        print()
65        for item in self.cart_items:63        for item in self.cart_items:
66            if(item.item_name == name):64            if(item.item_name == name):
67                quantity = int(input('Enter the new quantity:'))65                quantity = int(input('Enter the new quantity:'))
68                print()66                print()
69                item.item_quantity = quantity67                item.item_quantity = quantity
70                flag=True68                flag=True
71                break69                break
72            else:70            else:
73                flag=False71                flag=False
74        if(flag==False):72        if(flag==False):
75            print('Item not found in cart. Nothing modified.')73            print('Item not found in cart. Nothing modified.')
76        print()74        print()
77    def get_num_items_in_cart(self):75    def get_num_items_in_cart(self):
78        num_items=076        num_items=0
nn77        for item in self.cart_items:
79        num_items= num_items+ item.item_quantity78            num_items= num_items+item.item_quantity
80        return num_items79        return num_items
81    def get_cost_of_cart(self):80    def get_cost_of_cart(self):
82        total_cost = 081        total_cost = 0
83        cost = 082        cost = 0
84        for item in self.cart_items:83        for item in self.cart_items:
85            cost = (item.item_quantity * item.item_price)84            cost = (item.item_quantity * item.item_price)
86            total_cost += cost85            total_cost += cost
87        return total_cost86        return total_cost
88    def print_total(self):87    def print_total(self):
89        total_cost = self.get_cost_of_cart()88        total_cost = self.get_cost_of_cart()
90        if (total_cost == 0):89        if (total_cost == 0):
91            print('SHOPPING CART IS EMPTY')90            print('SHOPPING CART IS EMPTY')
92        else:91        else:
93            self.output_cart()92            self.output_cart()
94    def print_descriptions(self):93    def print_descriptions(self):
95        print('OUTPUT ITEMS\' DESCRIPTIONS')94        print('OUTPUT ITEMS\' DESCRIPTIONS')
96        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current95        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date),end='\n')>_date),end='\n')
97        print('\nItem Descriptions')96        print('\nItem Descriptions')
98        for item in self.cart_items:97        for item in self.cart_items:
99            print('{}: {}'.format(item.item_name, item.item_description))98            print('{}: {}'.format(item.item_name, item.item_description))
100    def output_cart(self):99    def output_cart(self):
101        print('OUTPUT SHOPPING CART')100        print('OUTPUT SHOPPING CART')
102        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current101        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date))      >_date))      
103        print('Number of Items:', self.get_num_items_in_cart())102        print('Number of Items:', self.get_num_items_in_cart())
104        print()103        print()
105        tc = 0104        tc = 0
106        for item in self.cart_items:105        for item in self.cart_items:
107            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,106            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,
108              item.item_price, (item.item_quantity * item.item_price)))107              item.item_price, (item.item_quantity * item.item_price)))
109            tc += (item.item_quantity * item.item_price)108            tc += (item.item_quantity * item.item_price)
110        if len(self.cart_items) == 0:109        if len(self.cart_items) == 0:
111            print('SHOPPING CART IS EMPTY')110            print('SHOPPING CART IS EMPTY')
112        print()111        print()
113        print('Total: ${}'.format(tc))112        print('Total: ${}'.format(tc))
114def print_menu(customer_Cart):113def print_menu(customer_Cart):
115    menu = ('\nMENU\n'114    menu = ('\nMENU\n'
116    'a - Add item to cart\n'115    'a - Add item to cart\n'
117    'r - Remove item from cart\n'116    'r - Remove item from cart\n'
118    'c - Change item quantity\n'117    'c - Change item quantity\n'
119    'i - Output items\' descriptions\n'118    'i - Output items\' descriptions\n'
120    'o - Output shopping cart\n'119    'o - Output shopping cart\n'
121    'q - Quit\n')120    'q - Quit\n')
122    command = ''121    command = ''
123    while(command != 'q'):122    while(command != 'q'):
124        print(menu)123        print(menu)
125        command = input('Choose an option:')124        command = input('Choose an option:')
126        print()125        print()
127        while(command != 'a' and command != 'o' and command != 'i' and command !126        while(command != 'a' and command != 'o' and command != 'i' and command !
>= 'r'>= 'r'
128              and command != 'c' and command != 'q'):127              and command != 'c' and command != 'q'):
129            command = input('Choose an option:')128            command = input('Choose an option:')
130            print()129            print()
131        if(command == 'a'):130        if(command == 'a'):
132            customer_Cart.add_item()131            customer_Cart.add_item()
133        if(command == 'o'):132        if(command == 'o'):
134            customer_Cart.output_cart()133            customer_Cart.output_cart()
135        if(command == 'i'):134        if(command == 'i'):
136            customer_Cart.print_descriptions()135            customer_Cart.print_descriptions()
137        if(command == 'r'):136        if(command == 'r'):
138            customer_Cart.remove_item()137            customer_Cart.remove_item()
139        if(command == 'c'):138        if(command == 'c'):
140            customer_Cart.modify_item()139            customer_Cart.modify_item()
141def main():140def main():
142    customer_name = str(input('Enter customer\'s name:'))141    customer_name = str(input('Enter customer\'s name:'))
143    print()142    print()
144    current_date = str(input('Enter today\'s date:'))143    current_date = str(input('Enter today\'s date:'))
145    print('\n')144    print('\n')
146    print('Customer name:', customer_name, end='\n')145    print('Customer name:', customer_name, end='\n')
147    print('Today\'s date:', current_date, end='\n')146    print('Today\'s date:', current_date, end='\n')
148    newCart = ShoppingCart(customer_name, current_date)147    newCart = ShoppingCart(customer_name, current_date)
149    print_menu(newCart)148    print_menu(newCart)
150if __name__ == '__main__':149if __name__ == '__main__':
n151    main()import mathn150    main()from math import sqrt
152class pt3d:151class pt3d:
153    def __init__(self, x=0, y=0, z=0):152    def __init__(self, x=0, y=0, z=0):
154        self.x = x153        self.x = x
155        self.y = y154        self.y = y
156        self.z = z155        self.z = z
nn156    def __add__(self, other):
157        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
158    def __sub__(self, other):
159        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
 >her.z)**2)
157    def __eq__(self, other):160    def __eq__(self, other):
n158        if self.x == other.x and self.y == other.y and self.z == other.z:n161        return self.x == other.x & self.y == other.y & self.z == other.z
159            return True
160        else: 
161            return False
162    def __add__(self,other):
163        addition_x = self.x + other.x
164        addition_y = self.y + other.y
165        addition_z = self.z + other.z
166        return pt3d(addition_x,addition_y,addition_z)
167    def __eq__(self, other):
168        if self.x == other.x and self.y == other.y and self.z == other.z:
169            return True
170        else: 
171            return False
172    def __add__(self,other):
173        addition_x = self.x + other.x
174        addition_y = self.y + other.y
175        addition_z = self.z + other.z
176        return pt3d(addition_x,addition_y,addition_z)
177    def __sub__(self,other):
178        subtraction_x = self.x - other.x
179        subtraction_y = self.y - other.y
180        subtraction_z = self.z - other.z
181        distance = math.sqrt(subtraction_x**2 + subtraction_y**2 + subtraction_z
>**2) 
182        return distance
183    def __str__(self):162    def __str__(self):
t184        return(f'<{self.x},{self.y},{self.z}>')t163        return (f'<{self.x}, {self.y}, {self.z}>')
164p1 = pt3d(1, 1, 1)
165p2 = pt3d(2, 2, 2)
166print(p1 + p2)
167print(p1 - p2)
168print(p1 == p2)
169print(p1+p1 == p2)
170print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 52

Student ID: 63, P-Value: 1.97e-02

Nearest Neighbor ID: 88

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self, x):n3    def __init__(self, radius):
4        self.radius = x4        self.radius = radius
5    def area(self):5    def area(self):
n6        return self.radius**2*math.pin6        return math.pi*(self.radius**2)
7    def perimeter(self):7    def perimeter(self):
n8        return 2*self.radius*math.pin8        return 2*math.pi*self.radius
9if __name__=='__main__':9if __name__=='__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14   def __init__(self, name='none', price=0, quantity=0, description='none'):14   def __init__(self, name='none', price=0, quantity=0, description='none'):
15       self.item_name=name15       self.item_name=name
16       self.item_description=description16       self.item_description=description
17       self.item_price=price17       self.item_price=price
18       self.item_quantity=quantity18       self.item_quantity=quantity
19   def print_item_description(self):19   def print_item_description(self):
n20       print('%s: %s' % (self.item_name, self.item_description))      n20       print('%s: %s' % (self.item_name, self.item_description))
21class ShoppingCart:21class ShoppingCart:
22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 22   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
23       self.customer_name = customer_name23       self.customer_name = customer_name
24       self.current_date = current_date24       self.current_date = current_date
n25       self.cart_items = cart_itemsn25       self.cart_items = cart_items  
26   def add_item(self, itemToPurchase):26   def add_item(self, itemToPurchase):
27       self.cart_items.append(itemToPurchase)  27       self.cart_items.append(itemToPurchase)  
28   def remove_item(self, itemName):28   def remove_item(self, itemName):
29       tremove_item = False29       tremove_item = False
30       for item in self.cart_items:30       for item in self.cart_items:
31           if item.item_name == itemName:31           if item.item_name == itemName:
32               self.cart_items.remove(item)32               self.cart_items.remove(item)
33               tremove_item = True33               tremove_item = True
34               break34               break
35       if not tremove_item:          35       if not tremove_item:          
n36           print('Item not found in cart. Nothing removed.')n36           print('Item not found in the cart. Nothing removed.')
37   def modify_item(self, itemToPurchase):  37   def modify_item(self, itemToPurchase):  
38       tmodify_item = False38       tmodify_item = False
39       for i in range(len(self.cart_items)):39       for i in range(len(self.cart_items)):
40           if self.cart_items[i].item_name == itemToPurchase.item_name:40           if self.cart_items[i].item_name == itemToPurchase.item_name:
n41                tmodify_item = Truen41               tmodify_item = True
42                self.cart_items[i].item_quantity = itemToPurchase.item_quantity42               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43                break43               break
44       if not tmodify_item:      44       if not tmodify_item:      
n45        print('Item not found in cart. Nothing modified.')n45           print('Item not found in the cart. Nothing modified.')  
46   def get_num_items_in_cart(self):46   def get_num_items_in_cart(self):
47       num_items = 047       num_items = 0
48       for item in self.cart_items:48       for item in self.cart_items:
49           num_items = num_items + item.item_quantity49           num_items = num_items + item.item_quantity
50       return num_items50       return num_items
51   def get_cost_of_cart(self):51   def get_cost_of_cart(self):
52       total_cost = 052       total_cost = 0
53       cost = 053       cost = 0
54       for item in self.cart_items:54       for item in self.cart_items:
55           cost = (item.item_quantity * item.item_price)55           cost = (item.item_quantity * item.item_price)
56           total_cost += cost56           total_cost += cost
n57       return total_cost        n57       return total_cost
58   def print_total(self):58   def print_total(self):
59       total_cost = self.get_cost_of_cart()59       total_cost = self.get_cost_of_cart()
60       if (total_cost == 0):60       if (total_cost == 0):
61           print('SHOPPING CART IS EMPTY')61           print('SHOPPING CART IS EMPTY')
n62           print('Total: $0')n
63       else:62       else:
n64           print("{}'s Shopping Cart - {}".format(self.customer_name, self.curren63           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>nt_date))>ent_date))
65           print('Number of Items: %d\n' %self.get_num_items_in_cart())64           print('Number of Items: %d\n' %self.get_num_items_in_cart())
66           for item in self.cart_items:65           for item in self.cart_items:
67               total = item.item_price * item.item_quantity66               total = item.item_price * item.item_quantity
68               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 67               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
>item.item_price, total))>item.item_price, total))
69           print('\nTotal: $%d' %(total_cost))68           print('\nTotal: $%d' %(total_cost))
70   def print_descriptions(self):69   def print_descriptions(self):
71       if len(self.cart_items) == 0:70       if len(self.cart_items) == 0:
72           print('SHOPPING CART IS EMPTY')71           print('SHOPPING CART IS EMPTY')
73       else:  72       else:  
n74           print("{}'s Shopping Cart - {}\n".format(self.customer_name, self.curn73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>rent_date))>ent_date))
75           print('Item Descriptions')74           print('\nItem Descriptions')
76           for item in self.cart_items:75           for item in self.cart_items:
77               item.print_item_description()  76               item.print_item_description()  
78def print_menu(newCart):77def print_menu(newCart):
n79    customer_Cart = newCartn78   customer_Cart = newCart
80    menu = ('\nMENU\n')79   menu = ('\nMENU\n'
81    'a - Add item to cart\n'80       'a - Add item to cart\n'
82    'r - Remove item from cart\n'81       'r - Remove item from cart\n'
83    'c - Change item quantity\n'82       'c - Change item quantity\n'
84    "i - Output items' descriptions\n"83       "i - Output items' descriptions\n"
85    'o - Output shopping cart\n'84       'o - Output shopping cart\n'
86    'q - Quit\n'85       'q - Quit\n')
87    command = ''86   command = ''
88    while(command != 'q'):87   while(command != 'q'):
89        print(menu)88       print(menu)
90        command = input('Choose an option:\n')89       command = input('Choose an option:\n')
91    while(command != 'a' and command != 'o' and command != 'i' and command != 'q90       while(command != 'a' and command != 'o' and command != 'i' and command !=
>' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
92        command = input('Choose an option:\n')91           command = input('Choose an option:\n')
93        if(command == 'a'):92       if(command == 'a'):
94           print("ADD ITEM TO CART")93           print("\nADD ITEM TO CART")
95           print('Enter the item name:')
96           print('Enter the item description:')
97           print('Enter the item price:') 
98           print('Enter the item quantity:')
99           item_name = input('Enter the item name:')94           item_name = input('Enter the item name:\n')
100           item_description = input('Enter the item description:')95           item_description = input('Enter the item description:\n')
101           item_price = int(input('Enter the item price:'))96           item_price = int(input('Enter the item price:\n'))
102           item_quantity = int(input('Enter the item quantity:'))97           item_quantity = int(input('Enter the item quantity:\n'))
103           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,98           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
n104           customer_Cart.add_item(itemtoPurchase)      n99           customer_Cart.add_item(itemtoPurchase)
105        elif(command == 'o'):100       elif(command == 'o'):
106           print('OUTPUT SHOPPING CART')101           print('\nOUTPUT SHOPPING CART')
107           customer_Cart.print_total()102           customer_Cart.print_total()  
108        elif(command == 'i'):103       elif(command == 'i'):
109           print("OUTPUT ITEMS' DESCRIPTIONS")104           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
110           customer_Cart.print_descriptions()105           customer_Cart.print_descriptions()
n111        elif(command == 'r'):n106       elif(command == 'r'):
112           print('REMOVE ITEM FROM CART')107           print('REMOVE ITEM FROM CART')
n113           itemName = input('Enter name of item to remove:\n')n108           itemName = input('Enter name of item to remove :\n')
114           customer_Cart.remove_item(itemName)109           customer_Cart.remove_item(itemName)
n115        elif(command == 'c'):n110       elif(command == 'c'):
116           print('CHANGE ITEM QUANTITY')111           print('\nCHANGE ITEM QUANTITY')
117           itemName = input('Enter the item name:\n')112           itemName = input('Enter name of item :\n')
118           qty = int(input('Enter the new quantity:\n'))113           qty = int(input('Enter the new quantity :\n'))
119           itemToPurchase = ItemToPurchase(itemName,0,qty)114           itemToPurchase = ItemToPurchase(itemName,0,qty)
120           customer_Cart.modify_item(itemToPurchase)115           customer_Cart.modify_item(itemToPurchase)
121if __name__ == "__main__":116if __name__ == "__main__":
n122    customer_name = input("Enter customer's name:\n")n117   customer_name = input("Enter customer's name:\n")
123    current_date = input("Enter today's date:\n")118   current_date = input("Enter today's date:\n")
124    print()    
125    print("Customer name: %s" %customer_name)119   print("\nCustomer name: %s" %customer_name)
126    print("Today's date: %s" %current_date)120   print("Today's date: %s" %current_date)
127    newCart = ShoppingCart(customer_name, current_date)121   newCart = ShoppingCart(customer_name, current_date)
128    print_menu(newCart) 122   print_menu(newCart)from math import sqrt
129from math import sqrt
130class pt3d:123class pt3d:
n131    def __init__(self, x=0, y=0, z=0):n124    def __init__(self, x, y, z):
132        self.x = x125        self.x = x
133        self.y = y126        self.y = y
134        self.z = z127        self.z = z
135    def __add__(self, other):128    def __add__(self, other):
136        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)129        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
137    def __sub__(self, other):130    def __sub__(self, other):
n138        return sqrt(((self.x - other.x)**2) + ((self.y - other.y)**2) + ((self.zn131        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
> - other.z)**2))>her.z)**2)
139    def __eq__(self, other):132    def __eq__(self, other):
n140        return ((self.x == other.x) & (self.y == other.y) & (self.z == other.z))n133        return self.x == other.x and self.y == other.y and self.z == other.z
141    def __str__(self):134    def __str__(self):
t142        return '<{},{},{}>'.format(self.x, self.y, self.z)t135        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
143p1 = pt3d(1, 1, 1)136p1 = pt3d(1, 1, 1)
144p2 = pt3d(2, 2, 2)137p2 = pt3d(2, 2, 2)
145print(p1 + p2)138print(p1 + p2)
146print(p1 - p2)139print(p1 - p2)
147print(p1 == p2)140print(p1 == p2)
148print(p1+p1 == p2)141print(p1+p1 == p2)
149print(p1==p2+pt3d(-1, -1, -1))142print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 53

Student ID: 461, P-Value: 2.00e-02

Nearest Neighbor ID: 418

Student (left) and Nearest Neighbor (right).


n1import math as azmainn1import math
2class Circle:2class Circle:
n3    def __init__(self, radius):n3    def __init__(self,radius):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
nn6        import math as m
6        return (azmain.pi * (self.radius ** 2))7        return m.pi*(self.radius)**2
7    def perimeter(self):8    def perimeter(self):
nn9        import math as m
8        return (azmain.pi * self.radius * 2)10        return 2*m.pi*self.radius
9if __name__=='__main__':11if __name__=='__main__':
10    x = int(input())12    x = int(input())
11    NewCircle = Circle(x)13    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))14    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))choball = {}15    print('{:.5f}'.format(NewCircle.perimeter()))choball = {}
14class ItemToPurchase:16class ItemToPurchase:
15    global choball17    global choball
16    def __init__(self):18    def __init__(self):
17        self.item_name = 'none'19        self.item_name = 'none'
18        self.item_price = 020        self.item_price = 0
19        self.item_quantity = 021        self.item_quantity = 0
20        self.item_description = 'none'22        self.item_description = 'none'
21    def __str__(self):23    def __str__(self):
22        cost = self.item_price * self.item_quantity24        cost = self.item_price * self.item_quantity
23        return f'{self.item_name} {self.item_quantity} @ ${self.item_price} = ${25        return f'{self.item_name} {self.item_quantity} @ ${self.item_price} = ${
>cost}'>cost}'
24    def print_item_cost(self):26    def print_item_cost(self):
25        print(self)27        print(self)
26    def print_item_description(self):28    def print_item_description(self):
27        print(f'{self.item_name}: {self.item_description}')29        print(f'{self.item_name}: {self.item_description}')
28class ShoppingCart:30class ShoppingCart:
29    def __init__(self, name='none', date='January 1, 2016'):31    def __init__(self, name='none', date='January 1, 2016'):
30        self.customer_name = name32        self.customer_name = name
31        self.current_date = date33        self.current_date = date
32        self.cart_items = []34        self.cart_items = []
33    def add_item(self, item):35    def add_item(self, item):
34        self.cart_items.append(item.item_name)36        self.cart_items.append(item.item_name)
35    def remove_item(self, item):37    def remove_item(self, item):
36        if item in self.cart_items:38        if item in self.cart_items:
37            self.cart_items.remove(item)39            self.cart_items.remove(item)
38        else:40        else:
39            print('Item not found in cart. Nothing removed.')41            print('Item not found in cart. Nothing removed.')
40    def modify_items(self, item):42    def modify_items(self, item):
41        newItem = ItemToPurchase()43        newItem = ItemToPurchase()
42        print('Enter the new quantity:')44        print('Enter the new quantity:')
43        if item in self.cart_items:45        if item in self.cart_items:
44            newItem.item_name = item46            newItem.item_name = item
45            newItem.item_description = choball[item][2]47            newItem.item_description = choball[item][2]
46            newItem.item_price = choball[item][0]48            newItem.item_price = choball[item][0]
47            newItem.item_quantity = input()49            newItem.item_quantity = input()
48            choball[item][1] = newItem.item_quantity50            choball[item][1] = newItem.item_quantity
49        else:51        else:
50            print('Item not found in cart. Nothing modified.')52            print('Item not found in cart. Nothing modified.')
51    def get_num_items_in_cart(self):53    def get_num_items_in_cart(self):
52        numItems = 054        numItems = 0
53        for item in self.cart_items:55        for item in self.cart_items:
54            if item in choball:56            if item in choball:
55                numItems += int(choball[item][1])57                numItems += int(choball[item][1])
56        return numItems58        return numItems
57    def get_cost_of_cart(self):59    def get_cost_of_cart(self):
58        totalCost = 060        totalCost = 0
59        for item in self.cart_items:61        for item in self.cart_items:
60            if item in choball:62            if item in choball:
61                p=int(choball[item][0])63                p=int(choball[item][0])
62                q=int(choball[item][1])64                q=int(choball[item][1])
n63                itemCost = int(p * q)n65                itemCost = p * q
64                totalCost += itemCost66                totalCost += itemCost
65        return totalCost67        return totalCost
66    def print_total(self):68    def print_total(self):
67        numItems = self.get_num_items_in_cart()69        numItems = self.get_num_items_in_cart()
68        if numItems == 0:70        if numItems == 0:
69            print(f"{self.customer_name}'s Shopping Cart - {self.current_date}")71            print(f"{self.customer_name}'s Shopping Cart - {self.current_date}")
70            print(f"Number of Items: {numItems}")72            print(f"Number of Items: {numItems}")
71            print()73            print()
72            print('SHOPPING CART IS EMPTY')74            print('SHOPPING CART IS EMPTY')
73            print()75            print()
74            print(f"Total: ${self.get_cost_of_cart()}")76            print(f"Total: ${self.get_cost_of_cart()}")
75        else:77        else:
76            print(f"{self.customer_name}'s Shopping Cart - {self.current_date}")78            print(f"{self.customer_name}'s Shopping Cart - {self.current_date}")
77            print(f"Number of Items: {numItems}")79            print(f"Number of Items: {numItems}")
78            print()80            print()
79            for item in self.cart_items:81            for item in self.cart_items:
80                cost = int(choball[item][1]) * int(choball[item][0])82                cost = int(choball[item][1]) * int(choball[item][0])
81                print(f'{item} {choball[item][1]} @ ${choball[item][0]} = ${cost83                print(f'{item} {choball[item][1]} @ ${choball[item][0]} = ${cost
>}')>}')
82            print()84            print()
83            print(f"Total: ${self.get_cost_of_cart()}")85            print(f"Total: ${self.get_cost_of_cart()}")
84    def print_descriptions(self):86    def print_descriptions(self):
85        print("OUTPUT ITEMS' DESCRIPTIONS")87        print("OUTPUT ITEMS' DESCRIPTIONS")
86        print(f"{self.customer_name}'s Shopping Cart - {self.current_date}")88        print(f"{self.customer_name}'s Shopping Cart - {self.current_date}")
87        print()89        print()
88        print('Item Descriptions')90        print('Item Descriptions')
89        for item in self.cart_items:91        for item in self.cart_items:
90            print(f'{item}: {choball[item][2]}')92            print(f'{item}: {choball[item][2]}')
91def print_menu():93def print_menu():
92    print('MENU')94    print('MENU')
93    print('a - Add item to cart')95    print('a - Add item to cart')
94    print('r - Remove item from cart')96    print('r - Remove item from cart')
95    print('c - Change item quantity')97    print('c - Change item quantity')
96    print("i - Output items' descriptions")98    print("i - Output items' descriptions")
97    print('o - Output shopping cart')99    print('o - Output shopping cart')
98    print('q - Quit')100    print('q - Quit')
99def execute_menu(choice, cart):101def execute_menu(choice, cart):
100    if choice == 'a':102    if choice == 'a':
101        item = ItemToPurchase()103        item = ItemToPurchase()
102        print('ADD ITEM TO CART')104        print('ADD ITEM TO CART')
103        print('Enter the item name:')105        print('Enter the item name:')
104        item.item_name = input()106        item.item_name = input()
105        print('Enter the item description:')107        print('Enter the item description:')
106        item.item_description = input()108        item.item_description = input()
107        print('Enter the item price:')109        print('Enter the item price:')
108        item.item_price = input()110        item.item_price = input()
109        print('Enter the item quantity:')111        print('Enter the item quantity:')
110        item.item_quantity = input()112        item.item_quantity = input()
111        cart.add_item(item)113        cart.add_item(item)
112        choball[item.item_name] = [item.item_price, item.item_quantity, item.ite114        choball[item.item_name] = [item.item_price, item.item_quantity, item.ite
>m_description]>m_description]
113        print()115        print()
114        print_menu()116        print_menu()
115        print()117        print()
116    elif choice == 'r':118    elif choice == 'r':
117        print('REMOVE ITEM FROM CART')119        print('REMOVE ITEM FROM CART')
118        print('Enter name of item to remove:')120        print('Enter name of item to remove:')
119        item = input()121        item = input()
120        cart.remove_item(item)122        cart.remove_item(item)
121        print()123        print()
122        print_menu()124        print_menu()
123        print()125        print()
124    elif choice == 'c':126    elif choice == 'c':
125        print('CHANGE ITEM QUANTITY')127        print('CHANGE ITEM QUANTITY')
126        print('Enter the item name:')128        print('Enter the item name:')
127        itema = input()129        itema = input()
128        cart.modify_items(itema)130        cart.modify_items(itema)
129        print()131        print()
130        print_menu()132        print_menu()
131        print()133        print()
132    elif choice == 'i':134    elif choice == 'i':
133        print("OUTPUT ITEMS' DESCRIPTIONS")135        print("OUTPUT ITEMS' DESCRIPTIONS")
134        cart.print_descriptions()136        cart.print_descriptions()
135        print()137        print()
136        print_menu()138        print_menu()
137        print()139        print()
138    elif choice == 'o':140    elif choice == 'o':
139        print('OUTPUT SHOPPING CART')141        print('OUTPUT SHOPPING CART')
140        cart.print_total()142        cart.print_total()
141        print()143        print()
142        print_menu()144        print_menu()
143        print()145        print()
144if __name__ == "__main__":146if __name__ == "__main__":
145    print("Enter customer's name:")147    print("Enter customer's name:")
146    name = input()148    name = input()
147    print("Enter today's date:")149    print("Enter today's date:")
148    date = input()150    date = input()
149    print()151    print()
150    print(f'Customer name: {name}')152    print(f'Customer name: {name}')
151    print(f"Today's date: {date}")153    print(f"Today's date: {date}")
152    print()154    print()
153    cart = ShoppingCart(name,date)155    cart = ShoppingCart(name,date)
154    print_menu()156    print_menu()
155    print()157    print()
156    print("Choose an option:")158    print("Choose an option:")
157    choice = input()159    choice = input()
158    while choice != 'q':160    while choice != 'q':
159        execute_menu(choice, cart)161        execute_menu(choice, cart)
160        print("Choose an option:")162        print("Choose an option:")
161        choice = input()163        choice = input()
n162import math as choballn
163class pt3d:164class pt3d:
n164    def __init__(self, x=0, y=0, z=0):n165    def __init__(self,x=0,y=0,z=0):
165        self.x = x166        self.x=x
166        self.y = y167        self.y=y
167        self.z = z168        self.z=z
168    def __str__(self) -> str:169    def __str__(self):
169        return f'<{self.x},{self.y},{self.z}>'170        return "<{},{},{}>".format(self.x,self.y,self.z)
170    def __add__(self, other):171    def __add__(self,other):
171        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)172        return pt3d(self.x+other.x,self.y+other.y,self.z+other.z)
172    def __sub__(self, other):173    def __sub__(self,other):
173        return choball.sqrt((other.x - self.x)**2 + (other.y - self.y)**2 + (oth174        import math as m
>er.z - self.z)**2) 
175        return m.sqrt((self.x-other.x)**2+(self.y-other.y)**2+(self.z-other.z)**
 >2)
174    def __eq__(self, other):176    def __eq__(self,other):
175        if (self.x == other.x) and (self.y == other.y) and (self.z == other.z):177        if (self.x==other.x) and (self.y==other.y) and (self.z==other.z):
176            return True178            return True
t177        else:t
178            return False179        return False
179if __name__ == "__main__":
180    a = pt3d(1,1,1)
181    b = pt3d(2,2,2)
182    print(a+b)
183    print(a-b)
184    a==b
185    a+a==b
186    a==b+pt3d(-1,-1,-1)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 54

Student ID: 418, P-Value: 2.00e-02

Nearest Neighbor ID: 461

Student (left) and Nearest Neighbor (right).


n1import mathn1import math as azmain
2class Circle:2class Circle:
n3    def __init__(self,radius):n3    def __init__(self, radius):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
n6        import math as mn
7        return m.pi*(self.radius)**26        return (azmain.pi * (self.radius ** 2))
8    def perimeter(self):7    def perimeter(self):
n9        import math as mn
10        return 2*m.pi*self.radius8        return (azmain.pi * self.radius * 2)
11if __name__=='__main__':9if __name__=='__main__':
12    x = int(input())10    x = int(input())
13    NewCircle = Circle(x)11    NewCircle = Circle(x)
14    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
15    print('{:.5f}'.format(NewCircle.perimeter()))choball = {}13    print('{:.5f}'.format(NewCircle.perimeter()))choball = {}
16class ItemToPurchase:14class ItemToPurchase:
17    global choball15    global choball
18    def __init__(self):16    def __init__(self):
19        self.item_name = 'none'17        self.item_name = 'none'
20        self.item_price = 018        self.item_price = 0
21        self.item_quantity = 019        self.item_quantity = 0
22        self.item_description = 'none'20        self.item_description = 'none'
23    def __str__(self):21    def __str__(self):
24        cost = self.item_price * self.item_quantity22        cost = self.item_price * self.item_quantity
25        return f'{self.item_name} {self.item_quantity} @ ${self.item_price} = ${23        return f'{self.item_name} {self.item_quantity} @ ${self.item_price} = ${
>cost}'>cost}'
26    def print_item_cost(self):24    def print_item_cost(self):
27        print(self)25        print(self)
28    def print_item_description(self):26    def print_item_description(self):
29        print(f'{self.item_name}: {self.item_description}')27        print(f'{self.item_name}: {self.item_description}')
30class ShoppingCart:28class ShoppingCart:
31    def __init__(self, name='none', date='January 1, 2016'):29    def __init__(self, name='none', date='January 1, 2016'):
32        self.customer_name = name30        self.customer_name = name
33        self.current_date = date31        self.current_date = date
34        self.cart_items = []32        self.cart_items = []
35    def add_item(self, item):33    def add_item(self, item):
36        self.cart_items.append(item.item_name)34        self.cart_items.append(item.item_name)
37    def remove_item(self, item):35    def remove_item(self, item):
38        if item in self.cart_items:36        if item in self.cart_items:
39            self.cart_items.remove(item)37            self.cart_items.remove(item)
40        else:38        else:
41            print('Item not found in cart. Nothing removed.')39            print('Item not found in cart. Nothing removed.')
42    def modify_items(self, item):40    def modify_items(self, item):
43        newItem = ItemToPurchase()41        newItem = ItemToPurchase()
44        print('Enter the new quantity:')42        print('Enter the new quantity:')
45        if item in self.cart_items:43        if item in self.cart_items:
46            newItem.item_name = item44            newItem.item_name = item
47            newItem.item_description = choball[item][2]45            newItem.item_description = choball[item][2]
48            newItem.item_price = choball[item][0]46            newItem.item_price = choball[item][0]
49            newItem.item_quantity = input()47            newItem.item_quantity = input()
50            choball[item][1] = newItem.item_quantity48            choball[item][1] = newItem.item_quantity
51        else:49        else:
52            print('Item not found in cart. Nothing modified.')50            print('Item not found in cart. Nothing modified.')
53    def get_num_items_in_cart(self):51    def get_num_items_in_cart(self):
54        numItems = 052        numItems = 0
55        for item in self.cart_items:53        for item in self.cart_items:
56            if item in choball:54            if item in choball:
57                numItems += int(choball[item][1])55                numItems += int(choball[item][1])
58        return numItems56        return numItems
59    def get_cost_of_cart(self):57    def get_cost_of_cart(self):
60        totalCost = 058        totalCost = 0
61        for item in self.cart_items:59        for item in self.cart_items:
62            if item in choball:60            if item in choball:
63                p=int(choball[item][0])61                p=int(choball[item][0])
64                q=int(choball[item][1])62                q=int(choball[item][1])
n65                itemCost = p * qn63                itemCost = int(p * q)
66                totalCost += itemCost64                totalCost += itemCost
67        return totalCost65        return totalCost
68    def print_total(self):66    def print_total(self):
69        numItems = self.get_num_items_in_cart()67        numItems = self.get_num_items_in_cart()
70        if numItems == 0:68        if numItems == 0:
71            print(f"{self.customer_name}'s Shopping Cart - {self.current_date}")69            print(f"{self.customer_name}'s Shopping Cart - {self.current_date}")
72            print(f"Number of Items: {numItems}")70            print(f"Number of Items: {numItems}")
73            print()71            print()
74            print('SHOPPING CART IS EMPTY')72            print('SHOPPING CART IS EMPTY')
75            print()73            print()
76            print(f"Total: ${self.get_cost_of_cart()}")74            print(f"Total: ${self.get_cost_of_cart()}")
77        else:75        else:
78            print(f"{self.customer_name}'s Shopping Cart - {self.current_date}")76            print(f"{self.customer_name}'s Shopping Cart - {self.current_date}")
79            print(f"Number of Items: {numItems}")77            print(f"Number of Items: {numItems}")
80            print()78            print()
81            for item in self.cart_items:79            for item in self.cart_items:
82                cost = int(choball[item][1]) * int(choball[item][0])80                cost = int(choball[item][1]) * int(choball[item][0])
83                print(f'{item} {choball[item][1]} @ ${choball[item][0]} = ${cost81                print(f'{item} {choball[item][1]} @ ${choball[item][0]} = ${cost
>}')>}')
84            print()82            print()
85            print(f"Total: ${self.get_cost_of_cart()}")83            print(f"Total: ${self.get_cost_of_cart()}")
86    def print_descriptions(self):84    def print_descriptions(self):
87        print("OUTPUT ITEMS' DESCRIPTIONS")85        print("OUTPUT ITEMS' DESCRIPTIONS")
88        print(f"{self.customer_name}'s Shopping Cart - {self.current_date}")86        print(f"{self.customer_name}'s Shopping Cart - {self.current_date}")
89        print()87        print()
90        print('Item Descriptions')88        print('Item Descriptions')
91        for item in self.cart_items:89        for item in self.cart_items:
92            print(f'{item}: {choball[item][2]}')90            print(f'{item}: {choball[item][2]}')
93def print_menu():91def print_menu():
94    print('MENU')92    print('MENU')
95    print('a - Add item to cart')93    print('a - Add item to cart')
96    print('r - Remove item from cart')94    print('r - Remove item from cart')
97    print('c - Change item quantity')95    print('c - Change item quantity')
98    print("i - Output items' descriptions")96    print("i - Output items' descriptions")
99    print('o - Output shopping cart')97    print('o - Output shopping cart')
100    print('q - Quit')98    print('q - Quit')
101def execute_menu(choice, cart):99def execute_menu(choice, cart):
102    if choice == 'a':100    if choice == 'a':
103        item = ItemToPurchase()101        item = ItemToPurchase()
104        print('ADD ITEM TO CART')102        print('ADD ITEM TO CART')
105        print('Enter the item name:')103        print('Enter the item name:')
106        item.item_name = input()104        item.item_name = input()
107        print('Enter the item description:')105        print('Enter the item description:')
108        item.item_description = input()106        item.item_description = input()
109        print('Enter the item price:')107        print('Enter the item price:')
110        item.item_price = input()108        item.item_price = input()
111        print('Enter the item quantity:')109        print('Enter the item quantity:')
112        item.item_quantity = input()110        item.item_quantity = input()
113        cart.add_item(item)111        cart.add_item(item)
114        choball[item.item_name] = [item.item_price, item.item_quantity, item.ite112        choball[item.item_name] = [item.item_price, item.item_quantity, item.ite
>m_description]>m_description]
115        print()113        print()
116        print_menu()114        print_menu()
117        print()115        print()
118    elif choice == 'r':116    elif choice == 'r':
119        print('REMOVE ITEM FROM CART')117        print('REMOVE ITEM FROM CART')
120        print('Enter name of item to remove:')118        print('Enter name of item to remove:')
121        item = input()119        item = input()
122        cart.remove_item(item)120        cart.remove_item(item)
123        print()121        print()
124        print_menu()122        print_menu()
125        print()123        print()
126    elif choice == 'c':124    elif choice == 'c':
127        print('CHANGE ITEM QUANTITY')125        print('CHANGE ITEM QUANTITY')
128        print('Enter the item name:')126        print('Enter the item name:')
129        itema = input()127        itema = input()
130        cart.modify_items(itema)128        cart.modify_items(itema)
131        print()129        print()
132        print_menu()130        print_menu()
133        print()131        print()
134    elif choice == 'i':132    elif choice == 'i':
135        print("OUTPUT ITEMS' DESCRIPTIONS")133        print("OUTPUT ITEMS' DESCRIPTIONS")
136        cart.print_descriptions()134        cart.print_descriptions()
137        print()135        print()
138        print_menu()136        print_menu()
139        print()137        print()
140    elif choice == 'o':138    elif choice == 'o':
141        print('OUTPUT SHOPPING CART')139        print('OUTPUT SHOPPING CART')
142        cart.print_total()140        cart.print_total()
143        print()141        print()
144        print_menu()142        print_menu()
145        print()143        print()
146if __name__ == "__main__":144if __name__ == "__main__":
147    print("Enter customer's name:")145    print("Enter customer's name:")
148    name = input()146    name = input()
149    print("Enter today's date:")147    print("Enter today's date:")
150    date = input()148    date = input()
151    print()149    print()
152    print(f'Customer name: {name}')150    print(f'Customer name: {name}')
153    print(f"Today's date: {date}")151    print(f"Today's date: {date}")
154    print()152    print()
155    cart = ShoppingCart(name,date)153    cart = ShoppingCart(name,date)
156    print_menu()154    print_menu()
157    print()155    print()
158    print("Choose an option:")156    print("Choose an option:")
159    choice = input()157    choice = input()
160    while choice != 'q':158    while choice != 'q':
161        execute_menu(choice, cart)159        execute_menu(choice, cart)
162        print("Choose an option:")160        print("Choose an option:")
163        choice = input()161        choice = input()
nn162import math as choball
164class pt3d:163class pt3d:
n165    def __init__(self,x=0,y=0,z=0):n164    def __init__(self, x=0, y=0, z=0):
166        self.x=x165        self.x = x
167        self.y=y166        self.y = y
168        self.z=z167        self.z = z
169    def __str__(self):168    def __str__(self) -> str:
170        return "<{},{},{}>".format(self.x,self.y,self.z)169        return f'<{self.x},{self.y},{self.z}>'
171    def __add__(self,other):170    def __add__(self, other):
172        return pt3d(self.x+other.x,self.y+other.y,self.z+other.z)171        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
173    def __sub__(self,other):172    def __sub__(self, other):
174        import math as m173        return choball.sqrt((other.x - self.x)**2 + (other.y - self.y)**2 + (oth
 >er.z - self.z)**2)
175        return m.sqrt((self.x-other.x)**2+(self.y-other.y)**2+(self.z-other.z)**
>2) 
176    def __eq__(self,other):174    def __eq__(self, other):
177        if (self.x==other.x) and (self.y==other.y) and (self.z==other.z):175        if (self.x == other.x) and (self.y == other.y) and (self.z == other.z):
178            return True176            return True
tt177        else:
179        return False178            return False
179if __name__ == "__main__":
180    a = pt3d(1,1,1)
181    b = pt3d(2,2,2)
182    print(a+b)
183    print(a-b)
184    a==b
185    a+a==b
186    a==b+pt3d(-1,-1,-1)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 55

Student ID: 373, P-Value: 2.14e-02

Nearest Neighbor ID: 475

Student (left) and Nearest Neighbor (right).


nn1import math
1class Circle():2class Circle:
2    def __init__(self, r):3    def __init__(self,radius):
3        self.radius = r4       self.radius=radius
4    def area(self):5    def area(self):
n5        return self.radius**2*3.14n6        area=math.pi*self.radius**2
7        return area
6    def perimeter(self):8    def perimeter(self):
n7        return 2*self.radius*3.14n9        perimeter=2*math.pi*self.radius
10        return perimeter
11if __name__=='__main__':
12    x = int(input())
8NewCircle = Circle()13    NewCircle = Circle(x)
9print(NewCircle.area())14    print('{:.5f}'.format(NewCircle.area()))
10print(NewCircle.perimeter())15    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
11class ItemToPurchase:
12    def __init__(self, item_name= 'none', item_price=0, item_quantity=0, item_de16    def __init__(self, item_name= 'none', item_price=0, item_quantity=0, item_de
>scription = 'none'):>scription = 'none'):
13        self.item_name = item_name17        self.item_name = item_name
14        self.item_price = item_price18        self.item_price = item_price
15        self.item_quantity = item_quantity19        self.item_quantity = item_quantity
16        self.item_description = item_description20        self.item_description = item_description
17    def print_item_cost(self):21    def print_item_cost(self):
18        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, 22        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, 
>self.item_price, (self.item_quantity >self.item_price, (self.item_quantity 
19* self.item_price))23* self.item_price))
20        cost = self.item_quantity * self.item_price24        cost = self.item_quantity * self.item_price
21        return string, cost25        return string, cost
22    def print_item_description(self):26    def print_item_description(self):
23        string = '{}: {}'.format(self.item_name, self.item_description)27        string = '{}: {}'.format(self.item_name, self.item_description)
24        print(string, end=' ')28        print(string, end=' ')
25        return string29        return string
26class ShoppingCart:30class ShoppingCart:
27    def __init__(self,customer_name= None ,current_date='January 1,2016',cart_it31    def __init__(self,customer_name= None ,current_date='January 1,2016',cart_it
>ems=[]):>ems=[]):
28        self.customer_name = customer_name32        self.customer_name = customer_name
29        self.current_date = current_date33        self.current_date = current_date
30        self.cart_items = cart_items34        self.cart_items = cart_items
31def add_item(self,):35def add_item(self,):
32    print('\nADD ITEM TO CART', end='\n')36    print('\nADD ITEM TO CART', end='\n')
33    item_name = str(input('Enter the item name:'));37    item_name = str(input('Enter the item name:'));
34    item_description = str(input('\nEnter the item description:'));38    item_description = str(input('\nEnter the item description:'));
35    item_price = int(input('\nEnter the item price:'));39    item_price = int(input('\nEnter the item price:'));
36    item_quantity = int(input('\nEnter the item quantity:\n'))40    item_quantity = int(input('\nEnter the item quantity:\n'))
37    self.cart_items.append(ItemToPurchase(item_name, item_price, item_quantity, 41    self.cart_items.append(ItemToPurchase(item_name, item_price, item_quantity, 
>item_description))>item_description))
38def remove_item(self):42def remove_item(self):
39    print()43    print()
40    print('REMOVE ITEM FROM CART', end='\n')44    print('REMOVE ITEM FROM CART', end='\n')
41    string = str(input('Enter name of item to remove:\n'))45    string = str(input('Enter name of item to remove:\n'))
42    i = 046    i = 0
43    for item in self.cart_items:47    for item in self.cart_items:
44        if(item.item_name == string):               48        if(item.item_name == string):               
45            del self.cart_items[i]49            del self.cart_items[i]
46            i += 150            i += 1
47            flag=True51            flag=True
48            break52            break
49        else:53        else:
50            flag=False54            flag=False
51    if(flag==False):55    if(flag==False):
52        print('Item not found in cart. Nothing removed.')56        print('Item not found in cart. Nothing removed.')
53def modify_item(self):57def modify_item(self):
54    print('\nCHANGE ITEM QUANTITY', end='\n')58    print('\nCHANGE ITEM QUANTITY', end='\n')
55    name = str(input('Enter the item name:'))       59    name = str(input('Enter the item name:'))       
56    for item in self.cart_items:60    for item in self.cart_items:
57        if(item.item_name == name):61        if(item.item_name == name):
58            quantity = int(input('Enter the new quantity:'))62            quantity = int(input('Enter the new quantity:'))
59            item.item_quantity = quantity63            item.item_quantity = quantity
60            flag=True64            flag=True
61            break65            break
62        else:66        else:
63            flag=False67            flag=False
64    if(flag==False):68    if(flag==False):
65        print('Item not found in cart. Nothing modified.')69        print('Item not found in cart. Nothing modified.')
66def get_num_items_in_cart(self):70def get_num_items_in_cart(self):
67    num_items = 071    num_items = 0
68    for item in self.cart_items:72    for item in self.cart_items:
69        num_items += item.item_quantity73        num_items += item.item_quantity
70    return num_items74    return num_items
71def get_cost_of_cart(self):75def get_cost_of_cart(self):
72    total_cost = 076    total_cost = 0
73    cost = 077    cost = 0
74    for item in self.cart_items:78    for item in self.cart_items:
75        cost = (item.item_quantity * item.item_price)79        cost = (item.item_quantity * item.item_price)
76        total_cost += cost80        total_cost += cost
77    return total_cost81    return total_cost
78def print_total():82def print_total():
79   total_cost = self.get_cost_of_cart()83   total_cost = self.get_cost_of_cart()
80   if (total_cost == 0):84   if (total_cost == 0):
81       print('SHOPPING CART IS EMPTY')85       print('SHOPPING CART IS EMPTY')
82   else:86   else:
83       output_cart()87       output_cart()
84def print_descriptions(self):88def print_descriptions(self):
85    print('OUTPUT ITEMS\' DESCRIPTIONS')89    print('OUTPUT ITEMS\' DESCRIPTIONS')
86    print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current_dat90    print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current_dat
>e),end='\n')>e),end='\n')
87    print('\nItem Descriptions', end='\n')91    print('\nItem Descriptions', end='\n')
88    for item in self.cart_items:92    for item in self.cart_items:
89        print('{}: {}'.format(item.item_name, item.item_description), end='\n')93        print('{}: {}'.format(item.item_name, item.item_description), end='\n')
90def output_cart(self):94def output_cart(self):
91    new=ShoppingCart()95    new=ShoppingCart()
92    print('OUTPUT SHOPPING CART', end='\n')96    print('OUTPUT SHOPPING CART', end='\n')
93    print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current_dat97    print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current_dat
>e),end='\n')      >e),end='\n')      
94    print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')98    print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')
95    self.total_cost = self.get_cost_of_cart()99    self.total_cost = self.get_cost_of_cart()
96    if (self.total_cost == 0):100    if (self.total_cost == 0):
97       print('SHOPPING CART IS EMPTY')101       print('SHOPPING CART IS EMPTY')
98    else:102    else:
99        pass103        pass
100    tc = 0104    tc = 0
101    for item in self.cart_items:105    for item in self.cart_items:
102        print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,106        print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,
103                                         item.item_price, (item.item_quantity * 107                                         item.item_price, (item.item_quantity * 
>item.item_price)), end='\n')>item.item_price)), end='\n')
104        tc += (item.item_quantity * item.item_price)108        tc += (item.item_quantity * item.item_price)
105    print('\nTotal: ${}'.format(tc), end='\n')109    print('\nTotal: ${}'.format(tc), end='\n')
106def print_menu(new_cart):110def print_menu(new_cart):
107    customer_Cart = newCart111    customer_Cart = newCart
108    string=''112    string=''
n109   menu = ('\nMENU\n'n113   menu = ('\nMENU\n')
110        'a - Add item to cart\n'114        'a - Add item to cart\n'
111        'r - Remove item from cart\n'115        'r - Remove item from cart\n'
112        'c - Change item quantity\n'116        'c - Change item quantity\n'
113        'i - Output items\' descriptions\n'117        'i - Output items\' descriptions\n'
114        'o - Output shopping cart\n'118        'o - Output shopping cart\n'
115        'q - Quit\n')119        'q - Quit\n')
116    command = ''120    command = ''
117    while(command != 'q'):121    while(command != 'q'):
118        string=''122        string=''
119        print('\nMENU\n'123        print('\nMENU\n'
120        'a - Add item to cart\n'124        'a - Add item to cart\n'
121        'r - Remove item from cart\n'125        'r - Remove item from cart\n'
122        'c - Change item quantity\n'126        'c - Change item quantity\n'
123        'i - Output items\' descriptions\n'127        'i - Output items\' descriptions\n'
124        'o - Output shopping cart\n'128        'o - Output shopping cart\n'
125        'q - Quit\n', end='\n')129        'q - Quit\n', end='\n')
126        command = input('Choose an option:')130        command = input('Choose an option:')
127        print()131        print()
128        while(command != 'a' and command != 'o' and command != 'i' and command !132        while(command != 'a' and command != 'o' and command != 'i' and command !
>= 'r' and command != 'c' and command != 'q'):>= 'r' and command != 'c' and command != 'q'):
129        command = input('Choose an option:\n')133        command = input('Choose an option:\n')
130    if(command == 'a'):134    if(command == 'a'):
131        customer_Cart.add_item()135        customer_Cart.add_item()
132    if(command == 'o'):136    if(command == 'o'):
133        customer_Cart.output_cart()137        customer_Cart.output_cart()
134    if(command == 'i'):138    if(command == 'i'):
135        customer_Cart.print_descriptions()139        customer_Cart.print_descriptions()
136    if(command == 'r'):140    if(command == 'r'):
137        customer_Cart.remove_item()141        customer_Cart.remove_item()
138    if(command == 'c'):142    if(command == 'c'):
139        customer_Cart.modify_item()143        customer_Cart.modify_item()
140if __name__ == "__main__":144if __name__ == "__main__":
141    customer_name = str(input('Enter customer\'s name:'))145    customer_name = str(input('Enter customer\'s name:'))
142    current_date = str(input('\nEnter today\'s date:'))146    current_date = str(input('\nEnter today\'s date:'))
143    print()147    print()
144    print()148    print()
145    print('Customer name:', customer_name, end='\n')149    print('Customer name:', customer_name, end='\n')
146    print('Today\'s date:', current_date, end='\n')150    print('Today\'s date:', current_date, end='\n')
147    newCart = ShoppingCart(customer_name, current_date)151    newCart = ShoppingCart(customer_name, current_date)
n148    print_menu(newCart)    n152    print_menu(newCart)
153import math
149class pt3d:154class pt3d:
n150    def __init__(self, x, y, z):n155    def __init__(self,x=0,y=0,z=0):
151        self.x = x156       self.x=x
152        self.y = y157       self.y=y       
153        self.z = z158       self.z=z
154    def __add__(self,other):159    def __add__ (self,other):
155        return pt3d(self.x + other.x, selfy + other.y, self.z + other.z)160        return pt3d((self.x+other.x),(self.y+other.y),(self.z+other.z))
156    def __sub__(self, other):161    def __sub__ (self,other):
157        return sqrt((self.x-other.x)**2+(self.y-other.y)**2+(self.z-other.z)**2)162        return math.sqrt(((other.x-self.x)**2)+((other.y-self.y)**2)+((other.z-s
 >elf.z)**2))
158    def __eq__(self, other):163    def __eq__(self,other):
159        return self.x==other.x & self.y==other.y & self.z==other.z164        if (self.x == other.x) and (self.y == other.y) and (self.z == other.z):
165            return True
166        else:
167            return False
160    def __str__(self):168    def __str__(self):
t161        return '<{}, {}, {}>'.format(self.x,self.y,self.z)t169       return "<{},{},{}>".format(self.x,self.y,self.z)
162p1 = pt3d(1,1,1)170if __name__=="__main__":
163p2 = pt3d(2,2,2)171    p2 = pt3d()
164print(p1 + p2)172    print(pt3d()+p2)
165print(p1-p2)173    print(pt3d()-p2)    
166print(p1==p2)
167print(p1+p1 == p2)
168print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 56

Student ID: 475, P-Value: 2.14e-02

Nearest Neighbor ID: 373

Student (left) and Nearest Neighbor (right).


n1import mathn
2class Circle:1class Circle():
3    def __init__(self,radius):2    def __init__(self, r):
4       self.radius=radius3        self.radius = r
5    def area(self):4    def area(self):
n6        area=math.pi*self.radius**2n5        return self.radius**2*3.14
7        return area
8    def perimeter(self):6    def perimeter(self):
n9        perimeter=2*math.pi*self.radiusn7        return 2*self.radius*3.14
10        return perimeter
11if __name__=='__main__':
12    x = int(input())
13    NewCircle = Circle(x)8NewCircle = Circle()
14    print('{:.5f}'.format(NewCircle.area()))9print(NewCircle.area())
15    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:10print(NewCircle.perimeter())
11class ItemToPurchase:
16    def __init__(self, item_name= 'none', item_price=0, item_quantity=0, item_de12    def __init__(self, item_name= 'none', item_price=0, item_quantity=0, item_de
>scription = 'none'):>scription = 'none'):
17        self.item_name = item_name13        self.item_name = item_name
18        self.item_price = item_price14        self.item_price = item_price
19        self.item_quantity = item_quantity15        self.item_quantity = item_quantity
20        self.item_description = item_description16        self.item_description = item_description
21    def print_item_cost(self):17    def print_item_cost(self):
22        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, 18        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, 
>self.item_price, (self.item_quantity >self.item_price, (self.item_quantity 
23* self.item_price))19* self.item_price))
24        cost = self.item_quantity * self.item_price20        cost = self.item_quantity * self.item_price
25        return string, cost21        return string, cost
26    def print_item_description(self):22    def print_item_description(self):
27        string = '{}: {}'.format(self.item_name, self.item_description)23        string = '{}: {}'.format(self.item_name, self.item_description)
28        print(string, end=' ')24        print(string, end=' ')
29        return string25        return string
30class ShoppingCart:26class ShoppingCart:
31    def __init__(self,customer_name= None ,current_date='January 1,2016',cart_it27    def __init__(self,customer_name= None ,current_date='January 1,2016',cart_it
>ems=[]):>ems=[]):
32        self.customer_name = customer_name28        self.customer_name = customer_name
33        self.current_date = current_date29        self.current_date = current_date
34        self.cart_items = cart_items30        self.cart_items = cart_items
35def add_item(self,):31def add_item(self,):
36    print('\nADD ITEM TO CART', end='\n')32    print('\nADD ITEM TO CART', end='\n')
37    item_name = str(input('Enter the item name:'));33    item_name = str(input('Enter the item name:'));
38    item_description = str(input('\nEnter the item description:'));34    item_description = str(input('\nEnter the item description:'));
39    item_price = int(input('\nEnter the item price:'));35    item_price = int(input('\nEnter the item price:'));
40    item_quantity = int(input('\nEnter the item quantity:\n'))36    item_quantity = int(input('\nEnter the item quantity:\n'))
41    self.cart_items.append(ItemToPurchase(item_name, item_price, item_quantity, 37    self.cart_items.append(ItemToPurchase(item_name, item_price, item_quantity, 
>item_description))>item_description))
42def remove_item(self):38def remove_item(self):
43    print()39    print()
44    print('REMOVE ITEM FROM CART', end='\n')40    print('REMOVE ITEM FROM CART', end='\n')
45    string = str(input('Enter name of item to remove:\n'))41    string = str(input('Enter name of item to remove:\n'))
46    i = 042    i = 0
47    for item in self.cart_items:43    for item in self.cart_items:
48        if(item.item_name == string):               44        if(item.item_name == string):               
49            del self.cart_items[i]45            del self.cart_items[i]
50            i += 146            i += 1
51            flag=True47            flag=True
52            break48            break
53        else:49        else:
54            flag=False50            flag=False
55    if(flag==False):51    if(flag==False):
56        print('Item not found in cart. Nothing removed.')52        print('Item not found in cart. Nothing removed.')
57def modify_item(self):53def modify_item(self):
58    print('\nCHANGE ITEM QUANTITY', end='\n')54    print('\nCHANGE ITEM QUANTITY', end='\n')
59    name = str(input('Enter the item name:'))       55    name = str(input('Enter the item name:'))       
60    for item in self.cart_items:56    for item in self.cart_items:
61        if(item.item_name == name):57        if(item.item_name == name):
62            quantity = int(input('Enter the new quantity:'))58            quantity = int(input('Enter the new quantity:'))
63            item.item_quantity = quantity59            item.item_quantity = quantity
64            flag=True60            flag=True
65            break61            break
66        else:62        else:
67            flag=False63            flag=False
68    if(flag==False):64    if(flag==False):
69        print('Item not found in cart. Nothing modified.')65        print('Item not found in cart. Nothing modified.')
70def get_num_items_in_cart(self):66def get_num_items_in_cart(self):
71    num_items = 067    num_items = 0
72    for item in self.cart_items:68    for item in self.cart_items:
73        num_items += item.item_quantity69        num_items += item.item_quantity
74    return num_items70    return num_items
75def get_cost_of_cart(self):71def get_cost_of_cart(self):
76    total_cost = 072    total_cost = 0
77    cost = 073    cost = 0
78    for item in self.cart_items:74    for item in self.cart_items:
79        cost = (item.item_quantity * item.item_price)75        cost = (item.item_quantity * item.item_price)
80        total_cost += cost76        total_cost += cost
81    return total_cost77    return total_cost
82def print_total():78def print_total():
83   total_cost = self.get_cost_of_cart()79   total_cost = self.get_cost_of_cart()
84   if (total_cost == 0):80   if (total_cost == 0):
85       print('SHOPPING CART IS EMPTY')81       print('SHOPPING CART IS EMPTY')
86   else:82   else:
87       output_cart()83       output_cart()
88def print_descriptions(self):84def print_descriptions(self):
89    print('OUTPUT ITEMS\' DESCRIPTIONS')85    print('OUTPUT ITEMS\' DESCRIPTIONS')
90    print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current_dat86    print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current_dat
>e),end='\n')>e),end='\n')
91    print('\nItem Descriptions', end='\n')87    print('\nItem Descriptions', end='\n')
92    for item in self.cart_items:88    for item in self.cart_items:
93        print('{}: {}'.format(item.item_name, item.item_description), end='\n')89        print('{}: {}'.format(item.item_name, item.item_description), end='\n')
94def output_cart(self):90def output_cart(self):
95    new=ShoppingCart()91    new=ShoppingCart()
96    print('OUTPUT SHOPPING CART', end='\n')92    print('OUTPUT SHOPPING CART', end='\n')
97    print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current_dat93    print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current_dat
>e),end='\n')      >e),end='\n')      
98    print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')94    print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')
99    self.total_cost = self.get_cost_of_cart()95    self.total_cost = self.get_cost_of_cart()
100    if (self.total_cost == 0):96    if (self.total_cost == 0):
101       print('SHOPPING CART IS EMPTY')97       print('SHOPPING CART IS EMPTY')
102    else:98    else:
103        pass99        pass
104    tc = 0100    tc = 0
105    for item in self.cart_items:101    for item in self.cart_items:
106        print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,102        print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,
107                                         item.item_price, (item.item_quantity * 103                                         item.item_price, (item.item_quantity * 
>item.item_price)), end='\n')>item.item_price)), end='\n')
108        tc += (item.item_quantity * item.item_price)104        tc += (item.item_quantity * item.item_price)
109    print('\nTotal: ${}'.format(tc), end='\n')105    print('\nTotal: ${}'.format(tc), end='\n')
110def print_menu(new_cart):106def print_menu(new_cart):
111    customer_Cart = newCart107    customer_Cart = newCart
112    string=''108    string=''
n113   menu = ('\nMENU\n')n109   menu = ('\nMENU\n'
114        'a - Add item to cart\n'110        'a - Add item to cart\n'
115        'r - Remove item from cart\n'111        'r - Remove item from cart\n'
116        'c - Change item quantity\n'112        'c - Change item quantity\n'
117        'i - Output items\' descriptions\n'113        'i - Output items\' descriptions\n'
118        'o - Output shopping cart\n'114        'o - Output shopping cart\n'
119        'q - Quit\n')115        'q - Quit\n')
120    command = ''116    command = ''
121    while(command != 'q'):117    while(command != 'q'):
122        string=''118        string=''
123        print('\nMENU\n'119        print('\nMENU\n'
124        'a - Add item to cart\n'120        'a - Add item to cart\n'
125        'r - Remove item from cart\n'121        'r - Remove item from cart\n'
126        'c - Change item quantity\n'122        'c - Change item quantity\n'
127        'i - Output items\' descriptions\n'123        'i - Output items\' descriptions\n'
128        'o - Output shopping cart\n'124        'o - Output shopping cart\n'
129        'q - Quit\n', end='\n')125        'q - Quit\n', end='\n')
130        command = input('Choose an option:')126        command = input('Choose an option:')
131        print()127        print()
132        while(command != 'a' and command != 'o' and command != 'i' and command !128        while(command != 'a' and command != 'o' and command != 'i' and command !
>= 'r' and command != 'c' and command != 'q'):>= 'r' and command != 'c' and command != 'q'):
133        command = input('Choose an option:\n')129        command = input('Choose an option:\n')
134    if(command == 'a'):130    if(command == 'a'):
135        customer_Cart.add_item()131        customer_Cart.add_item()
136    if(command == 'o'):132    if(command == 'o'):
137        customer_Cart.output_cart()133        customer_Cart.output_cart()
138    if(command == 'i'):134    if(command == 'i'):
139        customer_Cart.print_descriptions()135        customer_Cart.print_descriptions()
140    if(command == 'r'):136    if(command == 'r'):
141        customer_Cart.remove_item()137        customer_Cart.remove_item()
142    if(command == 'c'):138    if(command == 'c'):
143        customer_Cart.modify_item()139        customer_Cart.modify_item()
144if __name__ == "__main__":140if __name__ == "__main__":
145    customer_name = str(input('Enter customer\'s name:'))141    customer_name = str(input('Enter customer\'s name:'))
146    current_date = str(input('\nEnter today\'s date:'))142    current_date = str(input('\nEnter today\'s date:'))
147    print()143    print()
148    print()144    print()
149    print('Customer name:', customer_name, end='\n')145    print('Customer name:', customer_name, end='\n')
150    print('Today\'s date:', current_date, end='\n')146    print('Today\'s date:', current_date, end='\n')
151    newCart = ShoppingCart(customer_name, current_date)147    newCart = ShoppingCart(customer_name, current_date)
n152    print_menu(newCart)n148    print_menu(newCart)    
153import math
154class pt3d:149class pt3d:
n155    def __init__(self,x=0,y=0,z=0):n150    def __init__(self, x, y, z):
156       self.x=x151        self.x = x
157       self.y=y       152        self.y = y
158       self.z=z153        self.z = z
159    def __add__ (self,other):154    def __add__(self,other):
160        return pt3d((self.x+other.x),(self.y+other.y),(self.z+other.z))155        return pt3d(self.x + other.x, selfy + other.y, self.z + other.z)
161    def __sub__ (self,other):156    def __sub__(self, other):
162        return math.sqrt(((other.x-self.x)**2)+((other.y-self.y)**2)+((other.z-s157        return sqrt((self.x-other.x)**2+(self.y-other.y)**2+(self.z-other.z)**2)
>elf.z)**2)) 
163    def __eq__(self,other):158    def __eq__(self, other):
164        if (self.x == other.x) and (self.y == other.y) and (self.z == other.z):159        return self.x==other.x & self.y==other.y & self.z==other.z
165            return True
166        else:
167            return False
168    def __str__(self):160    def __str__(self):
t169       return "<{},{},{}>".format(self.x,self.y,self.z)t161        return '<{}, {}, {}>'.format(self.x,self.y,self.z)
170if __name__=="__main__":162p1 = pt3d(1,1,1)
171    p2 = pt3d()163p2 = pt3d(2,2,2)
172    print(pt3d()+p2)164print(p1 + p2)
173    print(pt3d()-p2)    165print(p1-p2)
166print(p1==p2)
167print(p1+p1 == p2)
168print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 57

Student ID: 379, P-Value: 2.41e-02

Nearest Neighbor ID: 183

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle:n2class Circle():
3    def __init__(self, radius):3    def __init__(self, radius):
n4        self.radius=radiusn4        self.radius = radius
5    def area(self):5    def area(self):
n6        return math.pi*(self.radius**2)n6        return math.pi * self.radius**2
7    def perimeter(self):7    def perimeter(self):
n8        return 2*math.pi*self.radiusn8        return 2 * math.pi * self.radius
9if __name__=='__main__':9if __name__=='__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des14    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des
>cription='none'):>cription='none'):
15        self.item_name = item_name15        self.item_name = item_name
16        self.item_price = item_price16        self.item_price = item_price
17        self.item_quantity = item_quantity17        self.item_quantity = item_quantity
18        self.item_description = item_description18        self.item_description = item_description
19    def print_item_cost(self):19    def print_item_cost(self):
20        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, 20        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, 
>self.item_price,>self.item_price,
21                                            (self.item_quantity * self.item_pric21                                            (self.item_quantity * self.item_pric
>e))>e))
22        cost = self.item_quantity * self.item_price22        cost = self.item_quantity * self.item_price
23        return string, cost23        return string, cost
24    def print_item_description(self):24    def print_item_description(self):
25        string = '{}: {}'.format(self.item_name, self.item_description)25        string = '{}: {}'.format(self.item_name, self.item_description)
26        print(string, end='\n')26        print(string, end='\n')
27        return string27        return string
28class ShoppingCart:28class ShoppingCart:
29    def __init__(self, customer_name='none', current_date='January 1, 2016', car29    def __init__(self, customer_name='none', current_date='January 1, 2016', car
>t_items=[]):>t_items=[]):
30        self.customer_name = customer_name30        self.customer_name = customer_name
31        self.current_date = current_date31        self.current_date = current_date
32        self.cart_items = cart_items32        self.cart_items = cart_items
33    def add_item(self, string):33    def add_item(self, string):
n34        print('ADD ITEM TO CART', end='\n')n34        print('\nADD ITEM TO CART', end='\n')
35        item_name = str(input('Enter the item name:'))35        item_name = str(input('Enter the item name: '))
36        item_description = str(input('\nEnter the item description:'))36        item_description = str(input('\nEnter the item description: '))
37        item_price = int(input('\nEnter the item price:'))37        item_price = int(input('\nEnter the item price: '))
38        item_quantity = int(input('\nEnter the item quantity:\n'))38        item_quantity = int(input('\nEnter the item quantity: '))
39        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti39        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti
>ty, item_description))>ty, item_description))
40    def remove_item(self):40    def remove_item(self):
41        print('\nREMOVE ITEM FROM CART', end='\n')41        print('\nREMOVE ITEM FROM CART', end='\n')
n42        string = str(input('Enter name of item to remove:\n'))n42        string = str(input('Enter name of item to remove: '))
43        i = 0
43        for item in self.cart_items:44        for item in self.cart_items:
44            if (item.item_name == string):45            if (item.item_name == string):
n45                self.cart_items.remove(item)n46                del self.cart_items[i]
47                i += 1
46                flag = True48                flag = True
47                break49                break
48            else:50            else:
49                flag = False51                flag = False
50        if (flag == False):52        if (flag == False):
n51            print('Item not found in cart. Nothing removed.')n53            print('Item not found in cart. Nothing removed')
52    def modify_item(self):54    def modify_item(self):
53        print('\nCHANGE ITEM QUANTITY', end='\n')55        print('\nCHANGE ITEM QUANTITY', end='\n')
54        name = str(input('Enter the item name: '))56        name = str(input('Enter the item name: '))
55        for item in self.cart_items:57        for item in self.cart_items:
56            if (item.item_name == name):58            if (item.item_name == name):
57                quantity = int(input('Enter the new quantity: '))59                quantity = int(input('Enter the new quantity: '))
58                item.item_quantity = quantity60                item.item_quantity = quantity
59                flag = True61                flag = True
60                break62                break
61            else:63            else:
62                flag = False64                flag = False
63        if (flag == False):65        if (flag == False):
n64            print('Item not found in cart. Nothing modified.')n66            print('Item not found in cart. Nothing modified')
65    def get_num_items_in_cart(self):67    def get_num_items_in_cart(self):
66        num_items = 068        num_items = 0
67        for item in self.cart_items:69        for item in self.cart_items:
68            num_items = num_items + item.item_quantity70            num_items = num_items + item.item_quantity
69        return num_items71        return num_items
70    def get_cost_of_cart(self):72    def get_cost_of_cart(self):
71        total_cost = 073        total_cost = 0
72        cost = 074        cost = 0
73        for item in self.cart_items:75        for item in self.cart_items:
74            cost = (item.item_quantity * item.item_price)76            cost = (item.item_quantity * item.item_price)
75            total_cost += cost77            total_cost += cost
76        return total_cost78        return total_cost
77    def print_total(self):79    def print_total(self):
n78        total_cost = get_cost_of_cart()n80        total_cost = self.get_cost_of_cart()
79        if (total_cost == 0):81        if (total_cost == 0):
80            print('SHOPPING CART IS EMPTY')82            print('SHOPPING CART IS EMPTY')
81        else:83        else:
n82            output_cart()n84            self.output_cart()
83    def print_descriptions(self):85    def print_descriptions(self):
84        print('\nOUTPUT ITEMS\' DESCRIPTIONS')86        print('\nOUTPUT ITEMS\' DESCRIPTIONS')
85        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current87        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date), end='\n')>_date), end='\n')
86        print('\nItem Descriptions', end='\n')88        print('\nItem Descriptions', end='\n')
87        for item in self.cart_items:89        for item in self.cart_items:
88            print('{}: {}'.format(item.item_name, item.item_description), end='\90            print('{}: {}'.format(item.item_name, item.item_description), end='\
>n')>n')
89    def output_cart(self):91    def output_cart(self):
90        new = ShoppingCart()92        new = ShoppingCart()
n91        print('OUTPUT SHOPPING CART', end='\n')n93        print('\nOUTPUT SHOPPING CART', end='\n')
92        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current94        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date), end='\n')>_date), end='\n')
93        print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')95        print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')
n94        if new.get_num_items_in_cart() == 0:n
95            print('SHOPPING CART IS EMPTY')
96        tc = 096        tc = 0
97        for item in self.cart_items:97        for item in self.cart_items:
98            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,98            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,
99                                             item.item_price, (item.item_quantit99                                             item.item_price, (item.item_quantit
>y * item.item_price)), end='\n')>y * item.item_price)), end='\n')
100            tc += (item.item_quantity * item.item_price)100            tc += (item.item_quantity * item.item_price)
101        print('\nTotal: ${}'.format(tc), end='\n')101        print('\nTotal: ${}'.format(tc), end='\n')
102def print_menu(ShoppingCart):102def print_menu(ShoppingCart):
103    customer_Cart = newCart103    customer_Cart = newCart
104    string = ''104    string = ''
105    menu = ('\nMENU\n'105    menu = ('\nMENU\n'
106            'a - Add item to cart\n'106            'a - Add item to cart\n'
107            'r - Remove item from cart\n'107            'r - Remove item from cart\n'
108            'c - Change item quantity\n'108            'c - Change item quantity\n'
109            'i - Output items\' descriptions\n'109            'i - Output items\' descriptions\n'
110            'o - Output shopping cart\n'110            'o - Output shopping cart\n'
111            'q - Quit\n')111            'q - Quit\n')
112    command = ''112    command = ''
113    while (command != 'q'):113    while (command != 'q'):
114        string = ''114        string = ''
115        print(menu, end='\n')115        print(menu, end='\n')
n116        command = input('Choose an option:\n')n116        command = input('Choose an option: ')
117        while (command != 'a' and command != 'o' and command != 'i' and command 117        while (command != 'a' and command != 'o' and command != 'i' and command 
>!= 'r'>!= 'r'
118               and command != 'c' and command != 'q'):118               and command != 'c' and command != 'q'):
n119            command = input('Choose an option:\n')n119            command = input('Choose an option: ')
120        if (command == 'a'):120        if (command == 'a'):
121            customer_Cart.add_item(string)121            customer_Cart.add_item(string)
122        if (command == 'o'):122        if (command == 'o'):
123            customer_Cart.output_cart()123            customer_Cart.output_cart()
124        if (command == 'i'):124        if (command == 'i'):
125            customer_Cart.print_descriptions()125            customer_Cart.print_descriptions()
126        if (command == 'r'):126        if (command == 'r'):
127            customer_Cart.remove_item()127            customer_Cart.remove_item()
128        if (command == 'c'):128        if (command == 'c'):
129            customer_Cart.modify_item()129            customer_Cart.modify_item()
n130if __name__=='__main__':n
131    customer_name = str(input('Enter customer\'s name:'))130customer_name = str(input('Enter customer\'s name: '))
132    current_date = str(input('\nEnter today\'s date:\n\n'))131current_date = str(input('\nEnter today\'s date: '))
133    print('Customer name:', customer_name, end='\n')132print('Customer name:', customer_name, end='\n')
134    print('Today\'s date:', current_date)133print('Today\'s date:', current_date, end='\n')
135    newCart = ShoppingCart(customer_name, current_date)134newCart = ShoppingCart(customer_name, current_date)
136    print_menu(newCart)from pt3d import pt3d135print_menu(newCart)from math import sqrt
137class pt3d:136class pt3d:
138    def __init__(self, x=0, y=0, z=0):137    def __init__(self, x=0, y=0, z=0):
139        self.x = x138        self.x = x
140        self.y = y139        self.y = y
141        self.z = z140        self.z = z
n142        p1 = pt3d(1, 1, 1)n
143        p2 = pt3d(2, 2, 2)
144    def __add__(self, other):141    def __add__(self, other):
t145        print(p1+p2).format'<{},{},{}>'t142        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
146    def __str__(self, other):143    def __sub__(self, other):
147        return "point : ({:d}, {:d}, {:d})".format(self.x,self.y,self.z)
148    def distance(self, other):
149        d = sqrt( (self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - othe144        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>r.z)**2 )>her.z)**2)
150        return distance145    def __eq__(self, other):
151    print(p2.distance(p1))146        return self.x == other.x & self.y == other.y & self.z == other.z
147    def __str__(self):
148        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
149if __name__ == '__main__':
150    p1 = pt3d(1, 1, 1)
151    p2 = pt3d(2, 2, 2)
152    print(p1+p2)
153    print(p1-p2)
154    print(p1==p2)
155    print(p1+p1==p2)
156    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 58

Student ID: 127, P-Value: 3.05e-02

Nearest Neighbor ID: 74

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
3    def __init__(self,radius):3    def __init__(self,radius):
4        self.radius=radius4        self.radius=radius
5    def area(self):5    def area(self):
n6        area=math.pi*(self.radius**2)n6        return math.pi*(self.radius**2)
7        return area
8    def perimeter(self):7    def perimeter(self):
n9        perimeter=math.pi*(self.radius*2)n8        return 2*self.radius*math.pi
10        return perimeter
11if __name__=='__main__':9if __name__=='__main__':
12    x = int(input())10    x = int(input())
13    NewCircle = Circle(x)11    NewCircle = Circle(x)
14    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
15    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
16   def __init__(self, name='none', price=0, quantity=0, description='none'):14   def __init__(self, name='none', price=0, quantity=0, description='none'):
17       self.item_name=name15       self.item_name=name
18       self.item_description=description16       self.item_description=description
19       self.item_price=price17       self.item_price=price
20       self.item_quantity=quantity18       self.item_quantity=quantity
21   def print_item_cost(self):19   def print_item_cost(self):
22       total = self.item_price * self.item_quantity20       total = self.item_price * self.item_quantity
23       print('%s %d @ $%d = $%d' % (self.item_name, self.item_quantity, self.ite21       print('%s %d @ $%d = $%d' % (self.item_name, self.item_quantity, self.ite
>m_price, total))>m_price, total))
24   def print_item_description(self):  22   def print_item_description(self):  
25       print('%s: %s' % (self.item_name, self.item_description))23       print('%s: %s' % (self.item_name, self.item_description))
26class ShoppingCart:24class ShoppingCart:
27   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 25   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016', 
>cart_items = []):>cart_items = []):
28       self.customer_name = customer_name26       self.customer_name = customer_name
29       self.current_date = current_date27       self.current_date = current_date
30       self.cart_items = cart_items28       self.cart_items = cart_items
31   def add_item(self, itemToPurchase):29   def add_item(self, itemToPurchase):
32       self.cart_items.append(itemToPurchase)30       self.cart_items.append(itemToPurchase)
33   def remove_item(self, itemName):31   def remove_item(self, itemName):
34       tremove_item = False32       tremove_item = False
35       for item in self.cart_items:33       for item in self.cart_items:
36           if item.item_name == itemName:34           if item.item_name == itemName:
37               self.cart_items.remove(item)35               self.cart_items.remove(item)
38               tremove_item = True36               tremove_item = True
39               break37               break
40       if not tremove_item:38       if not tremove_item:
41           print('Item not found in cart. Nothing removed.')      39           print('Item not found in cart. Nothing removed.')      
42   def modify_item(self, itemToPurchase):40   def modify_item(self, itemToPurchase):
43       tmodify_item = False41       tmodify_item = False
44       for i in range(len(self.cart_items)):42       for i in range(len(self.cart_items)):
45           if self.cart_items[i].item_name == itemToPurchase.item_name:43           if self.cart_items[i].item_name == itemToPurchase.item_name:
46               tmodify_item = True44               tmodify_item = True
47               self.cart_items[i].item_quantity = itemToPurchase.item_quantity45               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
48               break46               break
49       if not tmodify_item:47       if not tmodify_item:
50           print('Item not found in cart. Nothing modified.')48           print('Item not found in cart. Nothing modified.')
51   def get_num_items_in_cart(self):49   def get_num_items_in_cart(self):
52       num_items = 050       num_items = 0
53       for item in self.cart_items:51       for item in self.cart_items:
54           num_items = num_items + item.item_quantity52           num_items = num_items + item.item_quantity
55       return num_items      53       return num_items      
56   def get_cost_of_cart(self):54   def get_cost_of_cart(self):
57       total_cost = 055       total_cost = 0
58       cost = 056       cost = 0
59       for item in self.cart_items:57       for item in self.cart_items:
60           cost = (item.item_quantity * item.item_price)58           cost = (item.item_quantity * item.item_price)
61           total_cost += cost59           total_cost += cost
62       return total_cost60       return total_cost
63   def print_total(self):61   def print_total(self):
64       print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current_62       print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current_
>date))>date))
65       print('Number of Items: %d\n' %self.get_num_items_in_cart())63       print('Number of Items: %d\n' %self.get_num_items_in_cart())
66       total_cost = self.get_cost_of_cart()64       total_cost = self.get_cost_of_cart()
67       if (total_cost == 0): 65       if (total_cost == 0): 
68           print('SHOPPING CART IS EMPTY')66           print('SHOPPING CART IS EMPTY')
69       else:67       else:
70           for item in self.cart_items:68           for item in self.cart_items:
71               item.print_item_cost()69               item.print_item_cost()
72       print('\nTotal: $%d' %(total_cost))      70       print('\nTotal: $%d' %(total_cost))      
73   def print_descriptions(self):71   def print_descriptions(self):
74       if len(self.cart_items) == 0:72       if len(self.cart_items) == 0:
75           print('SHOPPING CART IS EMPTY')73           print('SHOPPING CART IS EMPTY')
76       else:74       else:
77           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr75           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
78           print('\nItem Descriptions')76           print('\nItem Descriptions')
79           for item in self.cart_items:77           for item in self.cart_items:
80               item.print_item_description()              78               item.print_item_description()              
81def print_menu(newCart):79def print_menu(newCart):
n82   customer_Cart = newCartn80    customer_Cart = newCart
83   menu = ('\nMENU\n'81    menu = ('\nMENU\n'
84       'a - Add item to cart\n'82    'a - Add item to cart\n'
85       'r - Remove item from cart\n'83    'r - Remove item from cart\n'
86       'c - Change item quantity\n'84    'c - Change item quantity\n'
87       "i - Output items' descriptions\n"85    'i - Output items\' descriptions\n'
88       'o - Output shopping cart\n'86    'o - Output shopping cart\n'
89       'q - Quit\n')87    'q - Quit\n')
90   command = ''88    command = ''
91   while(command != 'q'):89    while(command != 'q'):
92       print(menu)90       print(menu)
93       command = input('Choose an option:\n')91       command = input('Choose an option:\n')
94       while(command != 'a' and command != 'o' and command != 'i' and command !=92       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
95           command = input('Choose an option:\n')93           command = input('Choose an option:\n')
96       if(command == 'a'):94       if(command == 'a'):
97           print("\nADD ITEM TO CART")95           print("\nADD ITEM TO CART")
98           item_name = input('Enter the item name:\n')96           item_name = input('Enter the item name:\n')
99           item_description = input('Enter the item description:\n')97           item_description = input('Enter the item description:\n')
n100           item_price = int(input('Enter the item price:\n'))n98           item_price = float(input('Enter the item price:\n'))
101           item_quantity = int(input('Enter the item quantity:\n'))99           item_quantity = int(input('Enter the item quantity:\n'))
102           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,100           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
103           customer_Cart.add_item(itemtoPurchase)101           customer_Cart.add_item(itemtoPurchase)
104       elif(command == 'o'):102       elif(command == 'o'):
105           print('OUTPUT SHOPPING CART')103           print('OUTPUT SHOPPING CART')
106           customer_Cart.print_total()104           customer_Cart.print_total()
107       elif(command == 'i'):105       elif(command == 'i'):
108           print('\nOUTPUT ITEMS\' DESCRIPTIONS')106           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
109           customer_Cart.print_descriptions()107           customer_Cart.print_descriptions()
110       elif(command == 'r'):108       elif(command == 'r'):
111           print('REMOVE ITEM FROM CART')109           print('REMOVE ITEM FROM CART')
112           itemName = input('Enter name of item to remove:\n')110           itemName = input('Enter name of item to remove:\n')
113           customer_Cart.remove_item(itemName)111           customer_Cart.remove_item(itemName)
114       elif(command == 'c'):112       elif(command == 'c'):
115           print('\nCHANGE ITEM QUANTITY')113           print('\nCHANGE ITEM QUANTITY')
116           itemName = input('Enter the item name:\n')114           itemName = input('Enter the item name:\n')
n117           qty = int(input('Enter the new quantity:\n'))n115           quantity = int(input('Enter the new quantity:\n'))
118           itemToPurchase = ItemToPurchase(itemName,0,qty)116           itemToPurchase = ItemToPurchase(itemName,0,quantity)
119           customer_Cart.modify_item(itemToPurchase)      117           customer_Cart.modify_item(itemToPurchase)      
nn118def execute_menu(command, my_cart):
119    customer_Cart = my_cart
120if __name__ == "__main__":120if __name__ == "__main__":
121   customer_name = input("Enter customer's name:\n")121   customer_name = input("Enter customer's name:\n")
122   current_date = input("Enter today's date:\n")122   current_date = input("Enter today's date:\n")
123   print("\nCustomer name: %s" %customer_name)123   print("\nCustomer name: %s" %customer_name)
124   print("Today's date: %s" %current_date)124   print("Today's date: %s" %current_date)
125   newCart = ShoppingCart(customer_name, current_date)125   newCart = ShoppingCart(customer_name, current_date)
n126   print_menu(newCart)import mathn126   print_menu(newCart)from math import sqrt
127class pt3d:127class pt3d:
n128    def __init__(self,x=0,y=0,z=0):n128    def __init__(self, x=0, y=0, z=0):
129        self.x=x129        self.x = x
130        self.y=y130        self.y = y
131        self.z=z131        self.z = z
132    def __add__(self,other):132    def __add__(self, other):
133        x=self.x+other.x133        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
134        y=self.y+other.y
135        z=self.z+other.z
136        return pt3d(x,y,z)
137    def __sub__(self,other):134    def __sub__(self, other):
138        distance=math.sqrt((((other.x-self.x)**2)+((other.y-self.y))**2+((other.135        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>z-self.z))**2))>her.z)**2)
139        return distance
140    def __eq__(self,other):   136    def __eq__(self, other):
141        if self.x==other.x and self.y==other.y and self.z==other.z:137        return self.x == other.x and self.y == other.y and self.z == other.z
142            return True
143        else:
144            return False
145    def __str__(self):138    def __str__(self):
t146        return (f'<{self.x},{self.y},{self.z}>')t139        return '<{0},{1},{2}>'.format(self.x, self.y, self.z)
147if __name__=='__main__':140p1 = pt3d(1,1,1)
148    a=pt3d(1,1,1)141p2 = pt3d(2,2,2)
149    b=pt3d(2,2,2)142print(p1 + p2)
150    print(a+b)143print(p1 - p2)
151    print(a-b)144print(p1 == p2)
152    print(a==b)145print(p1+p1 == p2)
153    print(a+a==b)
154    print(a==b+pt3d(-1,-1,-1))146print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 59

Student ID: 215, P-Value: 3.87e-02

Nearest Neighbor ID: 116

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle :n2class Circle:
3    def __init__(self,radius):3    def __init__(self,radius):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
n6        return math.pi*self.radius*self.radiusn6        return math.pi * self.radius * self.radius
7    def perimeter(self):7    def perimeter(self):
n8        return 2*math.pi*self.radiusn8        return 2 * math.pi * self.radius
9if __name__ == '__main__':9if __name__=='__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14               def __init__(self, name='none', price=0, quantity=0, description=14               def __init__(self, name='none', price=0, quantity=0, description=
>'none'):>'none'):
15                              self.item_name=name15                              self.item_name=name
16                              self.item_description=description16                              self.item_description=description
17                              self.item_price=price17                              self.item_price=price
18                              self.item_quantity=quantity18                              self.item_quantity=quantity
19               def print_item_cost(self):19               def print_item_cost(self):
20                              total = self.item_price * self.item_quantity20                              total = self.item_price * self.item_quantity
21                              print('%s %d @ $%d = $%d' % (self.item_name, self.21                              print('%s %d @ $%d = $%d' % (self.item_name, self.
>item_quantity, self.item_price, total))>item_quantity, self.item_price, total))
22               def print_item_description(self):22               def print_item_description(self):
23                              print('%s: %s' % (self.item_name, self.item_descri23                              print('%s: %s' % (self.item_name, self.item_descri
>ption))>ption))
24class ShoppingCart:24class ShoppingCart:
25               def __init__(self, customer_name = 'none', current_date = 'Januar25               def __init__(self, customer_name = 'none', current_date = 'Januar
>y 1, 2016', cart_items = []):>y 1, 2016', cart_items = []):
26                              self.customer_name = customer_name26                              self.customer_name = customer_name
27                              self.current_date = current_date27                              self.current_date = current_date
28                              self.cart_items = cart_items        28                              self.cart_items = cart_items        
29               def add_item(self, itemToPurchase):29               def add_item(self, itemToPurchase):
n30                              self.cart_items.append(itemToPurchase)n30                              self.cart_items.append(itemToPurchase)            
 >   
31               def get_cost_of_cart(self):
32                              total_cost = 0
33                              cost = 0
34                              for item in self.cart_items:
35                                             cost = (item.item_quantity * item.i
 >tem_price)
36                                             total_cost += cost
37                              return total_cost
38               def print_total():
39                              total_cost = self.get_cost_of_cart()
40                              if (total_cost == 0):
41                                             print('SHOPPING CART IS EMPTY')
42                              else:
43                                             self.output_cart()                 
 >                         
44               def print_descriptions(self):
45                              if len(self.cart_items) == 0:
46                                             print('SHOPPING CART IS EMPTY')
47                              else:
48                                             print('\nOUTPUT ITEMS\' DESCRIPTION
 >S')             
49                                             print('{}\'s Shopping Cart - {}'.fo
 >rmat(self.customer_name, self.current_date))
50                                             print('\nItem Descriptions')
51                                             for item in self.cart_items:
52                                                            item.print_item_desc
 >ription()
53               def output_cart(self):
54                              print('\nOUTPUT SHOPPING CART')
55                              print('{}\'s Shopping Cart - {}'.format(self.custo
 >mer_name, self.current_date))
56                              print('Number of Items:'+ str(self.get_num_items_i
 >n_cart())+'\n')
57                              if len(self.cart_items) == 0:
58                                             print('SHOPPING CART IS EMPTY')
59                              else:      
60                                             tc = 0
61                                             for item in self.cart_items:
62                                                            print('{} {} @ ${} =
 > ${}'.format(item.item_name, item.item_quantity, item.item_price, (item.item_qua
 >ntity * item.item_price)))
63                                                            tc += (item.item_qua
 >ntity * item.item_price)
64                                             print('\nTotal: ${}'.format(tc))
31               def remove_item(self, itemName):65               def remove_item(self, itemName):
32                              tremove_item = False66                              tremove_item = False
33                              for item in self.cart_items:67                              for item in self.cart_items:
34                                             if item.item_name == itemName:68                                             if item.item_name == itemName:
35                                                            self.cart_items.remo69                                                            self.cart_items.remo
>ve(item)>ve(item)
36                                                            tremove_item = True70                                                            tremove_item = True
37                                                            break71                                                            break
38                              if not tremove_item:                              72                              if not tremove_item:                              
>      >      
39                                             print('Item not found in the cart. 73                                             print('Item not found in the cart. 
>Nothing removed')>Nothing removed')
40               def modify_item(self, itemToPurchase):  74               def modify_item(self, itemToPurchase):  
41                              tmodify_item = False75                              tmodify_item = False
42                              for i in range(len(self.cart_items)):76                              for i in range(len(self.cart_items)):
43                                             if self.cart_items[i].item_name == 77                                             if self.cart_items[i].item_name == 
>itemToPurchase.item_name:>itemToPurchase.item_name:
44                                                            tmodify_item = True78                                                            tmodify_item = True
45                                                            if(itemToPurchase.it79                                                            if(itemToPurchase.it
>em_price == 0 and itemToPurchase.item_quantity == 0 and itemToPurchase.item_desc>em_price == 0 and itemToPurchase.item_quantity == 0 and itemToPurchase.item_desc
>ription == 'none'):>ription == 'none'):
46                                                                           break80                                                                           break
47                                                            else:81                                                            else:
48                                                                           if(it82                                                                           if(it
>emToPurchase.item_price != 0):>emToPurchase.item_price != 0):
49                                                                                83                                                                                
>          self.cart_items[i].item_price = itemToPurchase.item_price>          self.cart_items[i].item_price = itemToPurchase.item_price
50                                                                           if(it84                                                                           if(it
>emToPurchase.item_quantity != 0):>emToPurchase.item_quantity != 0):
51                                                                                85                                                                                
>          self.cart_items[i].item_quantity = itemToPurchase.item_quantity>          self.cart_items[i].item_quantity = itemToPurchase.item_quantity
52                                                                           if(it86                                                                           if(it
>emToPurchase.item_description != 'none'):>emToPurchase.item_description != 'none'):
53                                                                                87                                                                                
>          self.cart_items[i].item_description = itemToPurchase.item_description>          self.cart_items[i].item_description = itemToPurchase.item_description
54                                                                           break88                                                                           break
55                              if not tmodify_item:                      89                              if not tmodify_item:                      
56                                             print('Item not found in the cart. 90                                             print('Item not found in the cart. 
>Nothing modified')          >Nothing modified')          
57               def get_num_items_in_cart(self):91               def get_num_items_in_cart(self):
58                              num_items = 092                              num_items = 0
59                              for item in self.cart_items:93                              for item in self.cart_items:
60                                             num_items = num_items + item.item_q94                                             num_items = num_items + item.item_q
>uantity>uantity
61                              return num_items95                              return num_items
n62               def get_cost_of_cart(self):n
63                              total_cost = 0
64                              cost = 0
65                              for item in self.cart_items:
66                                             cost = (item.item_quantity * item.i
>tem_price) 
67                                             total_cost += cost
68                              return total_cost
69               def print_total(self):
70                              total_cost = self.get_cost_of_cart()
71                              if (total_cost == 0):
72                                             print('SHOPPING CART IS EMPTY')
73                              else:
74                                             print('{}\'s Shopping Cart - {}'.fo
>rmat(self.customer_name, self.current_date)) 
75                                             print('Number of Items: %d\n' %self
>.get_num_items_in_cart()) 
76                                             for item in self.cart_items:
77                                                            item.print_item_cost
>() 
78                                             print('\nTotal: $%d' %(total_cost))
79               def print_descriptions(self):
80                              if len(self.cart_items) == 0:
81                                             print('SHOPPING CART IS EMPTY')
82                              else:      
83                                             print('{}\'s Shopping Cart - {}'.fo
>rmat(self.customer_name, self.current_date)) 
84                                             print('\nItem Descriptions')
85                                             for item in self.cart_items:
86                                                            item.print_item_desc
>ription()       
87def print_menu(newCart):96def print_menu(newCart):
88               customer_Cart = newCart97               customer_Cart = newCart
89               menu = ('\nMENU\n'98               menu = ('\nMENU\n'
90                              'a - Add item to cart\n'99                              'a - Add item to cart\n'
n91                              'r - Remove item from cart\n'n100                              'r - Remove item from the cart\n'
92                              'c - Change item quantity\n'101                              'c - Change item quantity\n'
n93                              "i - Output items' descriptions\n"n102                              "i - Output item's descriptions\n"
94                              'o - Output shopping cart\n'103                              'o - Output shopping cart\n'
95                              'q - Quit\n')104                              'q - Quit\n')
96               command = ''105               command = ''
97               while(command != 'q'):106               while(command != 'q'):
nn107                              string=''
98                              print(menu)108                              print(menu)
n99                              command = input('Choose an option:\n')n109                              command = raw_input('Choose an option: ')
100                              while(command != 'a' and command != 'o' and comman110                              while(command != 'a' and command != 'o' and comman
>d != 'i' and command != 'q' and command != 'r' and command != 'c'):>d != 'i' and command != 'q' and command != 'r' and command != 'c'):
n101                                             command = input('Choose an option:\n111                                             command = raw_input('Choose an opti
>n')>on: ')
102                              if(command == 'a'):112                              if(command == 'a'):
103                                             print("\nADD ITEM TO CART")113                                             print("\nADD ITEM TO CART")
n104                                             item_name = input('Enter the item nn114                                             item_name = raw_input('Enter the it
>ame:\n')>em name: ')
105                                             item_description = input('Enter the115                                             item_description = raw_input('Enter
> item description:\n')> the item description: ')
106                                             item_price = int(input('Enter the i116                                             item_price = float(raw_input('Enter
>tem price:\n'))> the item price: '))
107                                             item_quantity = int(input('Enter th117                                             item_quantity = int(raw_input('Ente
>e item quantity:\n'))>r the item quantity: '))
108                                             itemtoPurchase = ItemToPurchase(ite118                                             itemtoPurchase = ItemToPurchase(ite
>m_name, item_price, item_quantity, item_description)>m_name, item_price, item_quantity, item_description)
109                                             customer_Cart.add_item(itemtoPurcha119                                             customer_Cart.add_item(itemtoPurcha
>se)>se)
n110                              elif(command == 'o'):n120                              if(command == 'o'):
111                                  print('\nOUTPUT SHOPPING CART')
112                                  customer_Cart.print_total()         121                                             customer_Cart.output_cart()
113                              elif(command == 'i'):122                              if(command == 'i'):
114                                  print('\nOUTPUT ITEMS\' DESCRIPTIONS')
115                                  customer_Cart.print_descriptions()123                                             customer_Cart.print_descriptions()
116                              elif(command == 'r'):124                              if(command == 'r'):
117                                             print('REMOVE ITEM FROM CART')125                                             print('REMOVE ITEM FROM CART')
n118                                             itemName = input('Enter the name ofn126                                             itemName = raw_input('Enter the nam
> the item to remove :\n')>e of the item to remove : ')
119                                             customer_Cart.remove_item(itemName)127                                             customer_Cart.remove_item(itemName)
n120                              elif(command == 'c'):n128                              if(command == 'c'):
121                                             print('\nCHANGE ITEM QUANTITY')129                                             print('\nCHANGE ITEM QUANTITY')
n122                                             itemName = input('Enter the name ofn130                                             itemName = raw_input('Enter the nam
> the item :\n')>e of the item : ')
123                                             qty = int(input('Enter the new quan131                                             qty = int(raw_input('Enter the new 
>tity :\n'))>quantity : '))
124                                             itemToPurchase = ItemToPurchase(ite132                                             itemToPurchase = ItemToPurchase(ite
>mName,0,qty)>mName,0,qty)
n125                                             customer_Cart.modify_item(itemToPurn133                                             customer_Cart.modify_item(itemToPur
>chase)>chase)     
126if __name__ == "__main__":134if __name__ == "__main__":
n127               customer_name = input("Enter customer's name:\n")n135               customer_name = raw_input("Enter customer's name:")
128               current_date = input("Enter today's date:\n")136               current_date = raw_input("Enter today's date:")
129               print("\nCustomer name: %s" %customer_name)137               print("\nCustomer name:"customer_name)
130               print("Today's date: %s" %current_date)138               print("Today's date:"current_date)
131               newCart = ShoppingCart(customer_name, current_date)139               newCart = ShoppingCart(customer_name, current_date)
n132               print_menu(newCart)  import mathn140               print_menu(newCart)import math
133class pt3d:141class pt3d:
n134    def __init__(self,x=0,y=0,z=0):n142    def __init__(self,x,y,z):
135        self.x= x143        self.x = x
136        self.y= y144        self.y = y
137        self.z= z145        self.z = z
138    def __add__(self, other):146    def __add__(self, other):
139        x = self.x + other.x147        x = self.x + other.x
140        y = self.y + other.y148        y = self.y + other.y
141        z = self.z + other.z149        z = self.z + other.z
n142        return pt3d(x, y,z)n150        return pt3d(x,y,z)
143    def __sub__(self, other):151    def __sub__(self, other):
144        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 152        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>2)+math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
145    def __eq__(self, other):153    def __eq__(self, other):
146        return other.x==self.x and other.y==self.y and other.z==self.z154        return other.x==self.x and other.y==self.y and other.z==self.z
147    def __str__(self):155    def __str__(self):
t148        return "<{0},{1},{2}>".format(self.x, self.y, self.z)t156        return "<"+str(self.x)+","+str(self.y)+","+str(self.z)+">"
149if __name__ == '__main__':
150    p1 = pt3d(1, 1, 1)
151    p2 = pt3d(2, 2, 2)
152    print(p1+p2)
153    print(p1-p2)
154    print(p1==p2)
155    print(p1+p1==p2)
156    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 60

Student ID: 116, P-Value: 3.87e-02

Nearest Neighbor ID: 215

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle:n2class Circle :
3    def __init__(self,radius):3    def __init__(self,radius):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
n6        return math.pi * self.radius * self.radiusn6        return math.pi*self.radius*self.radius
7    def perimeter(self):7    def perimeter(self):
n8        return 2 * math.pi * self.radiusn8        return 2*math.pi*self.radius
9if __name__=='__main__':9if __name__ == '__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14               def __init__(self, name='none', price=0, quantity=0, description=14               def __init__(self, name='none', price=0, quantity=0, description=
>'none'):>'none'):
15                              self.item_name=name15                              self.item_name=name
16                              self.item_description=description16                              self.item_description=description
17                              self.item_price=price17                              self.item_price=price
18                              self.item_quantity=quantity18                              self.item_quantity=quantity
19               def print_item_cost(self):19               def print_item_cost(self):
20                              total = self.item_price * self.item_quantity20                              total = self.item_price * self.item_quantity
21                              print('%s %d @ $%d = $%d' % (self.item_name, self.21                              print('%s %d @ $%d = $%d' % (self.item_name, self.
>item_quantity, self.item_price, total))>item_quantity, self.item_price, total))
22               def print_item_description(self):22               def print_item_description(self):
23                              print('%s: %s' % (self.item_name, self.item_descri23                              print('%s: %s' % (self.item_name, self.item_descri
>ption))>ption))
24class ShoppingCart:24class ShoppingCart:
25               def __init__(self, customer_name = 'none', current_date = 'Januar25               def __init__(self, customer_name = 'none', current_date = 'Januar
>y 1, 2016', cart_items = []):>y 1, 2016', cart_items = []):
26                              self.customer_name = customer_name26                              self.customer_name = customer_name
27                              self.current_date = current_date27                              self.current_date = current_date
28                              self.cart_items = cart_items        28                              self.cart_items = cart_items        
29               def add_item(self, itemToPurchase):29               def add_item(self, itemToPurchase):
n30                              self.cart_items.append(itemToPurchase)            n30                              self.cart_items.append(itemToPurchase)
>    
31               def get_cost_of_cart(self):
32                              total_cost = 0
33                              cost = 0
34                              for item in self.cart_items:
35                                             cost = (item.item_quantity * item.i
>tem_price) 
36                                             total_cost += cost
37                              return total_cost
38               def print_total():
39                              total_cost = self.get_cost_of_cart()
40                              if (total_cost == 0):
41                                             print('SHOPPING CART IS EMPTY')
42                              else:
43                                             self.output_cart()                 
>                          
44               def print_descriptions(self):
45                              if len(self.cart_items) == 0:
46                                             print('SHOPPING CART IS EMPTY')
47                              else:
48                                             print('\nOUTPUT ITEMS\' DESCRIPTION
>S')              
49                                             print('{}\'s Shopping Cart - {}'.fo
>rmat(self.customer_name, self.current_date)) 
50                                             print('\nItem Descriptions')
51                                             for item in self.cart_items:
52                                                            item.print_item_desc
>ription() 
53               def output_cart(self):
54                              print('\nOUTPUT SHOPPING CART')
55                              print('{}\'s Shopping Cart - {}'.format(self.custo
>mer_name, self.current_date)) 
56                              print('Number of Items:'+ str(self.get_num_items_i
>n_cart())+'\n') 
57                              if len(self.cart_items) == 0:
58                                             print('SHOPPING CART IS EMPTY')
59                              else:      
60                                             tc = 0
61                                             for item in self.cart_items:
62                                                            print('{} {} @ ${} =
> ${}'.format(item.item_name, item.item_quantity, item.item_price, (item.item_qua 
>ntity * item.item_price))) 
63                                                            tc += (item.item_qua
>ntity * item.item_price) 
64                                             print('\nTotal: ${}'.format(tc))
65               def remove_item(self, itemName):31               def remove_item(self, itemName):
66                              tremove_item = False32                              tremove_item = False
67                              for item in self.cart_items:33                              for item in self.cart_items:
68                                             if item.item_name == itemName:34                                             if item.item_name == itemName:
69                                                            self.cart_items.remo35                                                            self.cart_items.remo
>ve(item)>ve(item)
70                                                            tremove_item = True36                                                            tremove_item = True
71                                                            break37                                                            break
72                              if not tremove_item:                              38                              if not tremove_item:                              
>      >      
73                                             print('Item not found in the cart. 39                                             print('Item not found in the cart. 
>Nothing removed')>Nothing removed')
74               def modify_item(self, itemToPurchase):  40               def modify_item(self, itemToPurchase):  
75                              tmodify_item = False41                              tmodify_item = False
76                              for i in range(len(self.cart_items)):42                              for i in range(len(self.cart_items)):
77                                             if self.cart_items[i].item_name == 43                                             if self.cart_items[i].item_name == 
>itemToPurchase.item_name:>itemToPurchase.item_name:
78                                                            tmodify_item = True44                                                            tmodify_item = True
79                                                            if(itemToPurchase.it45                                                            if(itemToPurchase.it
>em_price == 0 and itemToPurchase.item_quantity == 0 and itemToPurchase.item_desc>em_price == 0 and itemToPurchase.item_quantity == 0 and itemToPurchase.item_desc
>ription == 'none'):>ription == 'none'):
80                                                                           break46                                                                           break
81                                                            else:47                                                            else:
82                                                                           if(it48                                                                           if(it
>emToPurchase.item_price != 0):>emToPurchase.item_price != 0):
83                                                                                49                                                                                
>          self.cart_items[i].item_price = itemToPurchase.item_price>          self.cart_items[i].item_price = itemToPurchase.item_price
84                                                                           if(it50                                                                           if(it
>emToPurchase.item_quantity != 0):>emToPurchase.item_quantity != 0):
85                                                                                51                                                                                
>          self.cart_items[i].item_quantity = itemToPurchase.item_quantity>          self.cart_items[i].item_quantity = itemToPurchase.item_quantity
86                                                                           if(it52                                                                           if(it
>emToPurchase.item_description != 'none'):>emToPurchase.item_description != 'none'):
87                                                                                53                                                                                
>          self.cart_items[i].item_description = itemToPurchase.item_description>          self.cart_items[i].item_description = itemToPurchase.item_description
88                                                                           break54                                                                           break
89                              if not tmodify_item:                      55                              if not tmodify_item:                      
90                                             print('Item not found in the cart. 56                                             print('Item not found in the cart. 
>Nothing modified')          >Nothing modified')          
91               def get_num_items_in_cart(self):57               def get_num_items_in_cart(self):
92                              num_items = 058                              num_items = 0
93                              for item in self.cart_items:59                              for item in self.cart_items:
94                                             num_items = num_items + item.item_q60                                             num_items = num_items + item.item_q
>uantity>uantity
95                              return num_items61                              return num_items
nn62               def get_cost_of_cart(self):
63                              total_cost = 0
64                              cost = 0
65                              for item in self.cart_items:
66                                             cost = (item.item_quantity * item.i
 >tem_price)
67                                             total_cost += cost
68                              return total_cost
69               def print_total(self):
70                              total_cost = self.get_cost_of_cart()
71                              if (total_cost == 0):
72                                             print('SHOPPING CART IS EMPTY')
73                              else:
74                                             print('{}\'s Shopping Cart - {}'.fo
 >rmat(self.customer_name, self.current_date))
75                                             print('Number of Items: %d\n' %self
 >.get_num_items_in_cart())
76                                             for item in self.cart_items:
77                                                            item.print_item_cost
 >()
78                                             print('\nTotal: $%d' %(total_cost))
79               def print_descriptions(self):
80                              if len(self.cart_items) == 0:
81                                             print('SHOPPING CART IS EMPTY')
82                              else:      
83                                             print('{}\'s Shopping Cart - {}'.fo
 >rmat(self.customer_name, self.current_date))
84                                             print('\nItem Descriptions')
85                                             for item in self.cart_items:
86                                                            item.print_item_desc
 >ription()      
96def print_menu(newCart):87def print_menu(newCart):
97               customer_Cart = newCart88               customer_Cart = newCart
98               menu = ('\nMENU\n'89               menu = ('\nMENU\n'
99                              'a - Add item to cart\n'90                              'a - Add item to cart\n'
n100                              'r - Remove item from the cart\n'n91                              'r - Remove item from cart\n'
101                              'c - Change item quantity\n'92                              'c - Change item quantity\n'
n102                              "i - Output item's descriptions\n"n93                              "i - Output items' descriptions\n"
103                              'o - Output shopping cart\n'94                              'o - Output shopping cart\n'
104                              'q - Quit\n')95                              'q - Quit\n')
105               command = ''96               command = ''
106               while(command != 'q'):97               while(command != 'q'):
n107                              string=''n
108                              print(menu)98                              print(menu)
n109                              command = raw_input('Choose an option: ')n99                              command = input('Choose an option:\n')
110                              while(command != 'a' and command != 'o' and comman100                              while(command != 'a' and command != 'o' and comman
>d != 'i' and command != 'q' and command != 'r' and command != 'c'):>d != 'i' and command != 'q' and command != 'r' and command != 'c'):
n111                                             command = raw_input('Choose an optin101                                             command = input('Choose an option:\
>on: ')>n')
112                              if(command == 'a'):102                              if(command == 'a'):
113                                             print("\nADD ITEM TO CART")103                                             print("\nADD ITEM TO CART")
n114                                             item_name = raw_input('Enter the itn104                                             item_name = input('Enter the item n
>em name: ')>ame:\n')
115                                             item_description = raw_input('Enter105                                             item_description = input('Enter the
> the item description: ')> item description:\n')
116                                             item_price = float(raw_input('Enter106                                             item_price = int(input('Enter the i
> the item price: '))>tem price:\n'))
117                                             item_quantity = int(raw_input('Ente107                                             item_quantity = int(input('Enter th
>r the item quantity: '))>e item quantity:\n'))
118                                             itemtoPurchase = ItemToPurchase(ite108                                             itemtoPurchase = ItemToPurchase(ite
>m_name, item_price, item_quantity, item_description)>m_name, item_price, item_quantity, item_description)
119                                             customer_Cart.add_item(itemtoPurcha109                                             customer_Cart.add_item(itemtoPurcha
>se)>se)
n120                              if(command == 'o'):n110                              elif(command == 'o'):
111                                  print('\nOUTPUT SHOPPING CART')
121                                             customer_Cart.output_cart()112                                  customer_Cart.print_total()         
122                              if(command == 'i'):113                              elif(command == 'i'):
114                                  print('\nOUTPUT ITEMS\' DESCRIPTIONS')
123                                             customer_Cart.print_descriptions()115                                  customer_Cart.print_descriptions()
124                              if(command == 'r'):116                              elif(command == 'r'):
125                                             print('REMOVE ITEM FROM CART')117                                             print('REMOVE ITEM FROM CART')
n126                                             itemName = raw_input('Enter the namn118                                             itemName = input('Enter the name of
>e of the item to remove : ')> the item to remove :\n')
127                                             customer_Cart.remove_item(itemName)119                                             customer_Cart.remove_item(itemName)
n128                              if(command == 'c'):n120                              elif(command == 'c'):
129                                             print('\nCHANGE ITEM QUANTITY')121                                             print('\nCHANGE ITEM QUANTITY')
n130                                             itemName = raw_input('Enter the namn122                                             itemName = input('Enter the name of
>e of the item : ')> the item :\n')
131                                             qty = int(raw_input('Enter the new 123                                             qty = int(input('Enter the new quan
>quantity : '))>tity :\n'))
132                                             itemToPurchase = ItemToPurchase(ite124                                             itemToPurchase = ItemToPurchase(ite
>mName,0,qty)>mName,0,qty)
n133                                             customer_Cart.modify_item(itemToPurn125                                             customer_Cart.modify_item(itemToPur
>chase)     >chase)
134if __name__ == "__main__":126if __name__ == "__main__":
n135               customer_name = raw_input("Enter customer's name:")n127               customer_name = input("Enter customer's name:\n")
136               current_date = raw_input("Enter today's date:")128               current_date = input("Enter today's date:\n")
137               print("\nCustomer name:"customer_name)129               print("\nCustomer name: %s" %customer_name)
138               print("Today's date:"current_date)130               print("Today's date: %s" %current_date)
139               newCart = ShoppingCart(customer_name, current_date)131               newCart = ShoppingCart(customer_name, current_date)
n140               print_menu(newCart)import mathn132               print_menu(newCart)  import math
141class pt3d:133class pt3d:
n142    def __init__(self,x,y,z):n134    def __init__(self,x=0,y=0,z=0):
143        self.x = x135        self.x= x
144        self.y = y136        self.y= y
145        self.z = z137        self.z= z
146    def __add__(self, other):138    def __add__(self, other):
147        x = self.x + other.x139        x = self.x + other.x
148        y = self.y + other.y140        y = self.y + other.y
149        z = self.z + other.z141        z = self.z + other.z
n150        return pt3d(x,y,z)n142        return pt3d(x, y,z)
151    def __sub__(self, other):143    def __sub__(self, other):
152        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 144        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>2)+math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
153    def __eq__(self, other):145    def __eq__(self, other):
154        return other.x==self.x and other.y==self.y and other.z==self.z146        return other.x==self.x and other.y==self.y and other.z==self.z
155    def __str__(self):147    def __str__(self):
t156        return "<"+str(self.x)+","+str(self.y)+","+str(self.z)+">"t148        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
149if __name__ == '__main__':
150    p1 = pt3d(1, 1, 1)
151    p2 = pt3d(2, 2, 2)
152    print(p1+p2)
153    print(p1-p2)
154    print(p1==p2)
155    print(p1+p1==p2)
156    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 61

Student ID: 113, P-Value: 5.10e-02

Nearest Neighbor ID: 345

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self,radius):n3    def __init__(self, r):
4        self.radius = radius4        self.radius = r
5    def area(self):5    def area(self):
n6        return (math.pi*(self.radius*self.radius))n6        return (self.radius**2)*(math.pi)
7    def perimeter(self):7    def perimeter(self):
n8        return 2*math.pi*self.radiusn8        return 2*(math.pi)*(self.radius)        
9if __name__=='__main__':9if __name__=='__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
n14    def __init__(self, name='none', price=0, quantity=0, description='none'):n14    def __init__(self, item_name = "none"item_price = 0, item_quantity = 0, it
 >em_description = "none"):
15        self.item_name = name15        self.item_name = item_name
16        self.item_price = item_price
17        self.item_quantity = item_quantity
16        self.item_description = description18        self.item_description = item_description
17        self.item_price = price
18        self.item_quantity = quantity
19    def print_item_cost(self):19    def print_item_cost(self):
nn20        print(self.item_name + " " + str(self.item_quantity) + " @ $" + str(self
 >.item_price) + " = $" +
20        total = self.item_price * self.item_quantity21              str(self.item_price * self.item_quantity))
21        print('%s %d @ $%d = $%d' % (self.item_name, self.item_quantity, self.it
>em_price, total)) 
22    def print_item_description(self):22    def print_item_description(self):
n23        print('%s: %s' % (self.item_nameself.item_description))n23        print(self.item_name + ": " + str(self.item_description))
24class ShoppingCart:24class ShoppingCart:
n25    def __init__(self, customer_name='none', current_date='January 1, 2016', carn25    def __init__(self, customer_name='none', current_date='January 1, 2016'):
>t_items=[]): 
26        self.customer_name = customer_name26        self.customer_name = customer_name
27        self.current_date = current_date27        self.current_date = current_date
n28        self.cart_items = cart_itemsn28        self.cart_items = []
29    def add_item(self, itemToPurchase):29    def add_item(self, ItemToPurchase):
30        self.cart_items.append(itemToPurchase)30        self.cart_items.append(ItemToPurchase)
31    def remove_item(self, itemName):31    def remove_item(self, itemName):
n32        tremove_item = Falsen32        RemoveIt = False
33        for item in self.cart_items:33        for item in self.cart_items:
34            if item.item_name == itemName:34            if item.item_name == itemName:
35                self.cart_items.remove(item)35                self.cart_items.remove(item)
n36                tremove_item = Truen36                RemoveIt = True
37                break37                break
n38        if not tremove_item:n38        if not RemoveIt:
39            print('Item not found in cart. Nothing removed.')39            print('Item not found in cart. Nothing removed.')
40    def modify_item(self, itemToPurchase):40    def modify_item(self, itemToPurchase):
n41        tmodify_item = Falsen41        ModifyIt = False
42        for i in range(len(self.cart_items)):42        for i in range(len(self.cart_items)):
43            if self.cart_items[i].item_name == itemToPurchase.item_name:43            if self.cart_items[i].item_name == itemToPurchase.item_name:
n44                tmodify_item = Truen44                ModifyIt = True
45                if (
46                        itemToPurchase.item_price == 0 and itemToPurchase.item_q
 >uantity == 0 and itemToPurchase.item_description == 'none'):
47                    break
48                else:
49                    if (itemToPurchase.item_price != 0):
50                        self.cart_items[i].item_price = itemToPurchase.item_pric
 >e
51                    if (itemToPurchase.item_quantity != 0):
45                self.cart_items[i].item_quantity = itemToPurchase.item_quantity52                        self.cart_items[i].item_quantity = itemToPurchase.item_q
 >uantity
53                    if (itemToPurchase.item_description != 'none'):
54                        self.cart_items[i].item_description = itemToPurchase.ite
 >m_description
46                break55                    break
47        if not tmodify_item:56        if not ModifyIt:
48            print('Item not found in cart. Nothing modified.')57            print('Item not found in cart. Nothing modified.')
49    def get_num_items_in_cart(self):58    def get_num_items_in_cart(self):
50        num_items = 059        num_items = 0
51        for item in self.cart_items:60        for item in self.cart_items:
52            num_items = num_items + item.item_quantity61            num_items = num_items + item.item_quantity
53        return num_items62        return num_items
54    def get_cost_of_cart(self):63    def get_cost_of_cart(self):
55        total_cost = 064        total_cost = 0
56        cost = 065        cost = 0
57        for item in self.cart_items:66        for item in self.cart_items:
58            cost = (item.item_quantity * item.item_price)67            cost = (item.item_quantity * item.item_price)
59            total_cost += cost68            total_cost += cost
60        return total_cost69        return total_cost
61    def print_total(self):70    def print_total(self):
nn71        total_cost = self.get_cost_of_cart()
62        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current72        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date))>_date))
63        print('Number of Items: %d\n' % self.get_num_items_in_cart())73        print('Number of Items: %d\n' % self.get_num_items_in_cart())
n64        total_cost = self.get_cost_of_cart()n74        for item in self.cart_items:
75            item.print_item_cost()
65        if total_cost == 0:76        if (total_cost == 0):
66            print('SHOPPING CART IS EMPTY')77            print('SHOPPING CART IS EMPTY')
n67            print('\nTotal: $%d' % total_cost)n78        print('\nTotal: $%d' % (total_cost))
68        else:
69            for item in self.cart_items:
70                item.print_item_cost()
71            print('\nTotal: $%d' % total_cost)
72    def print_descriptions(self):79    def print_descriptions(self):
73        if len(self.cart_items) == 0:80        if len(self.cart_items) == 0:
74            print('SHOPPING CART IS EMPTY')81            print('SHOPPING CART IS EMPTY')
75        else:82        else:
76            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur83            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur
>rent_date))>rent_date))
77            print('\nItem Descriptions')84            print('\nItem Descriptions')
78            for item in self.cart_items:85            for item in self.cart_items:
79                item.print_item_description()86                item.print_item_description()
80def print_menu():87def print_menu():
n81    print('\nMENU\n'n88    print('MENU\n'
82            'a - Add item to cart\n'89            'a - Add item to cart\n'
83            'r - Remove item from cart\n'90            'r - Remove item from cart\n'
84            'c - Change item quantity\n'91            'c - Change item quantity\n'
85            "i - Output items' descriptions\n"92            "i - Output items' descriptions\n"
86            'o - Output shopping cart\n'93            'o - Output shopping cart\n'
87            'q - Quit\n')94            'q - Quit\n')
88def execute_menu(command, my_cart):95def execute_menu(command, my_cart):
89    customer_Cart = my_cart96    customer_Cart = my_cart
90    if command == 'a':97    if command == 'a':
91        print("\nADD ITEM TO CART")98        print("\nADD ITEM TO CART")
92        item_name = input('Enter the item name:\n')99        item_name = input('Enter the item name:\n')
93        item_description = input('Enter the item description:\n')100        item_description = input('Enter the item description:\n')
94        item_price = int(input('Enter the item price:\n'))101        item_price = int(input('Enter the item price:\n'))
95        item_quantity = int(input('Enter the item quantity:\n'))102        item_quantity = int(input('Enter the item quantity:\n'))
96        itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity, it103        itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity, it
>em_description)>em_description)
97        customer_Cart.add_item(itemtoPurchase)104        customer_Cart.add_item(itemtoPurchase)
98    elif command == 'o':105    elif command == 'o':
99        print('OUTPUT SHOPPING CART')106        print('OUTPUT SHOPPING CART')
100        customer_Cart.print_total()107        customer_Cart.print_total()
101    elif command == 'i':108    elif command == 'i':
102        print('\nOUTPUT ITEMS\' DESCRIPTIONS')109        print('\nOUTPUT ITEMS\' DESCRIPTIONS')
103        customer_Cart.print_descriptions()110        customer_Cart.print_descriptions()
104    elif command == 'r':111    elif command == 'r':
105        print('REMOVE ITEM FROM CART')112        print('REMOVE ITEM FROM CART')
106        itemName = input('Enter name of item to remove:\n')113        itemName = input('Enter name of item to remove:\n')
107        customer_Cart.remove_item(itemName)114        customer_Cart.remove_item(itemName)
108    elif command == 'c':115    elif command == 'c':
109        print('\nCHANGE ITEM QUANTITY')116        print('\nCHANGE ITEM QUANTITY')
110        itemName = input('Enter the item name:\n')117        itemName = input('Enter the item name:\n')
111        qty = int(input('Enter the new quantity:\n'))118        qty = int(input('Enter the new quantity:\n'))
112        itemToPurchase = ItemToPurchase(itemName, 0, qty)119        itemToPurchase = ItemToPurchase(itemName, 0, qty)
113        customer_Cart.modify_item(itemToPurchase)120        customer_Cart.modify_item(itemToPurchase)
114if __name__ == "__main__":121if __name__ == "__main__":
115    customer_name = input("Enter customer's name:\n")122    customer_name = input("Enter customer's name:\n")
116    current_date = input("Enter today's date:\n")123    current_date = input("Enter today's date:\n")
117    print("\nCustomer name: %s" % customer_name)124    print("\nCustomer name: %s" % customer_name)
118    print("Today's date: %s" % current_date)125    print("Today's date: %s" % current_date)
119    newCart = ShoppingCart(customer_name, current_date)126    newCart = ShoppingCart(customer_name, current_date)
120    command = ''127    command = ''
121    while command != 'q':128    while command != 'q':
nn129        print()
122        print_menu()130        print_menu()
123        command = input('Choose an option:\n')131        command = input('Choose an option:\n')
124        while command != 'a' and command != 'o' and command != 'i' and command !132        while command != 'a' and command != 'o' and command != 'i' and command !
>= 'q' and command != 'r' and command != 'c':>= 'q' and command != 'r' and command != 'c':
125            command = input('Choose an option:\n')133            command = input('Choose an option:\n')
126        execute_menu(command, newCart)import math134        execute_menu(command, newCart)import math
127class pt3d:135class pt3d:
n128    def __init__(self,x,y,z):n136    def __init__(self,x=0,y=0,z=0):
129        self.x= x137        self.x= x
130        self.y= y138        self.y= y
131        self.z= z139        self.z= z
132    def __add__(self, other):140    def __add__(self, other):
t133        x1 = self.x + other.xt141        x = self.x + other.x
134        y1 = self.y + other.y142        y = self.y + other.y
135        z1 = self.z + other.z143        z = self.z + other.z
136        return pt3d(x1, y1,z1)144        return pt3d(x, y,z)
137    def __sub__(self, other):145    def __sub__(self, other):
138        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 146        return math.sqrt(math.pow(other.x-self.x, 2) + math.pow(other.y-self.y, 
>2)+math.pow(other.z-self.z, 2))>2)+math.pow(other.z-self.z, 2))
139    def __eq__(self, other):147    def __eq__(self, other):
140        return other.x==self.x and other.y==self.y and other.z==self.z148        return other.x==self.x and other.y==self.y and other.z==self.z
141    def __str__(self):149    def __str__(self):
142        return "<{0},{1},{2}>".format(self.x, self.y, self.z)150        return "<{0},{1},{2}>".format(self.x, self.y, self.z)
143if __name__ == '__main__':151if __name__ == '__main__':
144    p1 = pt3d(1, 1, 1)152    p1 = pt3d(1, 1, 1)
145    p2 = pt3d(2, 2, 2)153    p2 = pt3d(2, 2, 2)
146    print(p1+p2)154    print(p1+p2)
147    print(p1-p2)155    print(p1-p2)
148    print(p1==p2)156    print(p1==p2)
149    print(p1+p1==p2)157    print(p1+p1==p2)
150    print(p1==p2+pt3d(-1,-1,-1))158    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 62

Student ID: 347, P-Value: 5.30e-02

Nearest Neighbor ID: 101

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle:n2class Circle():
3    def __init__(self,circ):3    def __init__(self,x):
4        self.circ = circ*2
5        self.radius = circ4        self.radius = x
6    def area(self):5    def area(self):
n7        return math.pi*self.radius*self.radiusn6        return math.pi*self.radius**2
8    def perimeter(self):7    def perimeter(self):
n9        return self.circ*math.pin8        return 2*math.pi*self.radius
10if __name__=='__main__':9if __name__=='__main__':
11    x = int(input())10    x = int(input())
12    NewCircle = Circle(x)11    NewCircle = Circle(x)
13    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
n14    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:n13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:    
15    def __init__(self,name='none',price=0,quantity=0,description='none'):14    def __init__(self,name='none',price=0,quantity=0,description='none'):
16        self.item_name=name15        self.item_name=name
17        self.item_price=price16        self.item_price=price
18        self.item_quantity=quantity17        self.item_quantity=quantity
19        self.item_description=description18        self.item_description=description
20    def print_item_cost(self):19    def print_item_cost(self):
21        totalcost = self.item_price * self.item_quantity20        totalcost = self.item_price * self.item_quantity
22        print('{} {} @ ${} = ${}'.format(self.item_name,self.item_quantity,self.21        print('{} {} @ ${} = ${}'.format(self.item_name,self.item_quantity,self.
>item_price, totalcost))>item_price, totalcost))
23    def print_item_description(self):22    def print_item_description(self):
24        print('{}: {}, {}'.format(self.item_name,self.item_description,self.item23        print('{}: {}, {}'.format(self.item_name,self.item_description,self.item
>_quantity))>_quantity))
n25class ShoppingCart:n24class ShoppingCart:    
26    def __init__(self,name='none',date='January 1, 2016',list=[],total_cost=0):25    def __init__(self,name='none',date='January 1, 2016',list=[],total_cost=0): 
 >  
27        self.customer_name=name26        self.customer_name=name
28        self.current_date=date27        self.current_date=date
29        self.cart_items=list28        self.cart_items=list
30        self.total_cost = total_cost29        self.total_cost = total_cost
31    def add_item(self,ItemToPurchase):30    def add_item(self,ItemToPurchase):
32        self.cart_items.append(ItemToPurchase)31        self.cart_items.append(ItemToPurchase)
33    def remove_item(self,TempName):32    def remove_item(self,TempName):
n34        tempmsg = Falsen33        item = False
35        for x in self.cart_items:34        for i in self.cart_items:
36            if x.item_name==TempName:35            if i.item_name==TempName:
37                self.cart_items.remove(item)36                self.cart_items.remove(i)
38                tempmsg=True37                item = True
39                break38                break
40        if not TempName:39        if not TempName:
41            print('Item not found in the cart. Nothing removed')40            print('Item not found in the cart. Nothing removed')
n42    def modify_item(self, itemToPurchase):  n
43       tmodify_item = False
44       for i in range(len(self.cart_items)):
45           if self.cart_items[i].item_name == itemToPurchase.item_name:
46               tmodify_item = True
47               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
48               break
49       if not tmodify_item:      
50           print('Item not found in the cart. Nothing modified')  
51    def get_num_items_in_cart(self):41    def get_num_items_in_cart(self):
n52       num_items = 0n42        num_items = 0
53       for item in self.cart_items:43        for item in self.cart_items:
54           num_items = num_items + item.item_quantity44            num_items = num_items + item.item_quantity
55       return num_items45        return num_items
56    def get_cost_of_cart(self):46    def get_cost_of_cart(self):
n57       total_cost = 0n47        total_cost = 0
58       cost = 048        cost = 0
59       for item in self.cart_items:49        for item in self.cart_items:
60           cost = (item.item_quantity * item.item_price)50            cost = (item.item_quantity * item.item_price)
61           total_cost += cost51            total_cost += cost
62       return total_cost52        return total_cost
63def execute_menu(command='',newCart=0):53def execute_menu(command='',newCart=0):
64    while(command != 'a' and command != 'o' and command != 'i' and command != 'q54    while(command != 'a' and command != 'o' and command != 'i' and command != 'q
>' and command != 'r' and command != 'c'):>' and command != 'r' and command != 'c'):
65        command = input('Choose an option:\n')55        command = input('Choose an option:\n')
66    if(command == 'o'):56    if(command == 'o'):
67        print(f"OUTPUT SHOPPING CART\n{newCart.customer_name}'s Shopping Cart - 57        print(f"OUTPUT SHOPPING CART\n{newCart.customer_name}'s Shopping Cart - 
>{newCart.current_date}\nNumber of Items: {len(newCart.cart_items)}\n\nSHOPPING C>{newCart.current_date}\nNumber of Items: {len(newCart.cart_items)}\n\nSHOPPING C
>ART IS EMPTY\n\nTotal: ${newCart.total_cost}\n")  >ART IS EMPTY\n\nTotal: ${newCart.total_cost}\n")  
68def print_menu(newCart=0):58def print_menu(newCart=0):
69        print('MENU')59        print('MENU')
70        print('a - Add item to cart')60        print('a - Add item to cart')
71        print('r - Remove item from cart')61        print('r - Remove item from cart')
72        print('c - Change item quantity')62        print('c - Change item quantity')
73        print('i - Output items\' descriptions')63        print('i - Output items\' descriptions')
74        print('o - Output shopping cart')64        print('o - Output shopping cart')
75        print('q - Quit')65        print('q - Quit')
76        print()66        print()
77if __name__ == '__main__':67if __name__ == '__main__':
78    customer_name = input('Enter customer\'s name:\n')68    customer_name = input('Enter customer\'s name:\n')
79    current_date = input('Enter today\'s date:\n')69    current_date = input('Enter today\'s date:\n')
80    print()70    print()
81    print('Customer name: %s' %customer_name)71    print('Customer name: %s' %customer_name)
82    print('Today\'s date: %s' %current_date)72    print('Today\'s date: %s' %current_date)
83    print()73    print()
84    my_cart = ShoppingCart(customer_name, current_date)74    my_cart = ShoppingCart(customer_name, current_date)
85    execute_menu(input('Choose an option:\n'), my_cart)75    execute_menu(input('Choose an option:\n'), my_cart)
86    print_menu()76    print_menu()
87    execute_menu(input('Choose an option:\n'), my_cart)from math import sqrt77    execute_menu(input('Choose an option:\n'), my_cart)from math import sqrt
88class pt3d:78class pt3d:
n89    def __init__(self, x=0, y=0, z=0):n79    def __init__(self, x=0, y=0, z=0):   
90        self.x = x80        self.x = x
91        self.y = y81        self.y = y
92        self.z = z82        self.z = z
n93    def __add__(self, other):n83    def __add__(self, other):  
94        new_points = pt3d(self.x+other.x,self.y+other.y,self.z+other.z)84        new_points = pt3d(self.x+other.x,self.y+other.y,self.z+other.z)
95        return new_points85        return new_points
n96    def __sub__(self, other):n86    def __sub__(self, other):  
97        new_points = sqrt((self.x-other.x)**2+(self.y-other.y)**2+(self.z-other.87        new_points = sqrt((self.x-other.x)**2+(self.y-other.y)**2+(self.z-other.
>z)**2)>z)**2)
98        return new_points88        return new_points
t99    def __eq__(self, other):t89    def __eq__(self, other):  
100        return self.x == other.x and self.y == other.y and self.z == other.z90        return self.x == other.x and self.y == other.y and self.z == other.z
101    def __str__(self):91    def __str__(self):
102        return '<{},{},{}>'.format(self.x, self.y, self.z)92        return '<{},{},{}>'.format(self.x, self.y, self.z)
103p1 = pt3d(1, 1, 1)93p1 = pt3d(1, 1, 1)
104p2 = pt3d(2, 2, 2)94p2 = pt3d(2, 2, 2)
105print(p1 + p2)95print(p1 + p2)
106print(p1 - p2)96print(p1 - p2)
107print(p1 == p2)97print(p1 == p2)
108print(p1+p1 == p2)98print(p1+p1 == p2)
109print(p1==p2+pt3d(-1, -1, -1))99print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 63

Student ID: 101, P-Value: 5.30e-02

Nearest Neighbor ID: 347

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle():n2class Circle:
3    def __init__(self,x):3    def __init__(self,circ):
4        self.circ = circ*2
4        self.radius = x5        self.radius = circ
5    def area(self):6    def area(self):
n6        return math.pi*self.radius**2n7        return math.pi*self.radius*self.radius
7    def perimeter(self):8    def perimeter(self):
n8        return 2*math.pi*self.radiusn9        return self.circ*math.pi
9if __name__=='__main__':10if __name__=='__main__':
10    x = int(input())11    x = int(input())
11    NewCircle = Circle(x)12    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))13    print('{:.5f}'.format(NewCircle.area()))
n13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:    n14    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14    def __init__(self,name='none',price=0,quantity=0,description='none'):15    def __init__(self,name='none',price=0,quantity=0,description='none'):
15        self.item_name=name16        self.item_name=name
16        self.item_price=price17        self.item_price=price
17        self.item_quantity=quantity18        self.item_quantity=quantity
18        self.item_description=description19        self.item_description=description
19    def print_item_cost(self):20    def print_item_cost(self):
20        totalcost = self.item_price * self.item_quantity21        totalcost = self.item_price * self.item_quantity
21        print('{} {} @ ${} = ${}'.format(self.item_name,self.item_quantity,self.22        print('{} {} @ ${} = ${}'.format(self.item_name,self.item_quantity,self.
>item_price, totalcost))>item_price, totalcost))
22    def print_item_description(self):23    def print_item_description(self):
23        print('{}: {}, {}'.format(self.item_name,self.item_description,self.item24        print('{}: {}, {}'.format(self.item_name,self.item_description,self.item
>_quantity))>_quantity))
n24class ShoppingCart:    n25class ShoppingCart:
25    def __init__(self,name='none',date='January 1, 2016',list=[],total_cost=0): 26    def __init__(self,name='none',date='January 1, 2016',list=[],total_cost=0):
>   
26        self.customer_name=name27        self.customer_name=name
27        self.current_date=date28        self.current_date=date
28        self.cart_items=list29        self.cart_items=list
29        self.total_cost = total_cost30        self.total_cost = total_cost
30    def add_item(self,ItemToPurchase):31    def add_item(self,ItemToPurchase):
31        self.cart_items.append(ItemToPurchase)32        self.cart_items.append(ItemToPurchase)
32    def remove_item(self,TempName):33    def remove_item(self,TempName):
n33        item = Falsen34        tempmsg = False
34        for i in self.cart_items:35        for x in self.cart_items:
35            if i.item_name==TempName:36            if x.item_name==TempName:
36                self.cart_items.remove(i)37                self.cart_items.remove(item)
37                item = True38                tempmsg=True
38                break39                break
39        if not TempName:40        if not TempName:
40            print('Item not found in the cart. Nothing removed')41            print('Item not found in the cart. Nothing removed')
nn42    def modify_item(self, itemToPurchase):  
43       tmodify_item = False
44       for i in range(len(self.cart_items)):
45           if self.cart_items[i].item_name == itemToPurchase.item_name:
46               tmodify_item = True
47               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
48               break
49       if not tmodify_item:      
50           print('Item not found in the cart. Nothing modified')  
41    def get_num_items_in_cart(self):51    def get_num_items_in_cart(self):
n42        num_items = 0n52       num_items = 0
43        for item in self.cart_items:53       for item in self.cart_items:
44            num_items = num_items + item.item_quantity54           num_items = num_items + item.item_quantity
45        return num_items55       return num_items
46    def get_cost_of_cart(self):56    def get_cost_of_cart(self):
n47        total_cost = 0n57       total_cost = 0
48        cost = 058       cost = 0
49        for item in self.cart_items:59       for item in self.cart_items:
50            cost = (item.item_quantity * item.item_price)60           cost = (item.item_quantity * item.item_price)
51            total_cost += cost61           total_cost += cost
52        return total_cost62       return total_cost
53def execute_menu(command='',newCart=0):63def execute_menu(command='',newCart=0):
54    while(command != 'a' and command != 'o' and command != 'i' and command != 'q64    while(command != 'a' and command != 'o' and command != 'i' and command != 'q
>' and command != 'r' and command != 'c'):>' and command != 'r' and command != 'c'):
55        command = input('Choose an option:\n')65        command = input('Choose an option:\n')
56    if(command == 'o'):66    if(command == 'o'):
57        print(f"OUTPUT SHOPPING CART\n{newCart.customer_name}'s Shopping Cart - 67        print(f"OUTPUT SHOPPING CART\n{newCart.customer_name}'s Shopping Cart - 
>{newCart.current_date}\nNumber of Items: {len(newCart.cart_items)}\n\nSHOPPING C>{newCart.current_date}\nNumber of Items: {len(newCart.cart_items)}\n\nSHOPPING C
>ART IS EMPTY\n\nTotal: ${newCart.total_cost}\n")  >ART IS EMPTY\n\nTotal: ${newCart.total_cost}\n")  
58def print_menu(newCart=0):68def print_menu(newCart=0):
59        print('MENU')69        print('MENU')
60        print('a - Add item to cart')70        print('a - Add item to cart')
61        print('r - Remove item from cart')71        print('r - Remove item from cart')
62        print('c - Change item quantity')72        print('c - Change item quantity')
63        print('i - Output items\' descriptions')73        print('i - Output items\' descriptions')
64        print('o - Output shopping cart')74        print('o - Output shopping cart')
65        print('q - Quit')75        print('q - Quit')
66        print()76        print()
67if __name__ == '__main__':77if __name__ == '__main__':
68    customer_name = input('Enter customer\'s name:\n')78    customer_name = input('Enter customer\'s name:\n')
69    current_date = input('Enter today\'s date:\n')79    current_date = input('Enter today\'s date:\n')
70    print()80    print()
71    print('Customer name: %s' %customer_name)81    print('Customer name: %s' %customer_name)
72    print('Today\'s date: %s' %current_date)82    print('Today\'s date: %s' %current_date)
73    print()83    print()
74    my_cart = ShoppingCart(customer_name, current_date)84    my_cart = ShoppingCart(customer_name, current_date)
75    execute_menu(input('Choose an option:\n'), my_cart)85    execute_menu(input('Choose an option:\n'), my_cart)
76    print_menu()86    print_menu()
77    execute_menu(input('Choose an option:\n'), my_cart)from math import sqrt87    execute_menu(input('Choose an option:\n'), my_cart)from math import sqrt
78class pt3d:88class pt3d:
n79    def __init__(self, x=0, y=0, z=0):   n89    def __init__(self, x=0, y=0, z=0):
80        self.x = x90        self.x = x
81        self.y = y91        self.y = y
82        self.z = z92        self.z = z
n83    def __add__(self, other):  n93    def __add__(self, other):
84        new_points = pt3d(self.x+other.x,self.y+other.y,self.z+other.z)94        new_points = pt3d(self.x+other.x,self.y+other.y,self.z+other.z)
85        return new_points95        return new_points
n86    def __sub__(self, other):  n96    def __sub__(self, other):
87        new_points = sqrt((self.x-other.x)**2+(self.y-other.y)**2+(self.z-other.97        new_points = sqrt((self.x-other.x)**2+(self.y-other.y)**2+(self.z-other.
>z)**2)>z)**2)
88        return new_points98        return new_points
t89    def __eq__(self, other):  t99    def __eq__(self, other):
90        return self.x == other.x and self.y == other.y and self.z == other.z100        return self.x == other.x and self.y == other.y and self.z == other.z
91    def __str__(self):101    def __str__(self):
92        return '<{},{},{}>'.format(self.x, self.y, self.z)102        return '<{},{},{}>'.format(self.x, self.y, self.z)
93p1 = pt3d(1, 1, 1)103p1 = pt3d(1, 1, 1)
94p2 = pt3d(2, 2, 2)104p2 = pt3d(2, 2, 2)
95print(p1 + p2)105print(p1 + p2)
96print(p1 - p2)106print(p1 - p2)
97print(p1 == p2)107print(p1 == p2)
98print(p1+p1 == p2)108print(p1+p1 == p2)
99print(p1==p2+pt3d(-1, -1, -1))109print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 64

Student ID: 199, P-Value: 5.51e-02

Nearest Neighbor ID: 419

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self, radius):n3    def __init__(self,radius):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
n6        return self.radius*self.radius*math.pin6        return math.pi * self.radius**2
7    def perimeter(self):7    def perimeter(self):
n8        return self.radius* math.pi *2n8        return 2 * math.pi * self.radius
9if __name__=='__main__':9if __name__=='__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14    def __init__(self, name='none', price=0, quantity=0, description='none'):14    def __init__(self, name='none', price=0, quantity=0, description='none'):
15        self.item_name=name15        self.item_name=name
16        self.item_description=description16        self.item_description=description
17        self.item_price=price17        self.item_price=price
18        self.item_quantity=quantity18        self.item_quantity=quantity
19    def print_item_description(self):19    def print_item_description(self):
20        print('%s: %s' % (self.item_name, self.item_description))20        print('%s: %s' % (self.item_name, self.item_description))
21class ShoppingCart:21class ShoppingCart:
22    def __init__(self, customer_name = 'none', current_date = 'January 1, 2016',22    def __init__(self, customer_name = 'none', current_date = 'January 1, 2016',
> cart_items = []):> cart_items = []):
23        self.customer_name = customer_name23        self.customer_name = customer_name
24        self.current_date = current_date24        self.current_date = current_date
25        self.cart_items = cart_items  25        self.cart_items = cart_items  
26    def add_item(self, itemToPurchase):26    def add_item(self, itemToPurchase):
27        self.cart_items.append(itemToPurchase)  27        self.cart_items.append(itemToPurchase)  
28    def remove_item(self, itemName):28    def remove_item(self, itemName):
29        tremove_item = False29        tremove_item = False
30        for item in self.cart_items:30        for item in self.cart_items:
31            if item.item_name == itemName:31            if item.item_name == itemName:
32                self.cart_items.remove(item)32                self.cart_items.remove(item)
33                tremove_item = True33                tremove_item = True
34                break34                break
35        if not tremove_item:          35        if not tremove_item:          
36            print('Item not found in cart. Nothing removed.')36            print('Item not found in cart. Nothing removed.')
37    def modify_item(self, itemToPurchase):  37    def modify_item(self, itemToPurchase):  
38        tmodify_item = False38        tmodify_item = False
39        for i in range(len(self.cart_items)):39        for i in range(len(self.cart_items)):
40            if self.cart_items[i].item_name == itemToPurchase.item_name:40            if self.cart_items[i].item_name == itemToPurchase.item_name:
41                tmodify_item = True41                tmodify_item = True
42                self.cart_items[i].item_quantity = itemToPurchase.item_quantity42                self.cart_items[i].item_quantity = itemToPurchase.item_quantity
43                break43                break
44        if not tmodify_item:      44        if not tmodify_item:      
45            print('Item not found in cart. Nothing modified.')  45            print('Item not found in cart. Nothing modified.')  
46    def get_num_items_in_cart(self):46    def get_num_items_in_cart(self):
47        num_items = 047        num_items = 0
48        for item in self.cart_items:48        for item in self.cart_items:
49            num_items = num_items + item.item_quantity49            num_items = num_items + item.item_quantity
50        return num_items50        return num_items
51    def get_cost_of_cart(self):51    def get_cost_of_cart(self):
52        total_cost = 052        total_cost = 0
53        cost = 053        cost = 0
54        for item in self.cart_items:54        for item in self.cart_items:
55            cost = (item.item_quantity * item.item_price)55            cost = (item.item_quantity * item.item_price)
56            total_cost += cost56            total_cost += cost
57        return total_cost57        return total_cost
58    def print_total(self):58    def print_total(self):
59        total_cost = self.get_cost_of_cart()59        total_cost = self.get_cost_of_cart()
60        if (total_cost == 0):60        if (total_cost == 0):
61            print('SHOPPING CART IS EMPTY')61            print('SHOPPING CART IS EMPTY')
n62            print()n
63            print('Total: $0')
64        else:62        else:
65            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur63            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur
>rent_date))>rent_date))
66            print('Number of Items: %d\n' %self.get_num_items_in_cart())64            print('Number of Items: %d\n' %self.get_num_items_in_cart())
67            for item in self.cart_items:65            for item in self.cart_items:
68                total = item.item_price * item.item_quantity66                total = item.item_price * item.item_quantity
69                print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity,67                print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity,
> item.item_price, total))> item.item_price, total))
70            print('\nTotal: $%d' %(total_cost))68            print('\nTotal: $%d' %(total_cost))
71    def print_descriptions(self):69    def print_descriptions(self):
72        if len(self.cart_items) == 0:70        if len(self.cart_items) == 0:
73            print('SHOPPING CART IS EMPTY')71            print('SHOPPING CART IS EMPTY')
74        else:  72        else:  
75            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur73            print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.cur
>rent_date))>rent_date))
76            print('\nItem Descriptions')74            print('\nItem Descriptions')
77            for item in self.cart_items:75            for item in self.cart_items:
n78                item.print_item_description() n76                item.print_item_description()  
79    def output_cart(self):
80        new=ShoppingCart()
81        print('\nOUTPUT SHOPPING CART', end='\n')
82        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date), end='\n') 
83        print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')
84        tc = 0
85        for item in self.cart_items:
86            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,
> item.item_price, (item.item_quantity * item.item_price)), end='\n') 
87            tc += (item.item_quantity * item.item_price)
88        print('\nTotal: ${}'.format(tc), end='\n')
89def print_menu(ShoppingCart):77def print_menu(newCart=' '):
90    cCart = newCart78    customer_Cart = newCart
91    menu = ('\nMENU\n'79    menu = ('\nMENU\n'
92        'a - Add item to cart\n'80        'a - Add item to cart\n'
93        'r - Remove item from cart\n'81        'r - Remove item from cart\n'
94        'c - Change item quantity\n'82        'c - Change item quantity\n'
95        "i - Output items' descriptions\n"83        "i - Output items' descriptions\n"
96        'o - Output shopping cart\n'84        'o - Output shopping cart\n'
97        'q - Quit\n')85        'q - Quit\n')
98    command = ''86    command = ''
99    while(command != 'q'):87    while(command != 'q'):
100        print(menu)88        print(menu)
101        command = input('Choose an option:\n')89        command = input('Choose an option:\n')
102        while(command != 'a' and command != 'o' and command != 'i' and command !90        while(command != 'a' and command != 'o' and command != 'i' and command !
>= 'q' and command != 'r' and command != 'c'):>= 'q' and command != 'r' and command != 'c'):
103            command = input('Choose an option:\n')91            command = input('Choose an option:\n')
104        if(command == 'a'):92        if(command == 'a'):
105            print("\nADD ITEM TO CART")93            print("\nADD ITEM TO CART")
106            item_name = input('Enter the item name:\n')94            item_name = input('Enter the item name:\n')
107            item_description = input('Enter the item description:\n')95            item_description = input('Enter the item description:\n')
108            item_price = int(input('Enter the item price:\n'))96            item_price = int(input('Enter the item price:\n'))
109            item_quantity = int(input('Enter the item quantity:\n'))97            item_quantity = int(input('Enter the item quantity:\n'))
110            itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity98            itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity
>, item_description)>, item_description)
n111            cCart.add_item(itemtoPurchase)n99            customer_Cart.add_item(itemtoPurchase)
112        elif(command == 'o'):100        elif(command == 'o'):
113            print('OUTPUT SHOPPING CART')101            print('OUTPUT SHOPPING CART')
n114            cCart.print_total() n102            customer_Cart.print_total()  
115        elif(command == 'i'):103        elif(command == 'i'):
116            print('\nOUTPUT ITEMS\' DESCRIPTIONS')104            print('\nOUTPUT ITEMS\' DESCRIPTIONS')
n117            cCart.print_descriptions()n105            customer_Cart.print_descriptions()
118        elif(command == 'r'):106        elif(command == 'r'):
119            print('REMOVE ITEM FROM CART')107            print('REMOVE ITEM FROM CART')
120            itemName = input('Enter name of item to remove:\n')108            itemName = input('Enter name of item to remove:\n')
n121            cCart.remove_item(itemName)n109            customer_Cart.remove_item(itemName)
122        elif(command == 'c'):110        elif(command == 'c'):
123            print('\nCHANGE ITEM QUANTITY')111            print('\nCHANGE ITEM QUANTITY')
124            itemName = input('Enter the item name:\n')112            itemName = input('Enter the item name:\n')
125            qty = int(input('Enter the new quantity:\n'))113            qty = int(input('Enter the new quantity:\n'))
126            itemToPurchase = ItemToPurchase(itemName,0,qty)114            itemToPurchase = ItemToPurchase(itemName,0,qty)
n127            cCart.modify_item(itemToPurchase)n115            customer_Cart.modify_item(itemToPurchase)
128if __name__ == "__main__":116if __name__ == "__main__":
129    customer_name = input("Enter customer's name:\n")117    customer_name = input("Enter customer's name:\n")
130    current_date = input("Enter today's date:\n")118    current_date = input("Enter today's date:\n")
131    print("\nCustomer name: %s" %customer_name)119    print("\nCustomer name: %s" %customer_name)
132    print("Today's date: %s" %current_date)120    print("Today's date: %s" %current_date)
133    newCart = ShoppingCart(customer_name, current_date)121    newCart = ShoppingCart(customer_name, current_date)
n134    print_menu(newCart)  class pt3d:n122    print_menu(newCart)  from math import sqrt
123class pt3d:
135    def __init__(self, x=0, y=0, z=0):124    def __init__(self, x=0, y=0, z=0):
136        self.x = x125        self.x = x
137        self.y = y126        self.y = y
138        self.z = z127        self.z = z
139    def __add__(self, other):128    def __add__(self, other):
n140        x = self.x +other.xn129        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
141        y = self.y +other.y
142        z = self.z +other.z
143        return pt3d(x, y, z)
144    def __sub__(self,other):130    def __sub__(self, other):
145        return (((self.x-other.x)**2) + ((self.y-other.y)**2) + ((self.z-other.z131        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>)**2))**0.5>her.z)**2)
146    def __eq__(self,other):132    def __eq__(self, other):
147        return self.x==other.x and self.y==other.y and self.z ==other.z133        return self.x == other.x and self.y == other.y and self.z == other.z
148    def __str__(self):134    def __str__(self):
t149        return'<{0},{1},{2}>'.format(self.x, self.y, self.z)t135        return '<{},{},{}>'.format(self.x, self.y, self.z)
150if __name__ == '__main__':
151    p1 = pt3d(1, 1, 1)136p1 = pt3d(1, 1, 1)
152    p2 = pt3d(2, 2, 2)137p2 = pt3d(2, 2, 2)
153    print(p1 + p2)138print(p1 + p2)
154    print(p1 - p2)139print(p1 - p2)
155    print(p1 == p2)140print(p1 == p2)
156    print(p1+p1 == p2)141print(p1+p1 == p2)
157    print(p1==p2+pt3d(-1, -1, -1))142print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 65

Student ID: 405, P-Value: 6.82e-02

Nearest Neighbor ID: 87

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self, radius):n3    def __init__(self,radius):
4        self.radius = radius4        self.radius = radius
5    def area(self):5    def area(self):
n6        return math.pi * self.radius * self.radiusn6        return math.pi*self.radius*self.radius
7    def perimeter(self):7    def perimeter(self):
n8        return 2 * math.pi * self.radiusn8        return 2*math.pi*self.radius
9if __name__=='__main__':9if __name__=='__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
n13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:   n13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
14    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des14    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des
>cription = 'none'):>cription = 'none'):
n15        self.item_name = item_name  n15        self.item_name = item_name
16        self.item_price = item_price16        self.item_price = item_price
17        self.item_quantity = item_quantity17        self.item_quantity = item_quantity
n18        self.item_description = item_description  n18        self.item_description = item_description
19    def print_item_cost(self): 19    def print_item_cost(self):
20        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, 20        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, 
>self.item_price,>self.item_price,
n21        (self.item_quantity * self.item_price))  n21        (self.item_quantity * self.item_price))
22        cost = self.item_quantity * self.item_price  22        cost = self.item_quantity * self.item_price
23        return string, cost  23        return string, cost
24    def print_item_description(self):  24    def print_item_description(self):
25        string = '{}: {}, %d oz.'.format(self.item_name, self.item_description, 25        string = '{}: {}, %d oz.'.format(self.item_name, self.item_description, 
>self.item_quantity)>self.item_quantity)
n26        print(string) n26        print(string)
27        return string  27        return string
28class ShoppingCart:28class ShoppingCart:
29    def __init__(self, customer_name = 'none', current_date = 'January 1, 2016',29    def __init__(self, customer_name = 'none', current_date = 'January 1, 2016',
> cart_items = []):> cart_items = []):
n30        self.customer_name = customer_name  n30        self.customer_name = customer_name
31        self.current_date = current_date  31        self.current_date = current_date
32        self.cart_items = cart_items 32        self.cart_items = cart_items
33    def add_item(self):  33    def add_item(self):
34        print('ADD ITEM TO CART') 34        print('ADD ITEM TO CART')
35        item_name = str(input('Enter the item name:')) 35        item_name = str(input('Enter the item name:'))
36        print() 
37        item_description = str(input('Enter the item description:')) 
38        print()36        print()
n39        item_price = int(input('Enter the item price:')) n37        item_description = str(input('Enter the item description:'))
40        print()38        print()
nn39        item_price = int(input('Enter the item price:'))
40        print()
41        item_quantity = int(input('Enter the item quantity:')) 41        item_quantity = int(input('Enter the item quantity:'))
42        print() 42        print()
43        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti43        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti
>ty, item_description))  >ty, item_description))
44    def remove_item(self):  44    def remove_item(self):
45        print('REMOVE ITEM FROM CART') 45        print('REMOVE ITEM FROM CART')
46        string = str(input('Enter name of item to remove:'))  46        string = str(input('Enter name of item to remove:'))
47        print() 47        print()
48        i = 048        i = 0
n49        for item in self.cart_items:  n49        for item in self.cart_items:
50            if(item.item_name == string):                  50            if(item.item_name == string):               
51                del self.cart_items[i]51                del self.cart_items[i]
52                flag=True52                flag=True
53                break53                break
n54            else:   n54            else:
55                flag=False  55                flag=False
56            i += 1  56            i += 1
57        if(flag==False):57        if(flag==False):
n58            print('Item not found in cart. Nothing removed.') n58            print('Item not found in cart. Nothing removed.')
59    def modify_item(self):59    def modify_item(self):
n60        print('CHANGE ITEM QUANTITY')  n60        print('CHANGE ITEM QUANTITY')
61        name = str(input('Enter the item name:'))61        name = str(input('Enter the item name:'))
62        print()62        print()
n63        for item in self.cart_items:   n63        for item in self.cart_items:
64            if(item.item_name == name):64            if(item.item_name == name):
65                quantity = int(input('Enter the new quantity:'))65                quantity = int(input('Enter the new quantity:'))
n66                print()  n66                print()
67                item.item_quantity = quantity  67                item.item_quantity = quantity
68                flag=True68                flag=True
n69                break  n69                break
70            else:70            else:
n71                flag=False  n71                flag=False
72        if(flag==False):  72        if(flag==False):
73            print('Item not found in cart. Nothing modified.')73            print('Item not found in cart. Nothing modified.')
n74        print()   n74        print()
75    def get_num_items_in_cart(self):   75    def get_num_items_in_cart(self):
76        num_items=0   76        num_items=0
77        for item in self.cart_items:77        for item in self.cart_items:
n78            num_items= num_items+item.item_quantity   n78            num_items= num_items+item.item_quantity
79        return num_items79        return num_items
n80    def get_cost_of_cart(self):   n80    def get_cost_of_cart(self):
81        total_cost = 081        total_cost = 0
n82        cost = 0  n82        cost = 0
83        for item in self.cart_items: 83        for item in self.cart_items:
84            cost = (item.item_quantity * item.item_price) 84            cost = (item.item_quantity * item.item_price)
85            total_cost += cost 85            total_cost += cost
86        return total_cost 86        return total_cost
87    def print_total(self):87    def print_total(self):
88        total_cost = self.get_cost_of_cart()88        total_cost = self.get_cost_of_cart()
n89        if (total_cost == 0): n89        if (total_cost == 0):
90            print('SHOPPING CART IS EMPTY') 90            print('SHOPPING CART IS EMPTY')
91        else:91        else:
n92            self.output_cart() n92            self.output_cart()
93    def print_descriptions(self): 93    def print_descriptions(self):
94        print('OUTPUT ITEMS\' DESCRIPTIONS') 94        print('OUTPUT ITEMS\' DESCRIPTIONS')
95        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current95        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date),end='\n')>_date),end='\n')
96        print('\nItem Descriptions')96        print('\nItem Descriptions')
97        for item in self.cart_items:97        for item in self.cart_items:
n98            print('{}: {}'.format(item.item_name, item.item_description))  n98            print('{}: {}'.format(item.item_name, item.item_description))
99    def output_cart(self):99    def output_cart(self):
100        print('OUTPUT SHOPPING CART')100        print('OUTPUT SHOPPING CART')
101        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current101        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date))      >_date))      
102        print('Number of Items:', self.get_num_items_in_cart())102        print('Number of Items:', self.get_num_items_in_cart())
103        print()103        print()
104        tc = 0104        tc = 0
n105        for item in self.cart_items:   n105        for item in self.cart_items:
106            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,106            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,
n107              item.item_price, (item.item_quantity * item.item_price)))  n107              item.item_price, (item.item_quantity * item.item_price)))
108            tc += (item.item_quantity * item.item_price)108            tc += (item.item_quantity * item.item_price)
109        if len(self.cart_items) == 0:109        if len(self.cart_items) == 0:
n110            print('SHOPPING CART IS EMPTY')  n110            print('SHOPPING CART IS EMPTY')
111        print()111        print()
n112        print('Total: ${}'.format(tc))  n112        print('Total: ${}'.format(tc))
113def print_menu(customer_Cart):113def print_menu(customer_Cart):
n114    menu = ('\nMENU\n'   n114    menu = ('\nMENU\n'
115    'a - Add item to cart\n'115    'a - Add item to cart\n'
n116    'r - Remove item from cart\n' n116    'r - Remove item from cart\n'
117    'c - Change item quantity\n' 117    'c - Change item quantity\n'
118    'i - Output items\' descriptions\n'118    'i - Output items\' descriptions\n'
119    'o - Output shopping cart\n'119    'o - Output shopping cart\n'
120    'q - Quit\n')120    'q - Quit\n')
121    command = ''121    command = ''
n122    while(command != 'q'): n122    while(command != 'q'):
123        print(menu)123        print(menu)
n124        command = input('Choose an option:') n124        command = input('Choose an option:')
125        print()125        print()
126        while(command != 'a' and command != 'o' and command != 'i' and command !126        while(command != 'a' and command != 'o' and command != 'i' and command !
>= 'r'>= 'r'
n127              and command != 'c' and command != 'q'): n127              and command != 'c' and command != 'q'):
128            command = input('Choose an option:') 128            command = input('Choose an option:')
129            print() 129            print()
130        if(command == 'a'): 130        if(command == 'a'):
131            customer_Cart.add_item() 131            customer_Cart.add_item()
132        if(command == 'o'): 132        if(command == 'o'):
133            customer_Cart.output_cart()    133            customer_Cart.output_cart()
134        if(command == 'i'): 134        if(command == 'i'):
135            customer_Cart.print_descriptions() 135            customer_Cart.print_descriptions()
136        if(command == 'r'): 136        if(command == 'r'):
137            customer_Cart.remove_item()137            customer_Cart.remove_item()
138        if(command == 'c'):138        if(command == 'c'):
139            customer_Cart.modify_item()139            customer_Cart.modify_item()
n140def main():    n140def main():
141    customer_name = str(input('Enter customer\'s name:'))   141    customer_name = str(input('Enter customer\'s name:'))
142    print()  142    print()
143    current_date = str(input('Enter today\'s date:'))  143    current_date = str(input('Enter today\'s date:'))
144    print('\n')144    print('\n')
n145    print('Customer name:', customer_name, end='\n')   n145    print('Customer name:', customer_name, end='\n')
146    print('Today\'s date:', current_date, end='\n')  146    print('Today\'s date:', current_date, end='\n')
147    newCart = ShoppingCart(customer_name, current_date)  147    newCart = ShoppingCart(customer_name, current_date)
148    print_menu(newCart)148    print_menu(newCart)
149if __name__ == '__main__':149if __name__ == '__main__':
t150    main()   from math import sqrt     t150    main()from math import sqrt
151class pt3d:     151class pt3d:
152    def __init__(self, x, y, z):      152    def __init__(self, x=0, y=0, z=0):
153        self.x = x     153        self.x = x
154        self.y = y  154        self.y = y
155        self.z = z  155        self.z = z
156    def __add__(self, other):  156    def __add__(self, other):
157        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)   157        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
158    def __sub__(self, other):    158    def __sub__(self, other):
159        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot159        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
>her.z)**2)  >her.z)**2)
160    def __eq__(self, other):   160    def __eq__(self, other):
161        return self.x == other.x and self.y == other.y and self.z == other.z   161        return self.x == other.x & self.y == other.y & self.z == other.z
162    def __str__(self):   162    def __str__(self):
163        return '<{},{},{}>'.format(self.x,self.y,self.z)   163        return (f'<{self.x}, {self.y}, {self.z}>')
164p1 = pt3d(1, 1, 1)  164p1 = pt3d(1, 1, 1)
165p2 = pt3d(2, 2, 2)    165p2 = pt3d(2, 2, 2)
166print(p1 + p2)   166print(p1 + p2)
167print(p1 - p2)    167print(p1 - p2)
168print(p1 == p2)   168print(p1 == p2)
169print(p1+p1 == p2)  169print(p1+p1 == p2)
170print(p1==p2+pt3d(-1, -1, -1))   170print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 66

Student ID: 335, P-Value: 6.99e-02

Nearest Neighbor ID: 445

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
3    def __init__(self,x):3    def __init__(self,x):
n4        self.x = xn4        self.radius = x
5    def area(self):5    def area(self):
n6        area = math.pi*(self.x**2)n6        area = math.pi * (self.radius)**2
7        return area7        return area
8    def perimeter(self):8    def perimeter(self):
n9        perimeter= math.pi*(self.x*2)n9        perimeter = 2 * math.pi * self.radius
10        return perimeter 10        return  perimeter
11if __name__=='__main__':11if __name__=='__main__':
12    x = int(input())12    x = int(input())
13    NewCircle = Circle(x)13    NewCircle = Circle(x)
14    print('{:.5f}'.format(NewCircle.area()))14    print('{:.5f}'.format(NewCircle.area()))
15    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:15    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
n16    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_desn16    def __init__(self, name='none', price=0, quantity=0, description='none'):
>cription='none'): 
17        self.item_name = item_name17        self.item_name = name
18        self.item_price = item_price18        self.item_price = price
19        self.item_quantity = item_quantity19        self.item_quantity = quantity
20        self.item_description = item_description20        self.item_description = description
21    def print_item_cost(self):21    def print_item_cost(self):
n22        totalCost = self.item_quantity*self.item_pricen22        total = self.item_quantity*self.item_price
23        print('{} {} @ ${} = ${}'. format(self.item_name, self.item_quantity,sel23        print('{} {} @ ${} = ${}'. format(self.item_name, self.item_quantity,sel
>f.item_price, totalCost))>f.item_price, Cost))
24    def print_item_description(self):24    def print_item_description(self):
25        print('{}: {}'.format(self.item_name,self.item_description))25        print('{}: {}'.format(self.item_name,self.item_description))
26class ShoppingCart:26class ShoppingCart:
n27    def __init__(self, customer_name='none', current_date='January 1, 2016', carn27    def __init__(self, customer='none', current='January 1, 2016', items=[]):
>t_items=[]): 
28        self.customer_name = customer_name28        self.customer_name = customer
29        self.current_date = current_date29        self.current_date = current
30        self.cart_items = cart_items30        self.cart_items = items
31    def add_item(self, string):31    def add_item(self, string):
32        print('\nADD ITEM TO CART', end='\n')32        print('\nADD ITEM TO CART', end='\n')
33        item_name = str(input('Enter the item name:'))33        item_name = str(input('Enter the item name:'))
34        item_description = str(input('\nEnter the item description:'))34        item_description = str(input('\nEnter the item description:'))
35        item_price = int(input('\nEnter the item price:'))35        item_price = int(input('\nEnter the item price:'))
36        item_quantity = int(input('\nEnter the item quantity:'))36        item_quantity = int(input('\nEnter the item quantity:'))
37        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti37        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti
>ty, item_description))>ty, item_description))
38    def remove_item(self):38    def remove_item(self):
39        print('\nREMOVE ITEM FROM CART', end='\n')39        print('\nREMOVE ITEM FROM CART', end='\n')
40        string = str(input('Enter name of item to remove:'))40        string = str(input('Enter name of item to remove:'))
41        i = 041        i = 0
n42        for Z in self.cart_items:n42        for item in self.cart_items:
43            if (Z.item_name == string):43            if (item.item_name == string):
44                del self.cart_items[i]44                del self.cart_items[i]
45                i += 145                i += 1
n46                bruv = Truen46                jawn = True
47                break47                break
48            else:48            else:
n49                bruv = Falsen49                jawn = False
50        if (bruv == False):50        if (jawn == False):
51            print('Item not found in cart. Nothing removed')51            print('Item not found in cart. Nothing removed')
52    def modify_item(self):52    def modify_item(self):
53        print('\nCHANGE ITEM QUANTITY', end='\n')53        print('\nCHANGE ITEM QUANTITY', end='\n')
54        name = str(input('Enter the item name:'))54        name = str(input('Enter the item name:'))
n55        for Z in self.cart_items:n55        for item in self.cart_items:
56            if (Z.item_name == name):56            if (item.item_name == name):
57                quantity = int(input('Enter the new quantity:'))57                quantity = int(input('Enter the new quantity:'))
58                item.item_quantity = quantity58                item.item_quantity = quantity
n59                bruv = Truen59                jawn = True
60                break60                break
61            else:61            else:
n62                bruv = Falsen62                jawn = False
63        if (bruv == False):63        if (jawn == False):
64            print('Item not found in cart. Nothing modified')64            print('Item not found in cart. Nothing modified')
65    def get_num_items_in_cart(self):65    def get_num_items_in_cart(self):
66        num_items = 066        num_items = 0
n67        for Z in self.cart_items:n67        for item in self.cart_items:
68            num_items = num_items + Z.item_quantity68            num_items = num_items + item.item_quantity
69        return num_items69        return num_items
70    def get_cost_of_cart(self):70    def get_cost_of_cart(self):
71        total_cost = 071        total_cost = 0
72        cost = 072        cost = 0
n73        for Z in self.cart_items:n73        for item in self.cart_items:
74            cost = (Z.item_quantity * Z.item_price)74            cost = (item.item_quantity * item.item_price)
75            total_cost += cost75            total_cost += cost
76        return total_cost76        return total_cost
77    def print_total(self):77    def print_total(self):
78        total_cost = self.get_cost_of_cart()78        total_cost = self.get_cost_of_cart()
79        if (total_cost == 0):79        if (total_cost == 0):
80            print('SHOPPING CART IS EMPTY')80            print('SHOPPING CART IS EMPTY')
81        else:81        else:
82            self.output_cart()82            self.output_cart()
83    def print_descriptions(self):83    def print_descriptions(self):
84        print('\nOUTPUT ITEMS\' DESCRIPTIONS')84        print('\nOUTPUT ITEMS\' DESCRIPTIONS')
85        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current85        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date), end='\n')>_date), end='\n')
86        print('\nItem Descriptions', end='\n')86        print('\nItem Descriptions', end='\n')
87        for item in self.cart_items:87        for item in self.cart_items:
88            print('{}: {}'.format(item.item_name, item.item_description), end='\88            print('{}: {}'.format(item.item_name, item.item_description), end='\
>n')>n')
89    def output_cart(self):89    def output_cart(self):
90        new = ShoppingCart()90        new = ShoppingCart()
91        print('\nOUTPUT SHOPPING CART', end='\n')91        print('\nOUTPUT SHOPPING CART', end='\n')
92        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current92        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date), end='\n')>_date), end='\n')
93        print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')93        print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')
94        tc = 094        tc = 0
95        for item in self.cart_items:95        for item in self.cart_items:
96            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,96            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,
97                                             item.item_price, (item.item_quantit97                                             item.item_price, (item.item_quantit
>y * item.item_price)), end='\n')>y * item.item_price)), end='\n')
98            tc += (item.item_quantity * item.item_price)98            tc += (item.item_quantity * item.item_price)
99        print('\nTotal: ${}'.format(tc), end='\n')99        print('\nTotal: ${}'.format(tc), end='\n')
100    def print_menu(ShoppingCart):100    def print_menu(ShoppingCart):
101        customer_Cart = newCart101        customer_Cart = newCart
102        string = ''102        string = ''
103        menu = ('\nMENU\n'103        menu = ('\nMENU\n'
104            'a - Add item to cart\n'104            'a - Add item to cart\n'
105            'r - Remove item from cart\n'105            'r - Remove item from cart\n'
106            'c - Change item quantity\n'106            'c - Change item quantity\n'
107            'i - Output items\' descriptions\n'107            'i - Output items\' descriptions\n'
108            'o - Output shopping cart\n'108            'o - Output shopping cart\n'
109            'q - Quit\n')109            'q - Quit\n')
110        command = ''110        command = ''
111        while (command != 'q'):111        while (command != 'q'):
112            string = ''112            string = ''
113            print(menu, end='\n')113            print(menu, end='\n')
114            command = input('Choose an option:')114            command = input('Choose an option:')
115            while (command != 'a' and command != 'o' and command != 'i' and comm115            while (command != 'a' and command != 'o' and command != 'i' and comm
>and != 'r'>and != 'r'
116                and command != 'c' and command != 'q'):116                and command != 'c' and command != 'q'):
117                command = input('Choose an option:')117                command = input('Choose an option:')
118                if (command == 'a'):118                if (command == 'a'):
119                    customer_Cart.add_item(string)119                    customer_Cart.add_item(string)
120                if (command == 'o'):120                if (command == 'o'):
121                    customer_Cart.output_cart()121                    customer_Cart.output_cart()
122                if (command == 'i'):122                if (command == 'i'):
123                    customer_Cart.print_descriptions()123                    customer_Cart.print_descriptions()
124                if (command == 'r'):124                if (command == 'r'):
125                    customer_Cart.remove_item()125                    customer_Cart.remove_item()
126                if (command == 'c'):126                if (command == 'c'):
127                    customer_Cart.modify_item()127                    customer_Cart.modify_item()
128        customer_name = str(input('Enter customer\'s name:'))128        customer_name = str(input('Enter customer\'s name:'))
129        current_date = str(input('\nEnter today\'s date:'))129        current_date = str(input('\nEnter today\'s date:'))
130        print()130        print()
131        print('\nCustomer name:', customer_name,)131        print('\nCustomer name:', customer_name,)
132        print('Today\'s date:', current_date,)132        print('Today\'s date:', current_date,)
133        newCart = ShoppingCart(customer_name, current_date)133        newCart = ShoppingCart(customer_name, current_date)
134        print_menu(newCart)import math134        print_menu(newCart)import math
135class pt3d:135class pt3d:
136    def __init__(self,x=0,y=0,z=0):136    def __init__(self,x=0,y=0,z=0):
n137        self.x=xn137        self.x = x
138        self.y=y138        self.y = y
139        self.z=z139        self.z = z
140    def __add__(self,L):
141        x1 = self.x+L.x
142        y1 = self.y+L.y
143        z1 = self.z+L.z
144        return pt3d(x1, y1, z1)
145    def __sub__(self,L):
146        x1 = (self.x-L.x)**2
147        y1 = (self.y-L.y)**2
148        z1 = (self.z-L.z)**2
149        return math.sqrt(x1+y1+z1)
150    def __str__(self):
151        return f"<{self.x},{self.y},{self.z}>"
152    def __eq__(self,L):140    def __eq__(self, other):
153        if (self.x == L.x) and (self.y == L.y) and (self.x == L.x):141        if self.x == other.x and self.y == other.y and self.z == other.z:
154            return True142            return True
155        else:143        else:
156            return False144            return False
t157a = pt3d(1,1,1)t145    def __add__(self,other):
158b = pt3d(2,2,2)146        addition_x = self.x + other.x
159print(a-b)147        addition_y = self.y + other.y
148        addition_z = self.z + other.z
149        return pt3d(addition_x,addition_y,addition_z)
150    def __eq__(self, other): 
151        if self.x == other.x and self.y == other.y and self.z == other.z:
152            return True
153        else:
154            return False
155    def __add__(self,other):
156        addition_x = self.x + other.x
157        addition_y = self.y + other.y
158        addition_z = self.z + other.z
159        return pt3d(addition_x,addition_y,addition_z)
160    def __sub__(self, other):
161        subtraction_x = self.x - other.x
162        subtraction_y = self.y - other.y            
163        subtraction_z = self.z - other.z
164        distance = math.sqrt(subtraction_x**2 + subtraction_y**2 + subtraction_z
 >**2)
165        return distance
166    def __str__(self):
167        return (f'<{self.x},{self.y},{self.z}>')
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 67

Student ID: 333, P-Value: 8.04e-02

Nearest Neighbor ID: 279

Student (left) and Nearest Neighbor (right).


n1import math n1import math
2class Circle():2class Circle():
n3    def __init__(self, r):n3    def __init__(self, radius):
4        self.radius = r4        self.radius = radius
5    def area(self):5    def area(self):
n6            return self.radius**2*3.14159265359 n6        return math.pi * self.radius**2
7    def perimeter(self):7    def perimeter(self):
n8        return 2*self.radius*3.14159265359n8        return 2*math.pi*self.radius
9if __name__ == '__main__':
10    x = int(input())
9        NewCircle = Circle(8)11    NewCircle = Circle(x)
10        print(NewCircle.area())12    print('{:.5f}'.format(NewCircle.area()))
11        print(NewCircle.perimeter())13    print('{:.5f}'.format(NewCircle.perimeter()))
12class ItemToPurchase:14class ItemToPurchase:
13   def __init__(self, name='none', price=0, quantity=0, description='none'):15   def __init__(self, name='none', price=0, quantity=0, description='none'):
14       self.item_name=name16       self.item_name=name
15       self.item_description=description17       self.item_description=description
16       self.item_price=price18       self.item_price=price
17       self.item_quantity=quantity19       self.item_quantity=quantity
n18   def print_item_cost(self):n
19       total = self.item_price * self.item_quantity
20       print('%s %d @ $%d = $%d' % (self.item_name, self.item_quantity, self.ite
>m_price, total)) 
21   def print_item_description(self):20   def print_item_description(self):
n22       print('%s: %s' % (self.item_name, self.item_description))  n21       print('%s: %s' % (self.item_name, self.item_description))
23class ShoppingCart:22class ShoppingCart:
n24   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016'):n23   def __init__(self, customer_name = 'none', current_date = 'January 1, 2016'
 >cart_items = []):
25       self.customer_name = customer_name24       self.customer_name = customer_name
26       self.current_date = current_date25       self.current_date = current_date
n27       self.cart_items = []n26       self.cart_items = cart_items  
28   def add_item(self, itemToPurchase):27   def add_item(self, itemToPurchase):
n29       self.cart_items.append(itemToPurchase)n28       self.cart_items.append(itemToPurchase)  
30   def remove_item(self, itemName):29   def remove_item(self, itemName):
31       tremove_item = False30       tremove_item = False
32       for item in self.cart_items:31       for item in self.cart_items:
33           if item.item_name == itemName:32           if item.item_name == itemName:
34               self.cart_items.remove(item)33               self.cart_items.remove(item)
35               tremove_item = True34               tremove_item = True
36               break35               break
37       if not tremove_item:          36       if not tremove_item:          
38           print('Item not found in the cart. Nothing removed')37           print('Item not found in the cart. Nothing removed')
n39   def modify_item(self, itemToPurchase):n38   def modify_item(self, itemToPurchase):  
40       tmodify_item = False39       tmodify_item = False
41       for i in range(len(self.cart_items)):40       for i in range(len(self.cart_items)):
42           if self.cart_items[i].item_name == itemToPurchase.item_name:41           if self.cart_items[i].item_name == itemToPurchase.item_name:
43               tmodify_item = True42               tmodify_item = True
n44               if(itemToPurchase.item_price == 0 and itemToPurchase.item_quantitn
>y == 0 and itemToPurchase.item_description == 'none'): 
45                   break
46               else:
47                   if(itemToPurchase.item_price != 0):
48                       self.cart_items[i].item_price = itemToPurchase.item_price
49                   if(itemToPurchase.item_quantity != 0):
50                       self.cart_items[i].item_quantity = itemToPurchase.item_qu43               self.cart_items[i].item_quantity = itemToPurchase.item_quantity
>antity 
51                   if(itemToPurchase.item_description != 'none'):
52                       self.cart_items[i].item_description = itemToPurchase.item
>_description 
53                   break44               break
54       if not tmodify_item:      45       if not tmodify_item:      
55           print('Item not found in the cart. Nothing modified')  46           print('Item not found in the cart. Nothing modified')  
56   def get_num_items_in_cart(self):47   def get_num_items_in_cart(self):
57       num_items = 048       num_items = 0
58       for item in self.cart_items:49       for item in self.cart_items:
59           num_items = num_items + item.item_quantity50           num_items = num_items + item.item_quantity
60       return num_items51       return num_items
61   def get_cost_of_cart(self):52   def get_cost_of_cart(self):
62       total_cost = 053       total_cost = 0
63       cost = 054       cost = 0
64       for item in self.cart_items:55       for item in self.cart_items:
65           cost = (item.item_quantity * item.item_price)56           cost = (item.item_quantity * item.item_price)
66           total_cost += cost57           total_cost += cost
67       return total_cost58       return total_cost
68   def print_total(self):59   def print_total(self):
69       total_cost = self.get_cost_of_cart()60       total_cost = self.get_cost_of_cart()
70       if (total_cost == 0):61       if (total_cost == 0):
71           print('SHOPPING CART IS EMPTY')62           print('SHOPPING CART IS EMPTY')
72       else:63       else:
73           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr64           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
74           print('Number of Items: %d\n' %self.get_num_items_in_cart())65           print('Number of Items: %d\n' %self.get_num_items_in_cart())
75           for item in self.cart_items:66           for item in self.cart_items:
n76               item.print_item_cost()n67               total = item.item_price * item.item_quantity
68               print('%s %d @ $%d = $%d' % (item.item_name, item.item_quantity, 
 >item.item_price, total))
77           print('\nTotal: $%d' %(total_cost))69           print('\nTotal: $%d' %(total_cost))
78   def print_descriptions(self):70   def print_descriptions(self):
79       if len(self.cart_items) == 0:71       if len(self.cart_items) == 0:
80           print('SHOPPING CART IS EMPTY')72           print('SHOPPING CART IS EMPTY')
81       else:  73       else:  
82           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr74           print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.curr
>ent_date))>ent_date))
83           print('\nItem Descriptions')75           print('\nItem Descriptions')
84           for item in self.cart_items:76           for item in self.cart_items:
85               item.print_item_description()  77               item.print_item_description()  
86def print_menu(newCart):78def print_menu(newCart):
87   customer_Cart = newCart79   customer_Cart = newCart
88   menu = ('\nMENU\n'80   menu = ('\nMENU\n'
89       'a - Add item to cart\n'81       'a - Add item to cart\n'
90       'r - Remove item from the cart\n'82       'r - Remove item from the cart\n'
91       'c - Change item quantity\n'83       'c - Change item quantity\n'
92       "i - Output item's descriptions\n"84       "i - Output item's descriptions\n"
93       'o - Output shopping cart\n'85       'o - Output shopping cart\n'
94       'q - Quit\n')86       'q - Quit\n')
95   command = ''87   command = ''
96   while(command != 'q'):88   while(command != 'q'):
97       print(menu)89       print(menu)
98       command = input('Choose an option:')90       command = input('Choose an option:')
99       while(command != 'a' and command != 'o' and command != 'i' and command !=91       while(command != 'a' and command != 'o' and command != 'i' and command !=
> 'q' and command != 'r' and command != 'c'):> 'q' and command != 'r' and command != 'c'):
100           command = input('Choose an option:\n')92           command = input('Choose an option:\n')
101       if(command == 'a'):93       if(command == 'a'):
102           print("\nADD ITEM TO CART")94           print("\nADD ITEM TO CART")
103           item_name = input('Enter the item name:\n')95           item_name = input('Enter the item name:\n')
104           item_description = input('Enter the item description:\n')96           item_description = input('Enter the item description:\n')
105           item_price = int(input('Enter the item price:\n'))97           item_price = int(input('Enter the item price:\n'))
106           item_quantity = int(input('Enter the item quantity:\n'))98           item_quantity = int(input('Enter the item quantity:\n'))
107           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,99           itemtoPurchase = ItemToPurchase(item_name, item_price, item_quantity,
> item_description)> item_description)
108           customer_Cart.add_item(itemtoPurchase)100           customer_Cart.add_item(itemtoPurchase)
109       elif(command == 'o'):101       elif(command == 'o'):
110           print('\nOUTPUT SHOPPING CART')102           print('\nOUTPUT SHOPPING CART')
111           customer_Cart.print_total()  103           customer_Cart.print_total()  
112       elif(command == 'i'):104       elif(command == 'i'):
113           print('\nOUTPUT ITEMS\' DESCRIPTIONS')105           print('\nOUTPUT ITEMS\' DESCRIPTIONS')
114           customer_Cart.print_descriptions()106           customer_Cart.print_descriptions()
115       elif(command == 'r'):107       elif(command == 'r'):
116           print('REMOVE ITEM FROM CART')108           print('REMOVE ITEM FROM CART')
117           itemName = input('Enter the name of the item to remove :\n')109           itemName = input('Enter the name of the item to remove :\n')
118           customer_Cart.remove_item(itemName)110           customer_Cart.remove_item(itemName)
119       elif(command == 'c'):111       elif(command == 'c'):
120           print('\nCHANGE ITEM QUANTITY')112           print('\nCHANGE ITEM QUANTITY')
121           itemName = input('Enter the name of the item :\n')113           itemName = input('Enter the name of the item :\n')
122           qty = int(input('Enter the new quantity :\n'))114           qty = int(input('Enter the new quantity :\n'))
123           itemToPurchase = ItemToPurchase(itemName,0,qty)115           itemToPurchase = ItemToPurchase(itemName,0,qty)
n124           customer_Cart.modify_item(itemToPurchase)import mathn116           customer_Cart.modify_item(itemToPurchase)
117if __name__ == "__main__":
118   customer_name = input("Enter customer's name:\n")
119   current_date = input("Enter today's date:\n")
120   print("\nCustomer name: %s" %customer_name)
121   print("Today's date: %s" %current_date)
122   newCart = ShoppingCart(customer_name, current_date)
123   print_menu(newCart)from math import sqrt
125class pt3d:124class pt3d:
n126    def __init__(self,x=0,y=0,z=0):n125    def __init__(self, x, y, z):
127        self.x = x126        self.x = x
128        self.y = y127        self.y = y
129        self.z = z128        self.z = z
130    def __add__(self, other):129    def __add__(self, other):
131        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)130        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
132    def __sub__(self, other):131    def __sub__(self, other):
n133        return math.sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.zn132        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
> - other.z)**2)>her.z)**2)
134    def __eq__(self, other):133    def __eq__(self, other):
n135        if self.x == other.x and self.y == other.y and self.z == other.z:n134        return self.x == other.x & self.y == other.y & self.z == other.z
136            return True
137        return False
138    def __str__(self):135    def __str__(self):
t139        return '<{},{},{}>'.format(self.x, self.y, self.z)t136        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
137p1 = pt3d(1, 1, 1)
138p2 = pt3d(2, 2, 2)
139print(p1 + p2)
140print(p1 - p2)
141print(p1 == p2)
142print(p1+p1 == p2)
143print(p1==p2+pt3d(-1, -1, -1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 68

Student ID: 252, P-Value: 8.04e-02

Nearest Neighbor ID: 183

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2class Circle:n2class Circle():
3    def __init__(self,rad):3    def __init__(self, radius):
4        self.rad=rad4        self.radius = radius
5    def area(self):5    def area(self):
n6        area=math.pi*self.rad*self.radn6        return math.pi * self.radius**2
7        return area
8    def perimeter(self):7    def perimeter(self):
n9        per=math.pi*2*self.radn8        return 2 * math.pi * self.radius
10        return per
11if __name__=='__main__':9if __name__=='__main__':
12    x = int(input())10    x = int(input())
13    NewCircle = Circle(x)11    NewCircle = Circle(x)
14    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
15    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
16    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des14    def __init__(self, item_name='none', item_price=0, item_quantity=0, item_des
>cription='none'):>cription='none'):
17        self.item_name = item_name15        self.item_name = item_name
18        self.item_price = item_price16        self.item_price = item_price
19        self.item_quantity = item_quantity17        self.item_quantity = item_quantity
20        self.item_description = item_description18        self.item_description = item_description
21    def print_item_cost(self):19    def print_item_cost(self):
22        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, 20        string = '{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, 
>self.item_price,>self.item_price,
23                                            (self.item_quantity * self.item_pric21                                            (self.item_quantity * self.item_pric
>e))>e))
24        cost = self.item_quantity * self.item_price22        cost = self.item_quantity * self.item_price
25        return string, cost23        return string, cost
26    def print_item_description(self):24    def print_item_description(self):
27        string = '{}: {}'.format(self.item_name, self.item_description)25        string = '{}: {}'.format(self.item_name, self.item_description)
28        print(string, end='\n')26        print(string, end='\n')
29        return string27        return string
30class ShoppingCart:28class ShoppingCart:
31    def __init__(self, customer_name='none', current_date='January 1, 2016', car29    def __init__(self, customer_name='none', current_date='January 1, 2016', car
>t_items=[]):>t_items=[]):
32        self.customer_name = customer_name30        self.customer_name = customer_name
33        self.current_date = current_date31        self.current_date = current_date
34        self.cart_items = cart_items32        self.cart_items = cart_items
35    def add_item(self, string):33    def add_item(self, string):
36        print('\nADD ITEM TO CART', end='\n')34        print('\nADD ITEM TO CART', end='\n')
n37        item_name = str(input('Enter the item name:'))n35        item_name = str(input('Enter the item name: '))
38        item_description = str(input('\nEnter the item description:'))36        item_description = str(input('\nEnter the item description: '))
39        item_price = int(input('\nEnter the item price:'))37        item_price = int(input('\nEnter the item price: '))
40        item_quantity = int(input('\nEnter the item quantity:\n'))38        item_quantity = int(input('\nEnter the item quantity: '))
41        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti39        self.cart_items.append(ItemToPurchase(item_name, item_price, item_quanti
>ty, item_description))>ty, item_description))
42    def remove_item(self):40    def remove_item(self):
n43        print('REMOVE ITEM FROM CART', end='\n')n41        print('\nREMOVE ITEM FROM CART', end='\n')
44        string = str(input('Enter name of item to remove:\n'))42        string = str(input('Enter name of item to remove: '))
45        i = 043        i = 0
46        for item in self.cart_items:44        for item in self.cart_items:
47            if (item.item_name == string):45            if (item.item_name == string):
48                del self.cart_items[i]46                del self.cart_items[i]
49                i += 147                i += 1
50                flag = True48                flag = True
51                break49                break
52            else:50            else:
53                flag = False51                flag = False
54        if (flag == False):52        if (flag == False):
n55            print('Item not found in cart. Nothing removed.')n53            print('Item not found in cart. Nothing removed')
56    def modify_item(self):54    def modify_item(self):
57        print('\nCHANGE ITEM QUANTITY', end='\n')55        print('\nCHANGE ITEM QUANTITY', end='\n')
n58        name = str(input('Enter the item name:'))n56        name = str(input('Enter the item name: '))
59        for item in self.cart_items:57        for item in self.cart_items:
60            if (item.item_name == name):58            if (item.item_name == name):
n61                quantity = int(input('Enter the new quantity:'))n59                quantity = int(input('Enter the new quantity: '))
62                item.item_quantity = quantity60                item.item_quantity = quantity
63                flag = True61                flag = True
64                break62                break
65            else:63            else:
66                flag = False64                flag = False
67        if (flag == False):65        if (flag == False):
n68            print('Item not found in cart. Nothing modified.')n66            print('Item not found in cart. Nothing modified')
69    def get_num_items_in_cart(self):67    def get_num_items_in_cart(self):
70        num_items = 068        num_items = 0
71        for item in self.cart_items:69        for item in self.cart_items:
72            num_items = num_items + item.item_quantity70            num_items = num_items + item.item_quantity
73        return num_items71        return num_items
74    def get_cost_of_cart(self):72    def get_cost_of_cart(self):
75        total_cost = 073        total_cost = 0
76        cost = 074        cost = 0
77        for item in self.cart_items:75        for item in self.cart_items:
78            cost = (item.item_quantity * item.item_price)76            cost = (item.item_quantity * item.item_price)
79            total_cost += cost77            total_cost += cost
80        return total_cost78        return total_cost
81    def print_total(self):79    def print_total(self):
82        total_cost = self.get_cost_of_cart()80        total_cost = self.get_cost_of_cart()
83        if (total_cost == 0):81        if (total_cost == 0):
84            print('SHOPPING CART IS EMPTY')82            print('SHOPPING CART IS EMPTY')
85        else:83        else:
86            self.output_cart()84            self.output_cart()
87    def print_descriptions(self):85    def print_descriptions(self):
88        print('\nOUTPUT ITEMS\' DESCRIPTIONS')86        print('\nOUTPUT ITEMS\' DESCRIPTIONS')
89        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current87        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date), end='\n')>_date), end='\n')
90        print('\nItem Descriptions', end='\n')88        print('\nItem Descriptions', end='\n')
91        for item in self.cart_items:89        for item in self.cart_items:
92            print('{}: {}'.format(item.item_name, item.item_description), end='\90            print('{}: {}'.format(item.item_name, item.item_description), end='\
>n')>n')
93    def output_cart(self):91    def output_cart(self):
94        new = ShoppingCart()92        new = ShoppingCart()
95        print('\nOUTPUT SHOPPING CART', end='\n')93        print('\nOUTPUT SHOPPING CART', end='\n')
96        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current94        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current
>_date), end='\n')>_date), end='\n')
97        print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')95        print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')
98        tc = 096        tc = 0
99        for item in self.cart_items:97        for item in self.cart_items:
100            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,98            print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,
101                                             item.item_price, (item.item_quantit99                                             item.item_price, (item.item_quantit
>y * item.item_price)), end='\n')>y * item.item_price)), end='\n')
102            tc += (item.item_quantity * item.item_price)100            tc += (item.item_quantity * item.item_price)
103        print('\nTotal: ${}'.format(tc), end='\n')101        print('\nTotal: ${}'.format(tc), end='\n')
104def print_menu(ShoppingCart):102def print_menu(ShoppingCart):
105    customer_Cart = newCart103    customer_Cart = newCart
106    string = ''104    string = ''
107    menu = ('\nMENU\n'105    menu = ('\nMENU\n'
108            'a - Add item to cart\n'106            'a - Add item to cart\n'
109            'r - Remove item from cart\n'107            'r - Remove item from cart\n'
110            'c - Change item quantity\n'108            'c - Change item quantity\n'
111            'i - Output items\' descriptions\n'109            'i - Output items\' descriptions\n'
112            'o - Output shopping cart\n'110            'o - Output shopping cart\n'
113            'q - Quit\n')111            'q - Quit\n')
114    command = ''112    command = ''
115    while (command != 'q'):113    while (command != 'q'):
116        string = ''114        string = ''
117        print(menu, end='\n')115        print(menu, end='\n')
n118        command = input('Choose an option:\n')n116        command = input('Choose an option: ')
119        while (command != 'a' and command != 'o' and command != 'i' and command 117        while (command != 'a' and command != 'o' and command != 'i' and command 
>!= 'r'>!= 'r'
120               and command != 'c' and command != 'q'):118               and command != 'c' and command != 'q'):
n121            command = input('Choose an option:\n')n119            command = input('Choose an option: ')
122        if (command == 'a'):120        if (command == 'a'):
123            customer_Cart.add_item(string)121            customer_Cart.add_item(string)
124        if (command == 'o'):122        if (command == 'o'):
125            customer_Cart.output_cart()123            customer_Cart.output_cart()
126        if (command == 'i'):124        if (command == 'i'):
127            customer_Cart.print_descriptions()125            customer_Cart.print_descriptions()
128        if (command == 'r'):126        if (command == 'r'):
129            customer_Cart.remove_item()127            customer_Cart.remove_item()
130        if (command == 'c'):128        if (command == 'c'):
131            customer_Cart.modify_item()129            customer_Cart.modify_item()
n132if __name__ == '__main__':n
133    customer_name = str(input('Enter customer\'s name:'))130customer_name = str(input('Enter customer\'s name: '))
134    current_date = str(input('\nEnter today\'s date:\n\n'))131current_date = str(input('\nEnter today\'s date: '))
135    print('Customer name:', customer_name)132print('Customer name:', customer_name, end='\n')
136    print('Today\'s date:', current_date)133print('Today\'s date:', current_date, end='\n')
137    newCart = ShoppingCart(customer_name, current_date)134newCart = ShoppingCart(customer_name, current_date)
138    print_menu(newCart)135print_menu(newCart)from math import sqrt
139import math
140class pt3d:136class pt3d:
n141    def __init__(self,x=0,y=0,z=0):n137    def __init__(self, x=0, y=0, z=0):
142        self.x = x138        self.x = x
143        self.y = y139        self.y = y
144        self.z = z140        self.z = z
n145    def __add__(self,pt):n141    def __add__(self, other):
146        if isinstance(pt,pt3d):
147            return pt3d(self.x + pt.x , self.y + pt.y , self.z + pt.z)142        return pt3d(self.x + other.x, self.y + other.y, self.z + other.z)
148    def __sub__(self,pt):143    def __sub__(self, other):
149        if isinstance(pt,pt3d):144        return sqrt((self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - ot
 >her.z)**2)
150            X = pow((self.x - pt.x),2)
151            Y = pow((self.y - pt.y),2)
152            Z = pow((self.z - pt.z),2)
153            return math.sqrt(X + Y + Z)
154    def __eq__(self,pt):145    def __eq__(self, other):
155        if self.x == pt.x and self.y == pt.y and self.z == pt.z:146        return self.x == other.x & self.y == other.y & self.z == other.z
156            return True
157        else:
158            return False
159    def __str__(self):147    def __str__(self):
t160        return "<{},{},{}>".format(self.x,self.y,self.z)t148        return '<{}, {}, {}>'.format(self.x, self.y, self.z)
161def main():149if __name__ == '__main__':
162    p1 = pt3d(1,1,1)150    p1 = pt3d(1, 1, 1)
163    p2 = pt3d(2,2,2)151    p2 = pt3d(2, 2, 2)
164    print(p1 + p2)152    print(p1+p2)
165    print(p1 - p2)153    print(p1-p2)
166    print(p1 == p2)154    print(p1==p2)
167    print(p1+p1 == p2)155    print(p1+p1==p2)
168if __name__ == "__main__":156    print(p1==p2+pt3d(-1,-1,-1))
169    main() 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 69

Student ID: 56, P-Value: 8.32e-02

Nearest Neighbor ID: 325

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self,radius=0,):n3    def __init__(self,x=0):
4        self.radius=radius4        self.x=x
5    def area(self):5    def area(self):
n6        area=self.radius*self.radius*math.pin6        return (self.x**2)*math.pi
7        return area
8    def perimeter(self):7    def perimeter(self):
n9        perimeter=2*self.radius*math.pin8        return self.x*2*math.pi
10        return perimeter
11if __name__=='__main__':9if __name__=='__main__':
12    x = int(input())10    x = int(input())
13    NewCircle = Circle(x)11    NewCircle = Circle(x)
14    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
15    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
n16    def init(self,item_name='none',item_price=0,item_quantity=0,item_descriptionn14    def __init__(self,item_name='none',item_price=0,item_quantity=0,item_descrip
>='none'):>tion='none'):
17        self.item_name=item_name15        self.item_name=item_name
18        self.item_price=item_price16        self.item_price=item_price
19        self.item_quantity=item_quantity17        self.item_quantity=item_quantity
20        self.item_description=item_description18        self.item_description=item_description
21    def print_item_description(self):19    def print_item_description(self):
22        return print(self.item_description)20        return print(self.item_description)
23    def print_item_cost(self):21    def print_item_cost(self):
24        totalCost=self.item_quantity*self.item_price22        totalCost=self.item_quantity*self.item_price
25        print('{} {} @ ${} = ${}'.format(self.item_name,self.item_quantity,self.23        print('{} {} @ ${} = ${}'.format(self.item_name,self.item_quantity,self.
>item_price,totalCost))>item_price,totalCost))
26class ShoppingCart:24class ShoppingCart:
27    def __init__(self,customer_name='none',current_date='January 1, 2016',cart_i25    def __init__(self,customer_name='none',current_date='January 1, 2016',cart_i
>tems=[]):>tems=[]):
28        self.customer_name=customer_name26        self.customer_name=customer_name
29        self.current_date=current_date27        self.current_date=current_date
30        self.cart_items=cart_items28        self.cart_items=cart_items
n31    def __add_item__(self,ItemToPurchase):n29    def add_item(self,ItemToPurchase):
32        print('ADD ITEM TO CART',end='\n')30        print('ADD ITEM TO CART',end='\n')
33        item_name=str(input('Enter the item name:\n'))31        item_name=str(input('Enter the item name:\n'))
34        item_description=str(input('Enter the item description:\n'))32        item_description=str(input('Enter the item description:\n'))
35        item_price=int(input('Enter the item price:\n'))33        item_price=int(input('Enter the item price:\n'))
36        item_quantity=int(input('Enter the item quantity:\n'))34        item_quantity=int(input('Enter the item quantity:\n'))
37        self.cart_items.append(ItemToPurchase(item_name,item_price,item_quantity35        self.cart_items.append(ItemToPurchase(item_name,item_price,item_quantity
>,item_description))>,item_description))
38    def remove_item(self):36    def remove_item(self):
39        print('REMOVE ITEM FROM CART\n')37        print('REMOVE ITEM FROM CART\n')
40        item=str(input('Enter name of item to remove:\n'))38        item=str(input('Enter name of item to remove:\n'))
41        i=039        i=0
42        for item in self.cart_items:40        for item in self.cart_items:
43            if self.item_name == item:41            if self.item_name == item:
44                self.cart_items.remove(item)42                self.cart_items.remove(item)
45                i+=143                i+=1
46                delete=True44                delete=True
47                break45                break
48            else:46            else:
49                delete=False47                delete=False
50        if delete==False:48        if delete==False:
51            print('Item not found in cart. Nothing removed.')49            print('Item not found in cart. Nothing removed.')
52    def modify_item(self):50    def modify_item(self):
53        print('CHANGE ITEM QUANTITY\n')51        print('CHANGE ITEM QUANTITY\n')
54        name=str(input('Enter the item name:\n'))52        name=str(input('Enter the item name:\n'))
55        for item in self.cart_items:53        for item in self.cart_items:
56            if self.item_name == name:54            if self.item_name == name:
57                quantity=int(input('Enter the new quantity:\n'))55                quantity=int(input('Enter the new quantity:\n'))
58                item.item_quantity=quantity56                item.item_quantity=quantity
59                mod = True57                mod = True
60                break58                break
61            else:59            else:
62                mod=False60                mod=False
63        if mod==False:61        if mod==False:
64            print('Item not found in cart. Nothing modified.')62            print('Item not found in cart. Nothing modified.')
65    def get_num_items_in_cart(self):63    def get_num_items_in_cart(self):
66        total=064        total=0
67        for item in self.cart_items:65        for item in self.cart_items:
68            total+=item.item_quantity66            total+=item.item_quantity
69        return total67        return total
70    def get_cost_of_cart(self):68    def get_cost_of_cart(self):
71        totalc=069        totalc=0
72        for item in self.cart_items:70        for item in self.cart_items:
n73            totalc+=(self.item_quantityself.item_price)n71            totalc+=(self.item_quantity*self.item_price)
74        return totalc72        return totalc
75    def print_total(self,get_cost_of_cart,output_cart):73    def print_total(self,get_cost_of_cart,output_cart):
76        totalcost=get_cost_of_cart()74        totalcost=get_cost_of_cart()
77        if totalcost==0:75        if totalcost==0:
78            print('SHOPPING CART IS EMPTY')76            print('SHOPPING CART IS EMPTY')
79        else:77        else:
80            output_cart()78            output_cart()
81    def print_descriptions(self):79    def print_descriptions(self):
82        print("OUTPUT ITEMS' DESCRIPTIONS\n")80        print("OUTPUT ITEMS' DESCRIPTIONS\n")
83        print("{}'s Shopping Cart - {}\n".format(self.customer_name,self.current81        print("{}'s Shopping Cart - {}\n".format(self.customer_name,self.current
>_date))>_date))
84        print('Item Descriptions\n')82        print('Item Descriptions\n')
85        for item in self.cart_items:83        for item in self.cart_items:
86            print('{}: {}\n'.format(item.item_name,item.item_description))84            print('{}: {}\n'.format(item.item_name,item.item_description))
87    def output_cart(self):85    def output_cart(self):
88        new=ShoppingCart()86        new=ShoppingCart()
89        print('OUTPUT SHOPPING CART\n')87        print('OUTPUT SHOPPING CART\n')
90        print("{}'s Shopping Cart - {}\n".format(self.customer_name,self.current88        print("{}'s Shopping Cart - {}\n".format(self.customer_name,self.current
>_date))>_date))
91        print('Number of Items: {}\n'.format(new.get_num_items_in_cart))89        print('Number of Items: {}\n'.format(new.get_num_items_in_cart))
92        costtotal=090        costtotal=0
93        for item in self.cart_items:91        for item in self.cart_items:
94            print('{} {} @ ${} = ${}\n'.format(item.item_name,item.item_quantity92            print('{} {} @ ${} = ${}\n'.format(item.item_name,item.item_quantity
>,item.item_price,>,item.item_price,
n95            (item.item_quantityitem.item_price)))n93            (item.item_quantity*item.item_price)))
96        costtotal+=(item.item_quantity*item.item_price)94        costtotal+=(item.item_quantity*item.item_price)
97        print('Total: ${}\n'.format(costtotal))95        print('Total: ${}\n'.format(costtotal))
98    def print_menu(ShoppingCart):96    def print_menu(ShoppingCart):
99        customer_Cart=newCart97        customer_Cart=newCart
100        blank=''98        blank=''
101        menu=('MENU\n'99        menu=('MENU\n'
102        'a - Add item to cart\n'100        'a - Add item to cart\n'
103        'r - Remove item from cart\n'101        'r - Remove item from cart\n'
104        'c - Change item quantity\n'102        'c - Change item quantity\n'
105        "i - Output items' descriptions\n"103        "i - Output items' descriptions\n"
106        'o - Output shopping cart\n'104        'o - Output shopping cart\n'
107        'q - Quit\n')105        'q - Quit\n')
108        command=''106        command=''
109        while command!='q':107        while command!='q':
n110            string=''n108            blank=''
111            print(menu,end='\n')109            print(menu,end='\n')
112            command = input('Choose an option:\n')110            command = input('Choose an option:\n')
n113        while (command != 'a' and command != 'r' and command != 'c' and command n111            while (command != 'a' and command != 'r' and command != 'c' and comm
>!= 'i' and command != 'o' and command != 'q'):>and != 'i' and command != 'o' 
112            and command != 'q'):
114            command = input('Choose an option:\n')113                command = input('Choose an option:\n')
115            if command == 'a':114        if command == 'a':
116                customer_Cart.add_item(string)115            customer_Cart.add_item(blank)
117            if command == 'r':116        if command == 'r':
118                customer_Cart.remove_item()117            customer_Cart.remove_item()
119            if command == 'c':118        if command == 'c':
120                customer_Cart.modify_item()119            customer_Cart.modify_item()
121            if command == 'i':120        if command == 'i':
122                customer_Cart.print_descriptions()121            customer_Cart.print_descriptions()
123            if command == 'o':122        if command == 'o':
124                customer_Cart.output_cart()123            customer_Cart.output_cart()
125if __name__=='__main__':124if __name__=='__main__':
126    itemdesc=ItemToPurchase()125    itemdesc=ItemToPurchase()
n127    customer_name=str(input("Enter customer's name:\n"))n126    shopcart=ShoppingCart()
128    current_date=str(input("Enter today's date:\n"))127    customer_name=str(input())
128    current_date=str(input())
129    print("Enter customer's name:")
130    print("Enter today's date:")
129    print('\nCustomer name: {}'.format(customer_name))131    print('\nCustomer name: {}'.format(customer_name))
130    print("Today's date: {}\n".format(current_date))132    print("Today's date: {}\n".format(current_date))
131    newCart=ShoppingCart(customer_name,current_date)133    newCart=ShoppingCart(customer_name,current_date)
n132    newCart.print_menun134    shopcart.print_menu()import math
133    ShoppinCart.output_cartfrom math import dist
134import math
135class pt3d:135class pt3d:
136    def __init__(self,x=0,y=0,z=0):136    def __init__(self,x=0,y=0,z=0):
n137        self.x=xn137        self.x = x
138        self.y=y138        self.y = y
139        self.z=z139        self.z = z
140        self.add_x=0
141        self.add_y=0
142        self.add_z=0
143    def __add__(self,jeff):140    def __add__ (self,number):
144        add_x=self.x+jeff.x141        x = self.x + number.x
145        add_y=self.y+jeff.y142        y = self.y + number.y
146        add_z=self.z+jeff.z143        z = self.z + number.z
147        return pt3d(add_x,add_y,add_z)144        return pt3d(x,y,z)
148    def __sub__(self,jeff):145    def __sub__ (self,number):
149        return math.sqrt(math.pow(self.x-jeff.x,2)+math.pow(self.y-jeff.y,2)+mat146        return math.sqrt(math.pow(number.x - self.x, 2) + math.pow(number.y - se
>h.pow(self.z-jeff.z,2))>lf.y, 2) + math.pow(number.z - self.z, 2))
150    def __eq__(self,jeff):147    def __eq__ (self,number):
151        if self.x==jeff.x and self.y==jeff.y and self.z==jeff.z: 148        if number.x == self.x:
152            return True149            return True
nn150        elif number.y == self.y:
151            return True
152        elif number.z == self.z:
153            return True
154        else:
155            return False
153    def __str__(self):156    def __str__ (self):
154        return f'<{self.x},{self.y},{self.z}>'157        return f'<{self.x},{self.y},{self.z}>'
155if __name__=='__main__':158if __name__=='__main__':
156    p1=pt3d(1,1,1)159    p1=pt3d(1,1,1)
157    p2=pt3d(2,2,2)160    p2=pt3d(2,2,2)
t158    print(p1+p2)t161    print(p1 + p2)
159    print(p1-p2)162    print(p1 - p2)
160    print(p1==p2)163    print(p1 == p2)
161    print(p1+p2==p2)164    print((p1 + p1) == p2)
162    print(p1==p2+pt3d(-1,-1,-1))165    print(p1 == (p2 + pt3d(-1,-1,-1)))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 70

Student ID: 325, P-Value: 8.32e-02

Nearest Neighbor ID: 56

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self,x=0):n3    def __init__(self,radius=0,):
4        self.x=x4        self.radius=radius
5    def area(self):5    def area(self):
n6        return (self.x**2)*math.pin6        area=self.radius*self.radius*math.pi
7        return area
7    def perimeter(self):8    def perimeter(self):
n8        return self.x*2*math.pin9        perimeter=2*self.radius*math.pi
10        return perimeter
9if __name__=='__main__':11if __name__=='__main__':
10    x = int(input())12    x = int(input())
11    NewCircle = Circle(x)13    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))14    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:15    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
n14    def __init__(self,item_name='none',item_price=0,item_quantity=0,item_descripn16    def init(self,item_name='none',item_price=0,item_quantity=0,item_description
>tion='none'):>='none'):
15        self.item_name=item_name17        self.item_name=item_name
16        self.item_price=item_price18        self.item_price=item_price
17        self.item_quantity=item_quantity19        self.item_quantity=item_quantity
18        self.item_description=item_description20        self.item_description=item_description
19    def print_item_description(self):21    def print_item_description(self):
20        return print(self.item_description)22        return print(self.item_description)
21    def print_item_cost(self):23    def print_item_cost(self):
22        totalCost=self.item_quantity*self.item_price24        totalCost=self.item_quantity*self.item_price
23        print('{} {} @ ${} = ${}'.format(self.item_name,self.item_quantity,self.25        print('{} {} @ ${} = ${}'.format(self.item_name,self.item_quantity,self.
>item_price,totalCost))>item_price,totalCost))
24class ShoppingCart:26class ShoppingCart:
25    def __init__(self,customer_name='none',current_date='January 1, 2016',cart_i27    def __init__(self,customer_name='none',current_date='January 1, 2016',cart_i
>tems=[]):>tems=[]):
26        self.customer_name=customer_name28        self.customer_name=customer_name
27        self.current_date=current_date29        self.current_date=current_date
28        self.cart_items=cart_items30        self.cart_items=cart_items
n29    def add_item(self,ItemToPurchase):n31    def __add_item__(self,ItemToPurchase):
30        print('ADD ITEM TO CART',end='\n')32        print('ADD ITEM TO CART',end='\n')
31        item_name=str(input('Enter the item name:\n'))33        item_name=str(input('Enter the item name:\n'))
32        item_description=str(input('Enter the item description:\n'))34        item_description=str(input('Enter the item description:\n'))
33        item_price=int(input('Enter the item price:\n'))35        item_price=int(input('Enter the item price:\n'))
34        item_quantity=int(input('Enter the item quantity:\n'))36        item_quantity=int(input('Enter the item quantity:\n'))
35        self.cart_items.append(ItemToPurchase(item_name,item_price,item_quantity37        self.cart_items.append(ItemToPurchase(item_name,item_price,item_quantity
>,item_description))>,item_description))
36    def remove_item(self):38    def remove_item(self):
37        print('REMOVE ITEM FROM CART\n')39        print('REMOVE ITEM FROM CART\n')
38        item=str(input('Enter name of item to remove:\n'))40        item=str(input('Enter name of item to remove:\n'))
39        i=041        i=0
40        for item in self.cart_items:42        for item in self.cart_items:
41            if self.item_name == item:43            if self.item_name == item:
42                self.cart_items.remove(item)44                self.cart_items.remove(item)
43                i+=145                i+=1
44                delete=True46                delete=True
45                break47                break
46            else:48            else:
47                delete=False49                delete=False
48        if delete==False:50        if delete==False:
49            print('Item not found in cart. Nothing removed.')51            print('Item not found in cart. Nothing removed.')
50    def modify_item(self):52    def modify_item(self):
51        print('CHANGE ITEM QUANTITY\n')53        print('CHANGE ITEM QUANTITY\n')
52        name=str(input('Enter the item name:\n'))54        name=str(input('Enter the item name:\n'))
53        for item in self.cart_items:55        for item in self.cart_items:
54            if self.item_name == name:56            if self.item_name == name:
55                quantity=int(input('Enter the new quantity:\n'))57                quantity=int(input('Enter the new quantity:\n'))
56                item.item_quantity=quantity58                item.item_quantity=quantity
57                mod = True59                mod = True
58                break60                break
59            else:61            else:
60                mod=False62                mod=False
61        if mod==False:63        if mod==False:
62            print('Item not found in cart. Nothing modified.')64            print('Item not found in cart. Nothing modified.')
63    def get_num_items_in_cart(self):65    def get_num_items_in_cart(self):
64        total=066        total=0
65        for item in self.cart_items:67        for item in self.cart_items:
66            total+=item.item_quantity68            total+=item.item_quantity
67        return total69        return total
68    def get_cost_of_cart(self):70    def get_cost_of_cart(self):
69        totalc=071        totalc=0
70        for item in self.cart_items:72        for item in self.cart_items:
n71            totalc+=(self.item_quantity*self.item_price)n73            totalc+=(self.item_quantityself.item_price)
72        return totalc74        return totalc
73    def print_total(self,get_cost_of_cart,output_cart):75    def print_total(self,get_cost_of_cart,output_cart):
74        totalcost=get_cost_of_cart()76        totalcost=get_cost_of_cart()
75        if totalcost==0:77        if totalcost==0:
76            print('SHOPPING CART IS EMPTY')78            print('SHOPPING CART IS EMPTY')
77        else:79        else:
78            output_cart()80            output_cart()
79    def print_descriptions(self):81    def print_descriptions(self):
80        print("OUTPUT ITEMS' DESCRIPTIONS\n")82        print("OUTPUT ITEMS' DESCRIPTIONS\n")
81        print("{}'s Shopping Cart - {}\n".format(self.customer_name,self.current83        print("{}'s Shopping Cart - {}\n".format(self.customer_name,self.current
>_date))>_date))
82        print('Item Descriptions\n')84        print('Item Descriptions\n')
83        for item in self.cart_items:85        for item in self.cart_items:
84            print('{}: {}\n'.format(item.item_name,item.item_description))86            print('{}: {}\n'.format(item.item_name,item.item_description))
85    def output_cart(self):87    def output_cart(self):
86        new=ShoppingCart()88        new=ShoppingCart()
87        print('OUTPUT SHOPPING CART\n')89        print('OUTPUT SHOPPING CART\n')
88        print("{}'s Shopping Cart - {}\n".format(self.customer_name,self.current90        print("{}'s Shopping Cart - {}\n".format(self.customer_name,self.current
>_date))>_date))
89        print('Number of Items: {}\n'.format(new.get_num_items_in_cart))91        print('Number of Items: {}\n'.format(new.get_num_items_in_cart))
90        costtotal=092        costtotal=0
91        for item in self.cart_items:93        for item in self.cart_items:
92            print('{} {} @ ${} = ${}\n'.format(item.item_name,item.item_quantity94            print('{} {} @ ${} = ${}\n'.format(item.item_name,item.item_quantity
>,item.item_price,>,item.item_price,
n93            (item.item_quantity*item.item_price)))n95            (item.item_quantityitem.item_price)))
94        costtotal+=(item.item_quantity*item.item_price)96        costtotal+=(item.item_quantity*item.item_price)
95        print('Total: ${}\n'.format(costtotal))97        print('Total: ${}\n'.format(costtotal))
96    def print_menu(ShoppingCart):98    def print_menu(ShoppingCart):
97        customer_Cart=newCart99        customer_Cart=newCart
98        blank=''100        blank=''
99        menu=('MENU\n'101        menu=('MENU\n'
100        'a - Add item to cart\n'102        'a - Add item to cart\n'
101        'r - Remove item from cart\n'103        'r - Remove item from cart\n'
102        'c - Change item quantity\n'104        'c - Change item quantity\n'
103        "i - Output items' descriptions\n"105        "i - Output items' descriptions\n"
104        'o - Output shopping cart\n'106        'o - Output shopping cart\n'
105        'q - Quit\n')107        'q - Quit\n')
106        command=''108        command=''
107        while command!='q':109        while command!='q':
n108            blank=''n110            string=''
109            print(menu,end='\n')111            print(menu,end='\n')
110            command = input('Choose an option:\n')112            command = input('Choose an option:\n')
n111            while (command != 'a' and command != 'r' and command != 'c' and commn113        while (command != 'a' and command != 'r' and command != 'c' and command 
>and != 'i' and command != 'o' >!= 'i' and command != 'o' and command != 'q'):
112            and command != 'q'):
113                command = input('Choose an option:\n')114            command = input('Choose an option:\n')
114        if command == 'a':115            if command == 'a':
115            customer_Cart.add_item(blank)116                customer_Cart.add_item(string)
116        if command == 'r':117            if command == 'r':
117            customer_Cart.remove_item()118                customer_Cart.remove_item()
118        if command == 'c':119            if command == 'c':
119            customer_Cart.modify_item()120                customer_Cart.modify_item()
120        if command == 'i':121            if command == 'i':
121            customer_Cart.print_descriptions()122                customer_Cart.print_descriptions()
122        if command == 'o':123            if command == 'o':
123            customer_Cart.output_cart()124                customer_Cart.output_cart()
124if __name__=='__main__':125if __name__=='__main__':
125    itemdesc=ItemToPurchase()126    itemdesc=ItemToPurchase()
n126    shopcart=ShoppingCart()n127    customer_name=str(input("Enter customer's name:\n"))
127    customer_name=str(input())128    current_date=str(input("Enter today's date:\n"))
128    current_date=str(input())
129    print("Enter customer's name:")
130    print("Enter today's date:")
131    print('\nCustomer name: {}'.format(customer_name))129    print('\nCustomer name: {}'.format(customer_name))
132    print("Today's date: {}\n".format(current_date))130    print("Today's date: {}\n".format(current_date))
133    newCart=ShoppingCart(customer_name,current_date)131    newCart=ShoppingCart(customer_name,current_date)
n134    shopcart.print_menu()import mathn132    newCart.print_menu
133    ShoppinCart.output_cartfrom math import dist
134import math
135class pt3d:135class pt3d:
136    def __init__(self,x=0,y=0,z=0):136    def __init__(self,x=0,y=0,z=0):
n137        self.x = xn137        self.x=x
138        self.y = y138        self.y=y
139        self.z = z139        self.z=z
140        self.add_x=0
141        self.add_y=0
142        self.add_z=0
140    def __add__ (self,number):143    def __add__(self,jeff):
141        x = self.x + number.x144        add_x=self.x+jeff.x
142        y = self.y + number.y145        add_y=self.y+jeff.y
143        z = self.z + number.z146        add_z=self.z+jeff.z
144        return pt3d(x,y,z)147        return pt3d(add_x,add_y,add_z)
145    def __sub__ (self,number):148    def __sub__(self,jeff):
146        return math.sqrt(math.pow(number.x - self.x, 2) + math.pow(number.y - se149        return math.sqrt(math.pow(self.x-jeff.x,2)+math.pow(self.y-jeff.y,2)+mat
>lf.y, 2) + math.pow(number.z - self.z, 2))>h.pow(self.z-jeff.z,2))
147    def __eq__ (self,number):150    def __eq__(self,jeff):
148        if number.x == self.x:151        if self.x==jeff.x and self.y==jeff.y and self.z==jeff.z: 
149            return True152            return True
n150        elif number.y == self.y:n
151            return True
152        elif number.z == self.z:
153            return True
154        else:
155            return False
156    def __str__ (self):153    def __str__(self):
157        return f'<{self.x},{self.y},{self.z}>'154        return f'<{self.x},{self.y},{self.z}>'
158if __name__=='__main__':155if __name__=='__main__':
159    p1=pt3d(1,1,1)156    p1=pt3d(1,1,1)
160    p2=pt3d(2,2,2)157    p2=pt3d(2,2,2)
t161    print(p1 + p2)t158    print(p1+p2)
162    print(p1 - p2)159    print(p1-p2)
163    print(p1 == p2)160    print(p1==p2)
164    print((p1 + p1) == p2)161    print(p1+p2==p2)
165    print(p1 == (p2 + pt3d(-1,-1,-1)))162    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 71

Student ID: 179, P-Value: 9.29e-01

Nearest Neighbor ID: 436

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self,x):n3    def __init__(self,radius):
4        self.x=x4        self.radius = radius
5    def area(self):5    def area(self):
n6        return math.pi*self.x*self.xn6        return math.pi*(self.radius**2)
7    def perimeter(self):7    def perimeter(self):
n8        return math.pi*self.x*2n8        return 2*math.pi*self.radius
9if __name__=='__main__':9if __name__=='__main__':
10    x = int(input())10    x = int(input())
11    NewCircle = Circle(x)11    NewCircle = Circle(x)
12    print('{:.5f}'.format(NewCircle.area()))12    print('{:.5f}'.format(NewCircle.area()))
13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:13    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
n14  def __init__(self) -> None:n14    def __init__(self):
15      self.item_description='none'
16      self.item_name='none'15        self.item_name='none'
17      self.item_price=016        self.item_price=0
18      self.item_quantity=017        self.item_quantity=0
19  def print_item_description(self, ItemToPurchase):
20      return self.item_description18        self.item_description = 'none'
21  def print_item_cost(self):19    def print_item_cost(self):
22      totalPrice = self.item_price*self.item_quantity20        totalCost = self.item_price * self.item_quantity
23      outStr = '{} {} @ ${} = ${}'.format(self.item_name,self.item_quantity,self21        print('{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, sel
>.item_price,totalPrice)>f.item_price, totalCost))
24      return outStr22    def print_item_description(self):
23        print(f'{self.item_name}: {self.item_description}')
25class ShoppingCart:24class ShoppingCart:
n26  def __init__(self, customer_name='none', current_date='January 1, 2016'):n25    def __init__(self,customer_name='none', current_date="January 1, 2016", cart
 >_items=[]):
27      self.customer_name=customer_name26        self.customer_name = customer_name
28      self.current_date=current_date27        self.current_date = current_date
29      self.cart_items=[]28        self.cart_items = cart_items  
30  def add_item(self, Item):29    def add_item(self,item_name=ItemToPurchase()):
30        self.item_name = item_name
31      self.cart_items.append(Item)     31        self.cart_items.append(self.item_name)
32  def remove_item(self, item_name):32    def remove_item(self,item_name=ItemToPurchase()):
33        self.item_name = item_name
33      if item_name in self.cart_items:34        if self.item_name in self.cart_items:
34          self.cart_items.remove(item_name)35            self.cart_items.remove(self.item_name)
35      else:36        else:
37            return "Item not found in cart. Nothing removed."
38    def modify_item(self,item_quantity = ItemToPurchase(),item_name = ItemToPurc
 >hase(), new_item_quantity = ItemToPurchase()):
39        self.item_quantity = item_quantity
40        self.item_name = item_name
41        self.new_item_quantity = new_item_quantity
42        if self.item_name in self.cart_items:
43            self.item_quantity = self.new_item_quantity
44        else:
36          print('Item not found in cart. Nothing removed.')45            print('Item not found in cart. Nothing modified.')
37  def get_num_items_in_cart(self):46    def get_num_items_in_cart(self):
38      c=047        num_items = 0
39      for k in self.cart_items:48        for x in self.cart_items:
40          c=c+k.item_quantity49            num_items = num_items+x.item_quantity
41      return c50        return num_items
42  def get_cost_of_cart(self):51    def get_cost_of_cart(self):
43      cost=052        total = 0
53        item_cost = 0
44      for k in self.cart_items:54        for i in self.cart_items:
45          cost = cost + k.item_price*k.item_quantity55            item_cost = (i.item_quantity * i.item_price)
56            total+=item_cost
46      return cost57        return total
58    def print_total(self):
59        print(f'{self.customer_name}\'s Shopping Cart - {self.current_date}')
60        print(f'Number of Items: {self.get_num_items_in_cart}')
61        print()
62        for x in self.cart_items:
63            print(f'{x.item_name} {x.item_quantity} @ ${x.item_price} = ${x.item
 >_price*x.item_quantity}')
64        print()
65        print(f'Total: ${self.get_cost_of_cart}')
66    def print_descriptions(self):
67        print(f'{self.customer_name}\'s Shopping Cart - {self.current_date}')
68        print()
69        print('Item Descriptions')
70        for item in self.cart_items:
71            print(f'{item.print_item_descripton()}')
47def print_menu():72def print_menu():
n48     print('MENU')n73    print('MENU')
49     print('a - Add item to cart')74    print('a - Add item to cart')
50     print('r - Remove item from cart')75    print('r - Remove item from cart')
51     print('c - Change item quantity')76    print('c - Change item quantity')
52     print('i - Output items\' descriptions')77    print('i - Output items\' descriptions')
53     print('o - Output shopping cart')78    print('o - Output shopping cart')
54     print('q - Quit')79def execute_menu(self,character,shopping_cart):
55def execute_menu(userOption, my_cart):80    self.character = character
56  if userOption == 'o':81    self.shopping_cart = shopping_cart
82    if character == 'q':
83       quit
84    elif character == 'a':
85        shopping_cart.add_item()
86    elif character == 'r':
87        shopping_cart.remove_item()
88    elif character == 'c':
89        shopping_cart.modify_item()
90    elif character == 'i':
91        print('OUTPUT ITEMS\' DESCRIPTIONS')
92        shopping_cart.print_descriptions()
93    elif character == 'o':
57    print('OUTPUT SHOPPING CART')94        print('OUTPUT SHOPPING CART')
58    print('John Doe\'s Shopping Cart - February 1, 2016')95        shopping_cart.print_total()
96if __name__=="__main__":
97    customer = ShoppingCart()
98    print('Enter customer\'s name:')
99    customer.customer_name = 'John Doe'
100    print('Enter today\'s date:')
101    customer.current_date = 'February 1, 2016'
59    print()102    print()
n60    tt = 0n
61    for k in my_cart:
62        print('{} {} @ ${}) = $378'.format((k.item_name),(k.item_quantity),(k.it
>em_price),(k.item_price*k.item_quantity))) 
63        tt = tt + (k.item_price*k.item_quantity)
64    print('Total: ${})'.format(tt)) 
65  if userOption == 'i':   
66      print('OUTPUT ITEMS\' DESCRIPTIONS')  
67      print('{}\'s Shopping Cart - {}'.format((customer_name),(current_date)))
68      print()
69      print('Item Descriptions')
70      for k in my_cart:
71          print(ItemToPurchase.print_item_description()) 
72if __name__=="__main__":
73  print('Enter customer\'s name:')
74  cmm = input()
75  customer1 = ShoppingCart()
76  customer1.customer_name=cmm
77  print('Enter today\'s date:')
78  dd = input()
79  customer1.current_date=dd
80  print()
81  print('Customer name:',customer1.customer_name)103    print(f'Customer name: {customer.customer_name}')
82  print('Today\'s date:',customer1.current_date)104    print(f'Today\'s date: {customer.current_date}')
83  print()
84  print_menu()105    print_menu()
85  print()106    print()
86  print('Choose an option:')
87  opt1=input()
88  print('Choose an option:')
89  opt2=input()
90  print('Choose an option:')
91  opt3=input()  
92import numpy as np107import numpy as np
93class pt3d:108class pt3d:
t94   def __init__(self,x=0,y=0,z=0):t109    def __init__(self,x=0,y=0,z=0):
95       self.x=x110        self.x = x
96       self.y=y111        self.y = y
97       self.z=z112        self.z = z
98   def __str__(self):113    def __str__(self):
99       return '<{},{},{}>'.format((self.x),(self.y),(self.z))114        return (f'<{self.x},{self.y},{self.z}>')
100   def __add__(self, other):115    def __add__(self,other):
101       p3 = pt3d((self.x + other.x),( self.y + other.y),(self.z + other.z))116        sum_x = self.x + other.x
102       return p3 117        sum_y = self.y + other.y
118        sum_z = self.z + other.z
119        return (f'<{sum_x},{sum_y},{sum_z}>')
120    def __sub__(self,other):
121        a = np.array((self.x, self.y, self.z))
122        b = np.array((other.x, other.y, other.z))
123        return (np.sqrt(np.sum(np.square(a-b))))
103   def __e__(self, other):124    def __eq__(self,other):
104       if (self.x==other.x and self.y==other.y and self.z==other.z):125        if (self.x == other.x) and (self.y == other.y) and (self.z == other.z):
105           return True126            return True
127        else:
106       return False128            return False
107   def __sub__(self, other):129if __name__ == "__main__":
108       po_1 = np.array((self.x, self.y, self.z))130    p1=pt3d(1,1,1)
109       po_2 = np.array((other.x, other.y, other.z))131    print(p1)
110       instance = np.sqrt(np.sum(np.square(po_1 - po_2)))132    p2=pt3d(2,2,2)
111       return instance133    print(p1+p2)
134    print(p1-p2)
135    print(p1==p2)
136    print(p1+p1==p2)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 72

Student ID: 365, P-Value: 9.19e-01

Nearest Neighbor ID: 241

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2class Circle:2class Circle:
n3    def __init__(self,radius):n3    def __init__(self, radius):
4        self.radius=radius4        self.radius = radius
5    def area(self):5    def area(self):
n6        self.area= math.pi * (self.radius**2)n6        area = ((self.radius)**2)*(math.pi)
7        return self.area7        return area
8    def perimeter(self):8    def perimeter(self):
n9        self.perimeter= 2 *math.pi * self.radiusn9        perimeter = 2*(math.pi)*(self.radius)
10        return self.perimeter10        return perimeter
11if __name__=='__main__':11if __name__=='__main__':
12    x = int(input())12    x = int(input())
13    NewCircle = Circle(x)13    NewCircle = Circle(x)
14    print('{:.5f}'.format(NewCircle.area()))14    print('{:.5f}'.format(NewCircle.area()))
15    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:15    print('{:.5f}'.format(NewCircle.perimeter()))class ItemToPurchase:
16    def __init__(self):16    def __init__(self):
17        self.item_name='none'17        self.item_name='none'
18        self.item_price=018        self.item_price=0
19        self.item_quantity=019        self.item_quantity=0
n20        self.item_description="none"n20        self.item_description ='none'
21    def get_total(self):
22        self_total=self.item_price*self.item_quantity
23        return self_total
24    def get_discription(self):21    def print_item_description(self):
25        return self.item_description22        print('{}: {}.'.format(self.item_name, self.item_description))
23    def print_item_cost(self):
24        totalCost = self.item_quantity*self.item_price
25        print('{} {} @ ${} = ${}'.format(self.item_name, self.item_quantity, sel
 >f.item_price, totalCost))
26class ShoppingCart:26class ShoppingCart:
n27    def __init__(self, name="none",date="January 1, 2016"):n27    def __init__(self, customer_name='none', current_date="January 1, 2016", car
 >t_items = []):
28        self.name=name28        self.customer_name = customer_name
29        self.date=date29        self.current_date = current_date
30        self.cart_items=[]30        self.cart_items = cart_items
31    def add_items(self):31    def add_item(self, ItemToPurchase):
32        self.cart_items.appened(self)32        self.cart_items.append(ItemToPurchase)
33    def remove_items(string):33    def remove_item(self, Item_name):
34        Item_name = str(input())
34        if string in self.cart_items:35        for item in self.cart_items:
35            self.cart_items.remove(string)36            if Item_name != item.item_name:
36        else: 
37            print("Item not found in cart. Nothing removed.")37                print('Item not found in cart. Nothing removed.')
38            else:
39                self.cart_items.remove(item)
38    def modify_items(self,x):40    def modify_item(self, Item_name):
41        Item_name = str(input())
39        if self in self.cart_items:42        for item in self.cart_items:
40            self.item_quanity= x43            if item.item_name != Item_name:
44                print('Item not found in cart. Nothing modified.')
45            else:
46                new_quantity = int(input())
47                item.item_quantity = new_quantity
48    def get_num_items_in_cart(self):
49        num_items = 0
50        for item in self.cart_items:
51            num_items += item.item_quantity
52        return num_items
53    def get_cost_of_cart(self):
54        total_cost = 0
55        for item in self.cart_items:
56            total_cost += (item.item_quantity * item.item_price)
57        return total_cost
58def print_menu():
59    print("MENU")
60    print("a - Add item to cart")
61    print("r - Remove item from cart")
62    print("c - Change item quantity")
63    print("i - Output items' descriptions")
64    print("o - Output shopping cart")
65    print("q - Quit\n")
66if __name__ == "__main__":
67    customer_name = str(input("Enter customer's name:\n"))
68    current_date = input("Enter today's date:\n")
69    print()
70    print("Customer name: {}".format(customer_name))
71    print("Today's date: {}".format(current_date))
72    print_menu()import math 
73class pt3d:
74    def __init__(self, x=0, y=0, z=0):
75        self.x = x
76        self.y = y
77        self.z = z
78    def __add__(self, other):
79        ab_x = self.x + other.x
80        ab_y = self.y + other.y
81        ab_z = self.z + other.z
82        return pt3d(ab_x, ab_y, ab_z)
83    def __sub__(self, other):
84        equation = (self.x-other.x)**2 + (self.y-other.y)**2 + (self.z - other.z
 >)**2
85        euclidean_distance = math.sqrt(equation)
86        return euclidean_distance
87    def __eq__(self, other):
88        if (self.x != other.x) or (self.y != other.y) or (self.z != other.z):
89            return False
41        else:90        else:
n42            print('Item not found in cart. Nothing modified.')n
43    def get_num_items_in_cart():
44        return len(self.cart_items)
45    def get_cost_of_cart():
46        t=0
47        for n in self.cart_items:
48            t+=get_total(n)
49        return 91            return True
50    def print_total(self):
51        print(get_num_items_in_cart(self))
52    def print_descriptions():
53        for n in self.cart_items:
54            print(get_description(n))
55def print_menu():
56    print('MENU')
57    print("a - Add item to cart")
58    print('r - Remove item from cart')
59    print('c - Change item quantity')
60    print('i - Output items\' descriptions')
61    print('o - Output shopping cart')
62    print('q - Quit')
63    return print()
64def execute_menu(x,y):
65    if x=="q":
66        print()
67    while x!="q":
68        if x=="a":
69            add_items(y)
70        elif x=='r':
71            remove_items(y)
72        elif x=='c':
73            modify_items(y)
74        elif x=='i':
75            print-discriptions(y)
76        elif x=='o':
77            print(y.cart_list)
78        else:    
79            print("Choose an option:")
80            break
81if __name__ == "__main__":
82    print('Enter customer\'s name:')
83    name=input()
84    print("Enter today\'s date:")
85    date=input()
86    print()
87    print("Customer name:", name)
88    print("Today's date:" , date)
89    print()
90    print(print_menu())
91    print()
92    print("Choose an option:")
93    choice=input('hello')
94    execute_menu(choice,name)class pt3d:
95    def __init__(self, x=0, y=0, z=0): 
96        self.x= x
97        self.y= y
98        self.z= z
99    def __add__(self,other_number):
100        return pt3d(self.x+other_number.x,self.y+other_number.y,self.z+other_num
>ber.z) 
101    def __sub__(self,other_number):
102        return ((((other_number.x - self.x)**2) + ((other_number.y-self.y)** 2)+
>((other_number.z-self.z)**2))**0.5)  
103    def __eq__(self, other_number):
104        return(self.x == other_number.x)
105        return(self.y == other_number.y)
106        return(self.z == other_number.z)
107    def __str__(self):92    def __str__(self):
t108        return (f'<{self.x},{self.y},{self.z}>')t93        return('<{},{},{}>'.format(self.x, self.y, self.z))
109if __name__ == '__main__':
110    p1 = pt3d(1, 1, 1)
111    p2 = pt3d(2, 2, 2)
112    print(p1+p2)
113    print(p1-p2)
114    print(p1==p2)
115    print(p1+p1==p2)
116    print(p1==p2+pt3d(-1,-1,-1))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op