Module 0
true-false questions
.thinking
takes place.true-false questions
are undertaken.binary
form.1
s and 0
s (eg 01001011).1
can be considered True
0
can be considered False
digital
.True
(1) or False
(0) output
.output
is also in binary.1
s and 0
s which the computer can then read and act upon.1
s and 0
s at runtime.Codespace
), so you do not need to install anything on your computer.reading_code.py
Output
I am the first line of code read by the computer
I am the second line read by the computer
Guess what, I am the third line read by the computer
reading_code.py
Output
I am printed first
I am a line inside a function
index_keys.py
Output:
a
1st value
Output:
a
Syntax error
Cell In[1], line 2
variable b = "The added space will cause an error"
^
SyntaxError: invalid syntax
quotation_marks.py
Syntax error
File "quotation_marks.py", line 2
variable_b = "I have the wrong matching quotation marks'
^
SyntaxError: unterminated string literal (detected at line 18)
variable_b
’s string causes an error due to unmatching quotation marks.quotation_marks.py
Will print as
I want to highlight 'this' word
I would like to show you "this"
Output
The patient's age is: 25
Output
The patient's age is: 25
Output
The patient's age is: 25
extremely
sensitive to indentation. One extra space or tab in front of a line of code and you will not hear the end of it in terms of errors or strange results.tabs
) of lines of code shows the computer which previous line(s) of code it relates to.Codespace
, 1 tab = 4 spacesindentation.py
Output
Drug has been prescribed and given to the patient
Drug round complete!
indentation.py
Output
Drug has been prescribed and given to the patient
snake_case
- for variables, functions and methodsuncomment
- remove the hashtag, or triple single / double quotation marks.Operators manipulate and compare data (which are stored in variables). Operator types include:
Assign =
x = "a string"
+
plus (eg x = 3 + 5
)-
minus*
multiply/
divide==
compare (eg if x == 8
)>
greater than<
less thanin
and not in
Output
Yes, 2 is in the list
DRY
(don't repeat yourself
) philosophy.Output
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.At first, this looks like a very complicated output
The traceback is printed to the terminal, as such:
Traceback (most recent call last):
File "/User/a_user/code/error_in_code.py", line 7, in _price
print(human_organ_locations["football"])
KeyError: 'football'
When reading a Traceback, alwas read from the last line upwards.
Traceback (most recent call last):
File "/User/a_user/code/error_in_code.py", line 7, in _price
print(human_organ_locations["football"])
==> KeyError: ‘football’ <==
^
Syntax error:
Cell In[1], line 2
variable b = "The added space will cause an error"
^
SyntaxError: invalid syntax
squiggly lines
to highlight errors.Lesson 2
.True
and False
, e.g. 1
and 0
s. 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
explaining
what code is supposed to do.10:1 reading to writing code ratio
).