BADM 211 Exam Prep
Function - answer A block of code that takes inputs and may return an output.
Python only provides ___ built-in functions - answer68
print() - answer prints output to the screen
max() - answer Get the maximum number from a list of numbers.
len() - answer Get the length (number of items) in an object.
round() - answer Round a number to the nearest integer.
Python functions are categorized into 3 different types: - answer1. Modules
2. Packages
3. Libraries
Pandas - answeruseful for data manipulation & analysis.
Matplotlib & Seaborn are good for... - answercreating plots/data visualization
Scikit-learn machine learning algorithms are.. - answerefficiently coded in Python
Integer (int) - answerWhole numbers (without a decimal point)
- Ex: 2, 45
Float (float) - answerNumbers with a decimal point.
- Ex: 2.0, 45.6
String (str) - answerAn ordered sequence of characters.
- Anything in quotes:
- Ex: "Business analytics", "2", "year is 1999."
Boolean (bool) - answerLogical value
- Ex: True/False
What kind of data type are these:
"True"
"22.4"
45.0 - answerAnswers:
String
String
,Float
Variable - answera named piece of memory that can store a value course_title = "Intro
to Business Analytics"
- Why: So we can access the value later in the notebook.
- Notice: We use = (a single equals sign)
- Variable names are never in quotation marks.
3 Rules with Variables - answer1. Some words cannot be used as a variable name
(del).
- Python returns an error if you accidentally use one.
2. Python is case sensitive:
- The variable Bob is different than the variable bob.
- We'll typically use all lower-case variable names.
3. Variables cannot start with a number or contain spaces:
- Invalid variable names: 211badm and badm 211.
- Valid variable name: badm211
Variables: Common Errors - answer1. Variable not defined (not assigned a value).
2. Using == instead of =
Variables + Data Types - answer- Can assign different types of data to variables.
- How to check the data type of a variable.
*type() function
Arithmetic Operators
(Addition, Subtraction, Multiplication, Division, Exponentiation) - answer1. Addition (+)
- Ex: 3+2 = 5
2. Subtraction (-)
- Ex: 3-2 = 1
3. Multiplication (*)
- Ex: 3*2 = 6
4. Division (/)
- Ex: 3/2 = 1.5
5. Exponentiaion (**)
- Ex: 3 ** 2 = 9
Arithmetic Operators - answer1. Order of operations is the same as what you learned in
elementary school.
- Multiplication, division, and exponentiation take precedence over addition and
subtraction.
- When in doubt, use parentheses.
2. Spaces don't matter here*
- 2+3 is the same as 2+3
- But the second one is easier to read, so use spaces.
, *Note: Spaces (indentations) will matter in certain scenarios (if-else statements, for
loops, and functions)
Comparison Operators:
- Sometimes we want to compare two values and return a Boolean value. -
answerEqual to (==)
- Ex: 3 == 2 --> False
Not equal to (!=)
- Ex: 3 != 2 --> True
Less than (<)
- Ex: 3 < 2 --> False
Less than or equal to (<=)
- Ex: 3 <= 2 False
Greater than (>)
- Ex: 3 > 2 --> True
Greater than or equal to (>=)
- Ex: 3 >= 2 --> True
What will you see if you execute the following line of code in Python?
x = true
A. Nothing. We are defining a variable, so nothing is returned.
B. An error message
C. x
D. True - answerB. An error message
Prof. Luckman and I have a weekly poker game. We played 5 games. I have won three
times; she has won twice.
I want to add up our winnings and see who has won more in Python, but something's
not right. Debug the following code:
# My winnings
vv = 10 + 21 + 19
Her winnings
eat = 38 - 99
# Check if I earned more
vv < eal - answer# My winnings
vv = 10 + 21 + 19
# Her winnings
eat = 38 + 99
# Check if I earned more
vv > eal
What is a list? - answer- In life: a set of items written consecutively.
- In Python: An ordered collection of data, list elements don't have to be the same type.
- Ex: star = ['R2D2', 'Luke', 'BB-8', 66]
Function - answer A block of code that takes inputs and may return an output.
Python only provides ___ built-in functions - answer68
print() - answer prints output to the screen
max() - answer Get the maximum number from a list of numbers.
len() - answer Get the length (number of items) in an object.
round() - answer Round a number to the nearest integer.
Python functions are categorized into 3 different types: - answer1. Modules
2. Packages
3. Libraries
Pandas - answeruseful for data manipulation & analysis.
Matplotlib & Seaborn are good for... - answercreating plots/data visualization
Scikit-learn machine learning algorithms are.. - answerefficiently coded in Python
Integer (int) - answerWhole numbers (without a decimal point)
- Ex: 2, 45
Float (float) - answerNumbers with a decimal point.
- Ex: 2.0, 45.6
String (str) - answerAn ordered sequence of characters.
- Anything in quotes:
- Ex: "Business analytics", "2", "year is 1999."
Boolean (bool) - answerLogical value
- Ex: True/False
What kind of data type are these:
"True"
"22.4"
45.0 - answerAnswers:
String
String
,Float
Variable - answera named piece of memory that can store a value course_title = "Intro
to Business Analytics"
- Why: So we can access the value later in the notebook.
- Notice: We use = (a single equals sign)
- Variable names are never in quotation marks.
3 Rules with Variables - answer1. Some words cannot be used as a variable name
(del).
- Python returns an error if you accidentally use one.
2. Python is case sensitive:
- The variable Bob is different than the variable bob.
- We'll typically use all lower-case variable names.
3. Variables cannot start with a number or contain spaces:
- Invalid variable names: 211badm and badm 211.
- Valid variable name: badm211
Variables: Common Errors - answer1. Variable not defined (not assigned a value).
2. Using == instead of =
Variables + Data Types - answer- Can assign different types of data to variables.
- How to check the data type of a variable.
*type() function
Arithmetic Operators
(Addition, Subtraction, Multiplication, Division, Exponentiation) - answer1. Addition (+)
- Ex: 3+2 = 5
2. Subtraction (-)
- Ex: 3-2 = 1
3. Multiplication (*)
- Ex: 3*2 = 6
4. Division (/)
- Ex: 3/2 = 1.5
5. Exponentiaion (**)
- Ex: 3 ** 2 = 9
Arithmetic Operators - answer1. Order of operations is the same as what you learned in
elementary school.
- Multiplication, division, and exponentiation take precedence over addition and
subtraction.
- When in doubt, use parentheses.
2. Spaces don't matter here*
- 2+3 is the same as 2+3
- But the second one is easier to read, so use spaces.
, *Note: Spaces (indentations) will matter in certain scenarios (if-else statements, for
loops, and functions)
Comparison Operators:
- Sometimes we want to compare two values and return a Boolean value. -
answerEqual to (==)
- Ex: 3 == 2 --> False
Not equal to (!=)
- Ex: 3 != 2 --> True
Less than (<)
- Ex: 3 < 2 --> False
Less than or equal to (<=)
- Ex: 3 <= 2 False
Greater than (>)
- Ex: 3 > 2 --> True
Greater than or equal to (>=)
- Ex: 3 >= 2 --> True
What will you see if you execute the following line of code in Python?
x = true
A. Nothing. We are defining a variable, so nothing is returned.
B. An error message
C. x
D. True - answerB. An error message
Prof. Luckman and I have a weekly poker game. We played 5 games. I have won three
times; she has won twice.
I want to add up our winnings and see who has won more in Python, but something's
not right. Debug the following code:
# My winnings
vv = 10 + 21 + 19
Her winnings
eat = 38 - 99
# Check if I earned more
vv < eal - answer# My winnings
vv = 10 + 21 + 19
# Her winnings
eat = 38 + 99
# Check if I earned more
vv > eal
What is a list? - answer- In life: a set of items written consecutively.
- In Python: An ordered collection of data, list elements don't have to be the same type.
- Ex: star = ['R2D2', 'Luke', 'BB-8', 66]