1/18
Looks like no tags are added yet.
Boolean Expressions can be which two things:
True or false
List of Comparison operators:
<, >, ==, !=, <=, and >=
Arithmetic (+-*/) first OR comparison (><=) first?
Arithmetic
False AND true =
False
False OR true =
True
Why should u be careful when using == with Floats?
tiny inaccuracies with the decimals build up and can eventually lead to significantly incorrect results.
Python program definition
A Python program is a sequence of Python statements
What are Python programs executed by?
Executed using an integrated development environment (IDE) or “from the command line”
how to use the if statement:
If (condition here):
(whatever code should happen if the condition is true)
how to use if else statement
If (condition):
(whatever code)
Else:
(anything apart from the if being true will be this)
What is critical for If and if-else statements to work?
Indentation
ow If, elif, else statements work
If (condition):
whatever it is
elif (condition 2):
else:
how does a for loop work:
for (Variable name) in (sequence of some sort):
whatever code block:
Example:
for number in range(5):
print(number)
how to write a for loop on the same line:
for number in range(5):
print(number, end = ' ')
Result: 0 1 2 3 4
how does the range function work:
he range function generates a sequence of integers in a for loop
Different types of range functions
range(n) generates the sequence 0, ..., n-1
• range(i, n)generates the sequence i, i+1, i+2, …, n-1
• range(i, n, c)generates the sequence i, i+c, i+2c, i+3c, …, n-1
for loop – string example:
For example:
word = "apple"
for letter in word:
print(letter)
for loop – tuple example
days = ('Mon','Tue','Wed','Thu','Fri','Sat','Sun')
for day in days:
print(day)
How to append a list:
oneTwoThree = [1, 2, 3]
for i in oneTwoThree:
oneTwoThree.append(i + 3)
print('i = ',i)
print('oneTwoThree = ', oneTwoThree)