diff --git a/.gitignore b/.gitignore index 075b254..dfec022 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /.quarto/ +users.txt \ No newline at end of file diff --git a/_site/module-1/slides/3-python-basics.html b/_site/module-1/slides/3-python-basics.html index 555d6e3..08afe63 100644 --- a/_site/module-1/slides/3-python-basics.html +++ b/_site/module-1/slides/3-python-basics.html @@ -579,6 +579,19 @@
indentation.py
if drug_prescribed == True:
- if drug_given == True:
- record_drug_given = True
- print("Drug has been prescribed and given to the patient")
- else:
- print("Drug has been prescribed but not given")
-else:
- print("Drug has not been prescribed")
-
-print("Drug round complete!")
if drug_prescribed == True:
+ if drug_given == True:
+ record_drug_given = True
+ print("Drug has been prescribed and given to the patient")
+ else:
+ print("Drug has been prescribed but not given")
+else:
+ print("Drug has not been prescribed")
+
+print("Drug round complete!")
Output (if drug has been prescribed and given)
Drug has been prescribed and given to the patient
@@ -612,16 +625,16 @@ Indentation
indentation.py
-if drug_prescribed == True:
- if drug_given == True:
- record_drug_given = True
- print("Drug has been prescribed and given to the patient")
- else:
- print("Drug has been prescribed but not given")
-else:
- print("Drug has not been prescribed")
-
- print("Drug round complete!")
+if drug_prescribed == True:
+ if drug_given == True:
+ record_drug_given = True
+ print("Drug has been prescribed and given to the patient")
+ else:
+ print("Drug has been prescribed but not given")
+else:
+ print("Drug has not been prescribed")
+
+ print("Drug round complete!")
Output (if drug has been prescribed and given)
Drug has been prescribed and given to the patient
@@ -667,20 +680,47 @@ Comments
comments.py
-# This is a single line comment
-a_string = "a string"
-
-""" Double quotation mark multiline comment
- Here is some more of the comment
-"""
-def i_am_a_function():
- return True
-
-''' Single quotation mark multiline comment
- Here is some more of the comment
-'''
-def i_am_another_function():
- return True
+# This is a single line comment
+a_string = "a string"
+
+""" Double quotation mark multiline comment
+ Here is some more of the comment
+"""
+def i_am_a_function():
+ return True
+
+''' Single quotation mark multiline comment
+ Here is some more of the comment
+'''
+def i_am_another_function():
+ return True
+
+
if_statement.py
patient_allergy = "amoxicillin"
-
-if patient_allergy == "amoxicillin":
- allergy_group = "penicillins"
-elif patient_allergy == "tazocin":
- allergy_group = "penicillins"
-else:
- allergy_group = "others"
-
-print("Patient is allergic to", allergy_group)
patient_allergy = "amoxicillin"
+
+if patient_allergy == "amoxicillin":
+ allergy_group = "penicillins"
+elif patient_allergy == "tazocin":
+ allergy_group = "penicillins"
+else:
+ allergy_group = "others"
+
+print("Patient is allergic to", allergy_group)
Output
Patient is allergic to penicillins
@@ -737,10 +777,10 @@ for_loop.py
Output
1
@@ -755,11 +795,11 @@ Control flow - while loops
while_loop.py
-
+
Output
1
@@ -783,13 +823,13 @@ Functions (methods)
functions.py
-
+
functions.py
try:
- variable = 1 + "a"
-except:
- print("I knew that you could not add an integer and a string!")
-else:
- print("Somehow I did not get an error!")
try:
+ variable = 1 + "a"
+except:
+ print("I knew that you could not add an integer and a string!")
+else:
+ print("Somehow I did not get an error!")
Output
I knew that you could not add an integer and a string!
@@ -872,20 +912,20 @@ functions.py
class FruitPrices:
- def __init__(self):
- self.prices = {"apple": 1.55, "banana": 2.44}
-
- def get_price(self, fruit):
- return self._price(fruit)
-
- def _price(self, fruit):
- return self.prices[fruit]
-
-
-fruit_prices = FruitPrices()
-
-print(fruit_prices.get_price("pear")) # 'pear' key does not exist!
class FruitPrices:
+ def __init__(self):
+ self.prices = {"apple": 1.55, "banana": 2.44}
+
+ def get_price(self, fruit):
+ return self._price(fruit)
+
+ def _price(self, fruit):
+ return self.prices[fruit]
+
+
+fruit_prices = FruitPrices()
+
+print(fruit_prices.get_price("pear")) # 'pear' key does not exist!
Comments
++- You will also come across something called docstrings. These are basically comments associated with functions / methods and classes.
+- You will see them associated with modules (at the top of files).
+
+