Module 1
yes-no questions.thinking takes place.yes-no questions are undertaken.binary form.1s and 0s (eg 01001011).digital.True (1) or False (0) answer (aka yes-no answer). The output (aka answer) is also in binary.1s and 0s which the computer can then read and act upon.Syntax error:
Cell In[1], line 2
variable b = "The added space will cause an error"
^
SyntaxError: invalid syntax
quotation_marks.py
variable_c is part of the string for variable_b and also an error!Output
The patient's age is : 25
Output
The patient's age is : 25
tabs) of lines of code shows the computer which previous line(s) of code it relates to.indentation.py
Output (if drug has been prescribed and given)
Drug has been prescribed and given to the patient
Drug round complete!
indentation.py
Output (if drug has been prescribed and given)
Drug has been prescribed and given to the patient
snake_caseCONSTANT_CASECamelCasesnake_caselowercasepackagenamesdocstrings. These are basically comments associated with functions / methods and classes.+ - * /== > < >= <=and or not= += -= *=& | ^ << >> ~in not inis is notif_statement.py
Output
Patient is allergic to penicillins
Output
1
2
3
4
5
Output
1
2
3
4
5
DRY (don't repeat yourself) philosophy.method is just a function, used within a class (a higher organisational entity in python).defOutput
hello world
5
debugging.Debugging is the practice of looking for bugs (errors in the code) and trying to fix them.exception is raised. You then use the traceback to try and find the cause of the error.functions.py
Output
I knew that you could not add an integer and a string!
Traceback (most recent call last):
File "/User/a_user/code/error_in_code.py", line 28, in <module>
print(fruit_prices.get_price("pear"))
File "/User/a_user/code/error_in_code.py", line 21, in get_price
return self._price(fruit)
File "/User/a_user/code/error_in_code.py", line 24, in _price
return self.prices[fruit]
KeyError: 'pear'
Traceback (most recent call last):
File "/User/a_user/code/error_in_code.py", line 28, in <module>
print(fruit_prices.get_price("pear"))
File "/User/a_user/code/error_in_code.py", line 21, in get_price
return self._price(fruit)
File "/User/a_user/code/error_in_code.py", line 24, in _price
return self.prices[fruit]
==> KeyError: 'pear' <==
Lesson 2.True and False, e.g. 1 and 0s. They are literal thinkers.unpaired quotation mark, look out for that space that should not be there, and make sure you match your indentations to your if statements.
Comments