From 51079bfabdc787c1823a809bc63b206acfd9ecc1 Mon Sep 17 00:00:00 2001 From: Divy Date: Wed, 25 Oct 2023 15:24:07 +0800 Subject: [PATCH] Fixed some styling and added a note to inheritance.md --- .idea/.gitignore | 8 + .idea/IntroToPython.iml | 11 ++ .idea/inspectionProfiles/Project_Default.xml | 44 +++++ .../inspectionProfiles/profiles_settings.xml | 6 + .idea/misc.xml | 4 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + docs/inheritance.md | 135 ++++++++++----- docs/style.css | 154 +++++++++++------- docs/vars.md | 2 +- mkdocs.yml | 5 +- 11 files changed, 281 insertions(+), 102 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/IntroToPython.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/IntroToPython.iml b/.idea/IntroToPython.iml new file mode 100644 index 0000000..816c63c --- /dev/null +++ b/.idea/IntroToPython.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..7ea6be9 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,44 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..8c9bbab --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..4625abc --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/docs/inheritance.md b/docs/inheritance.md index 1128339..7970cf5 100644 --- a/docs/inheritance.md +++ b/docs/inheritance.md @@ -96,8 +96,19 @@ class Student2: print() # when there are a lot of function parameters, it is nice to specify which parameters correspond to what -# values for better readability and clarity -B = Student2(name = "Robert", age = 14, sex = "male", height = 160, weight = 65, school = "SUTD", id_no = 1025, seat_no = 12, year = 1, section = "A") +# values for better readability and clarity and put them each on their own line +B = Student2( + name = "Robert", + age = 14, + sex = "male", + height = 160, + weight = 65, + school = "SUTD", + id_no = 1025, + seat_no = 12, + year = 1, + section = "A", +) print(B.name+"'s age: "+str(B.age)) B.display_information() ``` @@ -109,7 +120,7 @@ Also, to access a student's name and age, you have to do `A.person.name` and `A. The 2nd approach fixes this issue but it is also a bit tedious because you have to manually declare all properties of a person inside the student constructor... What if there were not 5, but 100 different properties associated with a person? It would be too unfeasable to manually rewrite them. -This is where inheritance comes into the picture. Inheritance literally allows us to "inherit" the properties of one class (called the super class) into another class (called the sub class) +This is where inheritance comes into the picture. Inheritance literally allows us to "inherit" the properties of one class (called the super or base class) into another class (called the sub or child class) ```py @@ -132,7 +143,7 @@ class Person: # Base/Sub class class Student(Person): def __init__(self, name, age, sex, height, weight, school, id_no, seat_no, year, section): - Person.__init__(self, name, age, sex, height, weight) + Person.__init__(self, name, age, sex, height, weight) # we can re-use functionality from the super class! self.school = school self.id_no = id_no self.seat_no = seat_no @@ -140,7 +151,7 @@ class Student(Person): self.section = section def display_information(self): - Person.display_information(self) + Person.display_information(self) # we can re-use functionality from the super class! print("School : " + self.school) print("ID : " + str(self.id_no)) print("Seat : " + str(self.seat_no)) @@ -148,12 +159,40 @@ class Student(Person): print("Section : " + self.section) # when there are a lot of function parameters, it is nice to specify which parameters correspond to what -# values for better readability and clarity -A = Student(name = "Robin", age = 16, sex = "male", height = 180, weight = 75, school = "SUTD", id_no = 1023, seat_no = 3, year = 3, section = "A") +# values for better readability and clarity and put them each on their own line +A = Student( + name = "Robin", + age = 16, + sex = "male", + height = 180, + weight = 75, + school = "SUTD", + id_no = 1023, + seat_no = 3, + year = 3, + section = "A", +) print(A.name+"'s age: "+str(A.age)) A.display_information() ``` +!!! note "Best practice" + The following usages of super class methods in the above example: + ```py + Person.__init__(self, name, age, sex, height, weight) + + Person.display_information(self) + ``` + Are for educational purposes only, in real python programs, we should make use of the following syntax instead: + + ```py + # notice that the self parameter has been omitted + super().__init__(name, age, sex, height, weight) + + super().display_information() + ``` + The reason for doing so is that `super()` in python does the work of figuring out which super class's function to call and if you end up changing the superclass, you don't have to change all your code everywhere (Also there can be multiple super classes, but that's a story for another day) + === "Practise" Given a class computer, Write a subclass laptop and desktop with the given additional properties: @@ -183,12 +222,14 @@ A.display_information() ```py class Computer: - def __init__(self, - cpu: str, - storage_type: str, - storage: float, - ram: float, - gpu: str): + def __init__( + self, + cpu: str, + storage_type: str, + storage: float, + ram: float, + gpu: str, + ): # type hints can also be given to a class' data members self.cpu: str = cpu @@ -234,12 +275,14 @@ A.display_information() ```py class Computer: - def __init__(self, - cpu: str, - storage_type: str, - storage: float, - ram: float, - gpu: str): + def __init__( + self, + cpu: str, + storage_type: str, + storage: float, + ram: float, + gpu: str, + ): # type hints can also be given to a class' data members self.cpu: str = cpu @@ -260,12 +303,14 @@ A.display_information() ```py class Computer: - def __init__(self, - cpu: str, - storage_type: str, - storage: float, - ram: float, - gpu: str): + def __init__( + self, + cpu: str, + storage_type: str, + storage: float, + ram: float, + gpu: str, + ): # type hints can also be given to a class' data members self.cpu: str = cpu @@ -282,14 +327,16 @@ A.display_information() print("The GPU is : "+self.gpu) class Laptop(Computer): - def __init__(self, - cpu: str, - storage_type: str, - storage: float, - ram: float, - gpu: str, - resolution: str, - is_touchscreen: bool): + def __init__( + self, + cpu: str, + storage_type: str, + storage: float, + ram: float, + gpu: str, + resolution: str, + is_touchscreen: bool, + ): Computer.__init__(self, cpu, storage_type, storage, ram, gpu) self.resolution = resolution self.is_touchscreen = is_touchscreen @@ -300,16 +347,18 @@ A.display_information() print("Is it a touchscreen : "+str(self.is_touchscreen)) class Desktop(Computer): - def __init__(self, - cpu: str, - storage_type: str, - storage: float, - ram: float, - gpu: str, - monitor: str, - resolution: str, - keyboard: str, - mouse: str): + def __init__( + self, + cpu: str, + storage_type: str, + storage: float, + ram: float, + gpu: str, + monitor: str, + resolution: str, + keyboard: str, + mouse: str, + ): Computer.__init__(self, cpu, storage_type, storage, ram, gpu) self.monitor = monitor self.resolution = resolution diff --git a/docs/style.css b/docs/style.css index 537cbf2..031e071 100644 --- a/docs/style.css +++ b/docs/style.css @@ -1,85 +1,127 @@ -h1 { - color: #f54242 !important; - font-family: Centaur !important; +.md-header { + box-shadow: 0px 0px 15px -5px #000000 !important; } -h2 { - color: #ed324e !important; + +.md-tabs { + background-color: #bc4240 !important; + box-shadow: 0px 0px 15px -5px #000000 !important; +} + +/* .hideTOC .md-nav { + display: none !important; +} */ + +h2 { + color: #BABABA !important; } -h3, h4 { - color: #ec455e !important; +h3, h4 { + color: #c0c0c0 !important; } -/* header { - background: url("imgs/test.png") center no-repeat fixed; - background-size: cover; - background-color: burlywood; - color: #000000; +body { + background-color: #222222 !important; } -nav { - background: url("imgs/test.png") center no-repeat fixed; - background-size: cover; - background-color: burlywood; - color: #000000 !important; -} */ -body { - font-weight: 200; - /* background: url("imgs/test.jpg"); - background-size: cover; - background-color: burlywood; - color: #000000; */ +.highlighttable .linenos { + background-color: #111111 !important; } -tr:nth-child(even) { - background-color: #3a3c4e !important; +.md-typeset code { + background-color: #111111 !important; } -tr th { - background-color:#ef5552 !important; - color: #000000 +.md-footer { + background-color: #111111; + z-index: 100; } -tr:hover { - background-color: #45495f !important; + +.md-footer-meta { + background-color: #000000; } +/* width */ +::-webkit-scrollbar { + width: 5px !important; +} -/* this code is used for different table styles in different tabs*/ +/*Track */ +::-webkit-scrollbar-track { + background-color: transparent !important; +} -/* #cs1 + div .tabbed-content:nth-of-type(1) table tr:nth-child(2), -#cs1 + div .tabbed-content:nth-of-type(1) table tr:nth-child(4) { - background-color: #535571 !important; +/* Handle */ +::-webkit-scrollbar-thumb { + background: #5b5c67 !important; } -#cs1 + div .tabbed-content:nth-of-type(1) table tr:nth-child(3):not(:first-child) { - background-color: #4a4c64 !important; + +/* Handle on hover */ +::-webkit-scrollbar-thumb:hover { + background: #ff1947 !important; +} + +.admonition.abstract, +.admonition.bug, +.admonition.danger, +.admonition.example, +.admonition.failure, +.admonition.info, +.admonition.note, +.admonition.success, +.admonition.tip, +.admonition.question, +.admonition.quote, +.admonition.warning { + box-shadow: 3px 3px 5px 0px #111111; } -#cs1 + div .tabbed-content:nth-of-type(1) table tr:hover:nth-child(2), -#cs1 + div .tabbed-content:nth-of-type(1) table tr:hover:nth-child(3), -#cs1 + div .tabbed-content:nth-of-type(1) table tr:hover:nth-child(4) { - background-color: #646986 !important; -} */ +tr td, table { + border-width: 0 !important; +} -/* formatting for damage calculation table under topic 3.3. */ +tr th { + background-color:#ef5552 !important; + color: #000000; +} -#cs1 + div table tr:nth-child(2), -#cs1 + div table tr:nth-child(4) { - background-color: #535571 !important; +tr:nth-child(even) { + background-color: #2b2b2b !important; } -#cs1 + div table tr:nth-child(3) { - background-color: #4a4c64 !important; + +tr:nth-child(odd) { + background-color: #1E2021 !important; } -#cs1 + div table tr:hover:nth-child(2), -#cs1 + div table tr:hover:nth-child(3), -#cs1 + div table tr:hover:nth-child(4) { - background-color: #646986 !important; + +tr:hover { + background-color: #63696E !important; +} + + +table { + box-shadow: 3px 3px 5px 0px #111111; } +/* formatting for damage calculation table under topic 3.3. */ +#cs1 + div table { + border-collapse: collapse !important; + overflow-x: hidden !important; + border-spacing: 0 !important; + } + #cs1 + div table tr:nth-child(2), + #cs1 + div table tr:nth-child(3), + #cs1 + div table tr:nth-child(4) { + border: 2px #ef5552 solid !important; + background-clip: padding-box !important; + } + /* formatting for damage calculation table under topic 3.4. */ +#cs2 + div table { + border-collapse: collapse !important; + overflow-x: hidden !important; + border-spacing: 0 !important; + } #cs2 + div table tr:nth-child(3) { - background-color: #535571 !important; -} -#cs2 + div table tr:hover:nth-child(3) { - background-color: #646986 !important; + border: 2px #ef5552 solid !important; + background-clip: padding-box !important; } .arithmatex { diff --git a/docs/vars.md b/docs/vars.md index c74dfdb..5759ebf 100644 --- a/docs/vars.md +++ b/docs/vars.md @@ -43,7 +43,7 @@ print(ls) ## 3. Data Types -Remember, variables are like boxes/containers that are used to store constants. For every different kind of constant, a different type of contanier/box is required! Think about it this way, you cannot store water in a paper bag. you need a water bottle to store water. Similarly, in python, each different kind of constant must be stored in a different type of variable. The tyoe of the variable is known as its data type. So how many kinds of boxes, or data types are there? The following are the most commonly used data types in python: +Remember, variables are like boxes/containers that are used to store constants. For every different kind of constant, a different type of contanier/box is required! Think about it this way, you cannot store water in a paper bag. you need a water bottle to store water. Similarly, in python, each different kind of constant must be stored in a different type of variable. The type of the variable is known as its data type. So how many kinds of boxes, or data types are there? The following are the most commonly used data types in python: ### 3.1. Integer (`#!py int` ) diff --git a/mkdocs.yml b/mkdocs.yml index 4bda982..f6d7b96 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -24,7 +24,9 @@ markdown_extensions: - pymdownx.mark # highlighting of text - pymdownx.tilde # strikethrough of text - pymdownx.keys # https://squidfunk.github.io/mkdocs-material/reference/code-blocks/#keys - - pymdownx.tabbed # https://squidfunk.github.io/mkdocs-material/reference/content-tabs/#tabbed + - pymdownx.superfences # https://squidfunk.github.io/mkdocs-material/reference/code-blocks/#superfences + - pymdownx.tabbed: # https://squidfunk.github.io/mkdocs-material/reference/content-tabs/#tabbed + alternate_style: true - pymdownx.details # https://squidfunk.github.io/mkdocs-material/reference/admonitions/#details - pymdownx.highlight: # https://squidfunk.github.io/mkdocs-material/reference/code-blocks/#code-blocks linenums: true @@ -32,7 +34,6 @@ markdown_extensions: emoji_index: !!python/name:materialx.emoji.twemoji emoji_generator: !!python/name:materialx.emoji.to_svg - pymdownx.inlinehilite - - pymdownx.superfences # https://squidfunk.github.io/mkdocs-material/reference/code-blocks/#superfences - pymdownx.smartsymbols # supporting special characters like copyright symbol (c) - pymdownx.arithmatex: # https://squidfunk.github.io/mkdocs-material/reference/mathjax/#arithmatex generic: true