2. WHAT IS SI?
• SI stands for supplemental instruction
• You can think of these as peer led study sessions that help develop
your own study skills and retain concepts learned in class
• I will try my best to answer any questions, or find answers and report
back to you, but will also refer you to the professor as she is much
more experienced
• Slideshows, quizzes, games, exam review
3. AVOCADO PRICE CALCULATOR ALGORITHM
Price per pound=$2.50
Individual Weight= ½ lb
Get number of avocados
Total weight= individual weight * # of avocados
Total Cost=Total Weight / Price Per Pound
4. LAST WEEK REVIEW
• Python is case sensitive, True or False?
• Which of these is the correct use of the print statement?
A. Print(“This is the correct use”)
• B. print(“This is the correct use’)
• C. print(“This is the correct use”)
• D. print(“This is the correct use?
• What is the output of print(24+7)? A.31 B. 24+7 C. No output D. “24+7”
• What does n do?
• Can you describe what an algorithm is?
5. INTRODUCTION TO VARIABLES
• A variable is a named storage location for a computer program.
• You define the variable by giving it a name, and assigning a value to that
variable with an assignment statement, =
• Variables are used to store values that will be referenced later on in your
code.
• There are 12 cans in a pack of coke. Let’s create a variable representing
the number of cans. cansPerPack will do. Now, lets set it equal to its
value, 12.
cansPerPack=12
• Pull up your IDEs and type this, followed by print(cansPerPack) . What
was the output?
6. UPDATING A VARIABLE
• Updating a variable is quite easy, just change the value on the right hand side. The variable
will now store the new value
• cansPerPack=12 12 is the value being stored to the variable cansPerPack.
print(cansPerPack) will yield the output 12.
• cansPerPack=14 14 is now the value being stored for variable cansPerPack.
Print(cansPerPack) will now yield the output 14
• Variables can only store one value at a time, and will change every time you update them.
8. TYPES OF DATA
Three main data types are
• Integer
• Float
• String
• Integer is a whole number(no decimal) 5
• Float is any number with a decimal 5.0
• String is a sequence of “characters” or letters “five”
• IMPORTANT: The data type is associated with the value(whatever is on the right side)
and not the variable.
numberOfAvocados= 12 This is an Integer or int
pricePerPound= 2.50 This is a float
These data types are universal across many coding languages and not just python, so
they are important. You will use them a lot so don’t worry you will be comfortable with
them.
9. NAMING VARIABLES
• Names have to describe the purpose and should be easily recognizable to the coder and whoever
is reading it. If I read avocadoNumber as a variable, I immediately know what this variable does.
• Names must start with a letter or underscore(_), and be followed up with letters(upper or
lowercase), digits, or underscore
• NO SPACES OR OTHER SYMBOLS
• Two common ways to write your variable name: using a underscore as a space, or using camelCase
• avocado_Number or avocadoNumber It is personal preference just like single or double
quotes for your print statement. Just be consistent
10. Which of these names are not “legal” variable names?
avocadoNumber1
X
AvocadoNumber
4avocado
avocado Number
Avocado_Number
11. CONSTANT VARIABLES
• Constant Variables or “Constants” are variables whose value should never be changed after its value has been assigned. You do not
have to, but it is best practice to name your constant variables using all caps
• So the difference between a regular variable, and a constant variable, is constant variables do not change their value.
• How do I know when to use a constant variable vs a regular variable?
Think about fixed values, values that should never really change, or at the very least not change often. Like how manyfl oz are in a
can of coke. Its always going to be 12. Something like cans per 12 pack is always going to be 12. How many packs we buy though?
That can change. Maybe I just want 1, maybe theres a sweet deal and I buy 6.
• FL_OZ=12
• CANSPERPACK=12
• packsPurchased=2
The first two are constant variables because their value is fixed, and they are in all caps to signify that. The third is just a regular
variable, because the amount of cans you purchase varies. Since it is a regular variable, you would follow basic naming rules and not
capitalize it.
12. CONSTANT VARIABLES
It is very good practice to use named constant variables in place of numbers in your calculations
For an example, think back to our avocado example from last session, we said that the total price was total
weight/ price per pound and that the price per pound was 2.50
• totalPrice= totalWeight / 2.50
This totally works, but is bad practice. If we were working on a program together, and you came upon this
line of code I had written, you would be wondering what the 2.50 was or represented. Maybe if the program
you were building was large enough, you might forget what the value represented yourself.
totalPrice=totalWeight / pricePerPound is much better and more descriptive. If we initialized our variables
and their values beforehand, this should yield the same output. I will show you later
• Never change the name of your constant variables.
13. COMMENTS
• Comments are used to describe what each aspect of your code does. It is mostly for other people
reading your code to easily understand what is going on. Again, useful for collaborative projects.
• The compiler ignores the comments, and use the # symbol beforehand.
• Try it in your compiler,
#This would be ignored
print(“but this would not”)
output:
____________
14. MAYBE LOW ON TIME? ARITHMETIC
• Basic Operations
Addition “+” print(6+7) output=?
Subtraction “-” print(6-7) output=?
Multiplication “*” print (6*7) output=?
Division “/” print(42/7) output=?
• Just like in regular math, PEMDAS applies. Parentheses, exponents, multiplication or division, addition
or subtraction
• print(2+3*5) output=?
print( (2+3) *5 ) output=?
15. MIXING DATA TYPES
• Remember float and integers? For an example, 7 is an integer and 7.0 would be a float data type.
• print(7 * 7) output=49
• print(7 * 7.0) output=? What do you think the value would be? What happens when you mix different
data types like integer and float?
16. OTHER MATHEMATICAL OPERATORS THAT ARE HANDY
• Powers, or exponents, are used with double stars **
print(6**2) output=36
• Floor division is when you divide two integers numbers and if there is a remainder, it is discared. In
other words, if you divide 7/3, the output will be 2.333333333333. We divided two integers, and got a
floating number. If you want to discard the remainder(the .33333), use floor division
• Floor division is used by // print(7 // 3) output=2 It rounds to the nearest number.
• If you want the remainder of two dividing numbers, use the % operator(Modulus)
print(7%3) output=1
17.
18. INPUT FUNCTION
• It is very common to prompt a user for input. What are some real world examples you can think of, when you the user, are prompted
for an input to enter in the computer?
• It is also very common to store the value the user inputs into a variable. Think to our avocado example. How are we going to know
how many avocados someone buys? It is not a fixed value, and it depends on the user. It is best to use an input function
• numberofAvocados=input(“Enter the number of avocados you wish to purchase:”)
Inside the “ “ , you should prompt the user for input, or let them know what they are supposed to be inputting.
• When prompting the user for input, you have to specify what data type you are asking for(str, int, float)
• In our avocado example, we are asking for a number. So it is an integer or float. Would # of avocados be better as a integer data type
or float data type?
• Lets check out our avocado Calculator one more time.
• A lot of your errors in your labs will be using the wrong data types or not converting integers to strings.
19. Q&A
• Ask me anything about the class, lesson, last week, this week, anything coding. I am experienced in this
class, but still am relatively new just like you! I will do my best to answer and research for you, and if
not, refer you to the professor if I can not answer
• This section is MASSIVE and really important. I just really wanted you all to grasp the variable, and be
comfortable with plugging them into your equations. This is where the class really begins in my
opinion. Make sure to read the whole section and give yourself plenty of time on the labs. Ask
questions or watch videos online(so much content out there) if you get stuck!
• Next week I will do a quick recap of things we might have skipped in this session. An hour is not
enough. Really do go over index, the input statement, and string concatenation. These are all super
important, useful, and input statement is used CONSTANTLY. You will need to be comfortable with it
and switching between data types. A lot of times, you will get errors because your data types do not
match up. Really really study the book and slides. Watch videos.