Beginners Programming Course
Lesson one
Ismail S
November 2018
Who am I?
- Studied maths & physics at Leeds uni
- Learnt to program in my spare time, initially via Youtube
- Got a job at a software consultancy
- Gets paid money to program
Who are you?
Introductions
Why am I doing this?
- I want to see if I can teach people to program
- To introduce you guys to a new skill (maybe a new career)
What we will cover
- Basics of programming in Python eg:
- Numbers, strings etc
- Variables
- Functions
- Lists, dictionaries
- Making basic programs
What we won’t cover
- Classes (unless we do well with everything else)
- Making websites
- Making apps
- Making anything with a graphical interface
- Loads of other stuff
- But you’ll take the first steps to being able to do these things
How I’ll teach
- We’ll work through Automate the Boring Stuff with Python (with a few tweaks/additions)
- Work at your pace, but ideally everyone stays roughly together
- At some points, I’ll present some stuff lecture-style
- I go around and help people
What I expect of you
- Be respectful (of everyone).
- This includes being on time (let me know in advance if you’ll be late).
- Ask questions, no matter how basic they may seem (but also try and figure things out yourself)
- I may ask you to look things up yourselves - this is intentional, I’m not being lazy
Homework?
- This isn’t school
- But doing stuff outside of the lessons will help. A lot.
- You can only help yourself.
Exam
- There isn’t one
- But depending on how things go, I may set a final (challenging-ish) exercise
Warning
- Programming is hard (it requires you to think)
- But, if done right, it can be enjoyable/addictive
- Programming is not for everyone (but give it a decent shot before giving up)
- However, software is eating the world
A little bit of background
What are computers?
- Machines that follow instructions
- Example instructions:
- Add these 2 numbers together
- Check if this number is equal to 0
- Go (jump) to another instruction
- Store this number in this place in memory
- The instructions computers follow aren’t too fancy or complicated
- But computers can perform these instructions very fast
- And computers don’t get tired or complain. Ever.
What is programming?
- Writing the instructions that computers can then follow (execute)
- The language that computers understand is very boring and tedious to write instructions in
- So we use easier languages to write the instructions in (like Python)
- Then we either:
- Run this through another program to turn it into the instructions a computer understands. Like translating from eg French to English. Except we get a program to do it for us.
- Run a virtual computer on top of the actual computer. The virtual computer understands our instructions.
- I know, it sounds crazy, but it does work
- This is how we’ll run our Python code
- A program is just a bunch of instructions for a computer to follow
What is Python?
- A good programming language for beginners
- One of the most popular programming languages in industry
- Named after Monty Python
Now let’s go over what you learned
Print function
- The print function takes something and prints it to the screen
print('like this')
print(50)
print('or even ' + 'like this')
Other functions
len
takes a string and returns the length
input
asks the user for input and returns it
int
turns things into an integer
str
turns things into a string
Comparing numbers and strings
Truth table
True |
True |
True |
True |
False |
False |
False |
True |
False |
False |
False |
False |
Truth table
True |
True |
True |
True |
False |
True |
False |
True |
True |
False |
False |
False |
Modules
- Modules are collections of functions and other stuff
- You have to import a module, then you can use the things that are in it
Importing in this way can make code confusing
Functions can:
- take 1 or more inputs
- return 1 or more outputs (more than 1 output will be covered later)
- do anything that can be done outside functions
- eg print to screen, get input from the user, add numbers etc
None
None
is the only value of type NoneType
- If a function doesn’t execute a
return
statement, then None
is implicitly returned
Local & global scope
- Variables assigned inside a function exist in the local scope of that function
- Variables assigned outside all functions exist in the global scope
- Local scopes are created every time a function is called
- Scopes sound confusing at first, but with practice, they become intuitive
Try not to do this to avoid confusion
In practice, we rarely use global
as it makes code confusing