Skip to content

Commit bf1f3c3

Browse files
committed
add
1 parent 4f822bd commit bf1f3c3

File tree

2 files changed

+45
-45
lines changed

2 files changed

+45
-45
lines changed

Code/oop.ipynb

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,17 +1086,17 @@
10861086
},
10871087
{
10881088
"cell_type": "code",
1089-
"execution_count": 33,
1089+
"execution_count": 91,
10901090
"metadata": {},
10911091
"outputs": [
10921092
{
10931093
"name": "stdout",
10941094
"output_type": "stream",
10951095
"text": [
10961096
"Jane Doe works at TechCorp\n",
1097-
"Jane Doe studies at State University\n",
1098-
"Jane Doe studies at Advanced Studies at State University\n",
1099-
"Jane Doe has specialization in Software Engineering and engages in advanced studies at Advanced Studies at State University\n",
1097+
"\u001b[35mJane Doe studies at State University\n",
1098+
"\u001b[35mJane Doe studies at Advanced Studies at State University\n",
1099+
"\u001b[36mJane Doe has specialization in Software Engineering and engages in advanced studies at Advanced Studies at State University\n",
11001100
"\u001b[32m======================================================= Dict ======================================================\n",
11011101
"obj.__dict__ = {'name': 'Jane Doe', 'company': 'TechCorp', 'school': 'Advanced Studies at State University', 'specialization': 'Software Engineering'}\n",
11021102
"\u001b[34m============================================= Method resolution order =============================================\n",
@@ -1129,7 +1129,7 @@
11291129
" def __init__(self, name: str, school: str):\n",
11301130
" self.name = name\n",
11311131
" self.school = school\n",
1132-
" print(f\"{self.name} studies at {self.school}\")\n",
1132+
" print(Fore.MAGENTA + f\"{self.name} studies at {self.school}\")\n",
11331133
" \n",
11341134
"class WorkingStudent(Employee, Student): # Class C\n",
11351135
" \"\"\"\n",
@@ -1150,7 +1150,7 @@
11501150
" # Call to the Student init is adjusted here to differentiate tasks or advanced level of study\n",
11511151
" Student.__init__(self, name, \"Advanced Studies at \" + school)\n",
11521152
" self.specialization = specialization\n",
1153-
" print(f\"{self.name} has specialization in {self.specialization} and engages in advanced studies at {self.school}\")\n",
1153+
" print(Fore.CYAN + f\"{self.name} has specialization in {self.specialization} and engages in advanced studies at {self.school}\")\n",
11541154
"\n",
11551155
"# Create an instance of SpecialWorkingStudent\n",
11561156
"obj = SpecialWorkingStudent(name=\"Jane Doe\", company=\"TechCorp\", school=\"State University\", specialization=\"Software Engineering\")\n",
@@ -2815,28 +2815,28 @@
28152815
},
28162816
{
28172817
"cell_type": "code",
2818-
"execution_count": null,
2818+
"execution_count": 87,
28192819
"metadata": {},
28202820
"outputs": [
28212821
{
28222822
"name": "stdout",
28232823
"output_type": "stream",
28242824
"text": [
2825-
"Setting attribute name to Alice\n",
2826-
"Setting attribute value to 42\n",
2827-
"Setting attribute data to {}\n",
2825+
"\u001b[36mSetting attribute name to Alice\n",
2826+
"\u001b[36mSetting attribute value to 42\n",
2827+
"\u001b[36mSetting attribute data to {}\n",
28282828
"Alice has value 42\n",
2829-
"Example(name='Alice', value=42)\n",
2830-
"Setting attribute name to Bob\n",
2831-
"Setting attribute value to 30\n",
2832-
"Setting attribute data to {}\n",
2829+
"\u001b[32mExample(name='Alice', value=42)\n",
2830+
"\u001b[36mSetting attribute name to Bob\n",
2831+
"\u001b[36mSetting attribute value to 30\n",
2832+
"\u001b[36mSetting attribute data to {}\n",
28332833
"False\n",
28342834
"True\n",
28352835
"value1\n",
28362836
"This is a special value!\n",
2837-
"Attribute 'missing_attr' not found!\n",
2838-
"Setting attribute name to Charlie\n",
2839-
"Deleting attribute name\n"
2837+
"\u001b[35mAttribute 'missing_attr' not found!\n",
2838+
"\u001b[36mSetting attribute name to Charlie\n",
2839+
"\u001b[33mDeleting attribute name\n"
28402840
]
28412841
}
28422842
],
@@ -2851,11 +2851,11 @@
28512851
"\n",
28522852
" def __str__(self):\n",
28532853
" # __str__ provides a human-readable string\n",
2854-
" return Fore.GREEN + f\"{self.name} has value {self.value}\"\n",
2854+
" return f\"{self.name} has value {self.value}\"\n",
28552855
"\n",
28562856
" def __repr__(self):\n",
28572857
" # __repr__ provides a debug-friendly string\n",
2858-
" return f\"Example(name={self.name!r}, value={self.value!r})\"\n",
2858+
" return Fore.GREEN + f\"Example(name={self.name!r}, value={self.value!r})\"\n",
28592859
"\n",
28602860
" def __eq__(self, other):\n",
28612861
" # __eq__ compares instances for equality\n",
@@ -2879,7 +2879,7 @@
28792879
"\n",
28802880
" def __getattr__(self, attr):\n",
28812881
" # __getattr__ handles missing attributes\n",
2882-
" return f\"Attribute '{attr}' not found!\"\n",
2882+
" return Fore.MAGENTA + f\"Attribute '{attr}' not found!\"\n",
28832883
"\n",
28842884
" def __getattribute__(self, attr):\n",
28852885
" # __getattribute__ handles all attribute access\n",
@@ -2889,12 +2889,12 @@
28892889
"\n",
28902890
" def __setattr__(self, attr, value):\n",
28912891
" # __setattr__ allows custom logic when setting attributes\n",
2892-
" print(f\"Setting attribute {attr} to {value}\")\n",
2892+
" print(Fore.CYAN + f\"Setting attribute {attr} to {value}\")\n",
28932893
" super().__setattr__(attr, value)\n",
28942894
"\n",
28952895
" def __delattr__(self, attr):\n",
28962896
" # __delattr__ allows custom logic when deleting attributes\n",
2897-
" print(f\"Deleting attribute {attr}\")\n",
2897+
" print(Fore.YELLOW + f\"Deleting attribute {attr}\")\n",
28982898
" super().__delattr__(attr)\n",
28992899
"\n",
29002900
"\n",
@@ -2958,23 +2958,23 @@
29582958
},
29592959
{
29602960
"cell_type": "code",
2961-
"execution_count": 162,
2961+
"execution_count": 89,
29622962
"metadata": {},
29632963
"outputs": [
29642964
{
29652965
"name": "stdout",
29662966
"output_type": "stream",
29672967
"text": [
29682968
"aa welcome!\n",
2969-
"aa has purchased the course: matlab\n",
2969+
"\u001b[32maa has purchased the course: matlab\n",
29702970
"rr welcome!\n",
2971-
"rr has purchased the course: python\n",
2971+
"\u001b[32mrr has purchased the course: python\n",
29722972
"['aa', 'rr']\n",
29732973
"{'aa': 'matlab', 'rr': 'python'}\n",
2974-
"f must register.\n",
2974+
"\u001b[36mf must register.\n",
29752975
"f welcome!\n",
2976-
"f has an account.\n",
2977-
"['aa', 'rr', 'f']\n"
2976+
"\u001b[36mf has an account.\n",
2977+
"\u001b[35mStudent.users = ['aa', 'rr', 'f']\n"
29782978
]
29792979
}
29802980
],
@@ -3009,13 +3009,13 @@
30093009
"\n",
30103010
" def login(self, name):\n",
30113011
" if name in Student.users:\n",
3012-
" print(f\"{name} has an account.\")\n",
3012+
" print(Fore.CYAN + f\"{name} has an account.\")\n",
30133013
" else:\n",
3014-
" print(f\"{name} must register.\")\n",
3014+
" print(Fore.CYAN + f\"{name} must register.\")\n",
30153015
"\n",
30163016
" def buy(self, coursename):\n",
30173017
" Student.users_course[self.name] = coursename\n",
3018-
" print(f\"{self.name} has purchased the course: {coursename}\")\n",
3018+
" print(Fore.GREEN + f\"{self.name} has purchased the course: {coursename}\")\n",
30193019
"\n",
30203020
"\n",
30213021
"# Create objects of the class\n",
@@ -3033,7 +3033,7 @@
30333033
"student_f = Student(\"f\", \"f@.com\", \"5478\", True)\n",
30343034
"student_f.login(\"f\") # Now attempts to log in \"f\" again\n",
30353035
"\n",
3036-
"print(Student.users) # Prints the updated list of user names"
3036+
"print(Fore.MAGENTA + f\"{Student.users = }\") # Prints the updated list of user names"
30373037
]
30383038
},
30393039
{
@@ -3181,16 +3181,16 @@
31813181
},
31823182
{
31833183
"cell_type": "code",
3184-
"execution_count": null,
3184+
"execution_count": 82,
31853185
"metadata": {},
31863186
"outputs": [
31873187
{
31883188
"name": "stdout",
31893189
"output_type": "stream",
31903190
"text": [
31913191
"Function 'add' is about to run with arguments (5, 10) {}.\n",
3192-
"Function 'add' has finished running.\n",
3193-
"15\n"
3192+
"\u001b[32mFunction 'add' has finished running.\n",
3193+
"\u001b[36madd(5, 10) =15\n"
31943194
]
31953195
}
31963196
],
@@ -3208,7 +3208,7 @@
32083208
" def wrapper(*args, **kwargs):\n",
32093209
" print(f\"Function '{func.__name__}' is about to run with arguments {args} {kwargs}.\")\n",
32103210
" result = func(*args, **kwargs)\n",
3211-
" print(f\"Function '{func.__name__}' has finished running.\")\n",
3211+
" print(Fore.GREEN + f\"Function '{func.__name__}' has finished running.\")\n",
32123212
" return result\n",
32133213
" return wrapper\n",
32143214
"\n",
@@ -3217,7 +3217,7 @@
32173217
" return a + b\n",
32183218
"\n",
32193219
"# Call the function\n",
3220-
"print(add(5, 10))"
3220+
"print(Fore.CYAN + f\"{add(5, 10) =}\")"
32213221
]
32223222
},
32233223
{
@@ -3230,29 +3230,29 @@
32303230
},
32313231
{
32323232
"cell_type": "code",
3233-
"execution_count": 6,
3233+
"execution_count": 88,
32343234
"metadata": {},
32353235
"outputs": [
32363236
{
32373237
"name": "stdout",
32383238
"output_type": "stream",
32393239
"text": [
3240-
"Car has Wi-Fi.\n",
3241-
"Airplane has Wi-Fi.\n",
3242-
"Airplane has music.\n",
3243-
"======================================================= Dict ======================================================\n",
3240+
"\u001b[32mCar has Wi-Fi.\n",
3241+
"\u001b[32mAirplane has Wi-Fi.\n",
3242+
"\u001b[36mAirplane has music.\n",
3243+
"\u001b[35m======================================================= Dict ======================================================\n",
32443244
"obj.__dict__ = {}\n"
32453245
]
32463246
}
32473247
],
32483248
"source": [
32493249
"class WifiMixin:\n",
32503250
" def Wifi(self):\n",
3251-
" print(f\"{self.__class__.__name__} has Wi-Fi.\")\n",
3251+
" print(Fore.GREEN + f\"{self.__class__.__name__} has Wi-Fi.\")\n",
32523252
"\n",
32533253
"class MusicMixin:\n",
32543254
" def music(self):\n",
3255-
" print(f\"{self.__class__.__name__} has music.\")\n",
3255+
" print(Fore.CYAN + f\"{self.__class__.__name__} has music.\")\n",
32563256
"\n",
32573257
"class Vehicle:\n",
32583258
" def mov(self):\n",
@@ -3274,7 +3274,7 @@
32743274
"obj.Wifi()\n",
32753275
"obj.music()\n",
32763276
"\n",
3277-
"print(f\"{55 * \"=\"} Dict {54 * \"=\"}\\n{obj.__dict__ = }\")"
3277+
"print(Fore.MAGENTA + f\"{55 * \"=\"} Dict {54 * \"=\"}\\n{obj.__dict__ = }\")"
32783278
]
32793279
}
32803280
],

Image/Image.eddx

-265 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)