Course 2: Telling Computers what to do
I learned the programming basics: variables, functions various data types (strings, numbers, lists...), etc... This course was definitely hard and I still don't feel like an expert in solving problems with Python, but I can at least read and reuse other people's code if I want to.
Lesson 1: Introduction to Serious Programming
Answers questions like: What's a program? What's a computer? What's a programming language?
Computer: A computer is a machine that can carry out instructions given to it by a programmer.
Grammar: Grammar refers to the rules that govern what statements are 'legal' in a language. Python has it's own grammar.
Lesson 2: Variables and Strings
We can store textual information (strings) in titled containers (variables)
Variable: A variable is a titled container that holds information.
String: A string is just text. We create strings by using single or double quotes.
Lesson 3: Input --> Function --> Output
A function is something that takes input, does something with that input, and then returns something else as output.
Defining Functions: In Python, functions are defined by writing the 'def' keyword followed by a name, and then the 'parameters' for the function (inside parentheses), and a colon.
return vs print: When functions don't have a 'return' statement, they don't really do anything (even though they may print out some text). You usually want to make sure to end your function with a return statement.
Lesson 4: Decisions and Repetition - If and While
Control flow statements (like 'if' and 'else') let us execute different blocks of code depending on some condition. While loops let us repeat a certain block of code many times until a certain condition is met.
==, !=, >, <, >=, <=: These are all Python "comparison operators". They return the "boolean" True when they are correct and False when they are not. For example, 5 != 6 would return True, since 5 is not equal to 6.
if, then, else: These three Python keywords let us tell Python what code we want it to execute in different situations.
while loops: A while loop will repeat the indented block of code beneath it as long as the condition on the first line (right after 'while') is true.
Lesson 5: How to Solve Problems
The first step in solving large problems is to understand the problem. We do this by 1) understanding the inputs. 2) understanding the outputs. And 3) writing a function to correctly produce the desired output from the input.
Understanding Inputs: This requires figuring out what inputs your function will be responsible for processing In the example problem, the inputs were 6 numbers which are used to encode two dates. We also assumed that the second date would always be after the first.
Understanding Outputs: This requires figuring out exactly what output your function is responsible for providing. In the example problem, the output was a single number which represented the number of days between two dates.