Python Lesson 3
Control flow gives us this ability to choose among outcomes based off what else is
happening in the program.
Six comparators
1. Equal to (==)
2. Not equal to (!=)
3. Less than (<)
4. Less than or equal to (<=)
5. Greater than (>)
6. Greater than or equal to (>=)
Difference between = and ==
Note that == compares whether two things are equal, and = assigns a value to a variable.
Boolean operators compare statements and result in boolean values.
There are three boolean operators:
1. and, which checks if both the statements are True;
2. or, which checks if at least one of the statements is True;
3. not, which gives the opposite of the statement.
Just like with arithmetic operators, there's an order of operations for boolean operators:
not is evaluated first;
and is evaluated next;
or is evaluated last.
Parentheses () ensure your expressions are evaluated in the order you want. Anything
in parentheses is evaluated as its own unit.
Conditional Statement Syntax
if is a conditional statement that executes some specified code after checking if its
expression is True.
Here's an example of if statement syntax:
if 8 < 9:
print "Eight is less than nine!"
Lesson 3 Questions
1. Write a program that prints “Hello World”
2. Write a program to assign a variable ‘a’ to a number, add 25 to that variable and print that
variable.
3. Write a program with 3 variables storing text, and print out the 3 variables after being
concatenated.
4. Write a program that prints out if the number you have entered is greater than 5 or below 5.
If the number is greater than 5 the program should print, “Yes! The number is greater than
5”.
Else if the number is less than 5 the program should print, “Sorry, the number is less than 5”.
First it prints the string you give as a parameter (in this case 'Enter your name: '),
and then it waits for a line to be typed in, and returns the string of characters you typed.
applicant = input("Enter the applicant's name: ")