SlideShare a Scribd company logo
1 of 19
Download to read offline
WELCOME TO SI
SI LEADER: CALEB PEACOCK
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
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
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?
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?
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.
UPDATING A VARIABLE
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.
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
Which of these names are not “legal” variable names?
avocadoNumber1
X
AvocadoNumber
4avocado
avocado Number
Avocado_Number
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.
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.
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:
____________
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=?
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?
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
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.
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.

More Related Content

Similar to powerpoint 1-19.pdf

powerpoint 2-7.pptx
powerpoint 2-7.pptxpowerpoint 2-7.pptx
powerpoint 2-7.pptxJuanPicasso7
 
Lecture 01 - Introduction and Review.ppt
Lecture 01 - Introduction and Review.pptLecture 01 - Introduction and Review.ppt
Lecture 01 - Introduction and Review.pptMaiGaafar
 
Recursion, debugging in c
Recursion, debugging in cRecursion, debugging in c
Recursion, debugging in cSaule Anay
 
To Loop or Not to Loop: Overcoming Roadblocks with FME
To Loop or Not to Loop: Overcoming Roadblocks with FMETo Loop or Not to Loop: Overcoming Roadblocks with FME
To Loop or Not to Loop: Overcoming Roadblocks with FMESafe Software
 
classVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptxclassVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptxssusere336f4
 
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGEINTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGERathnaM16
 
Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine LearningShahar Cohen
 
Brixton Library Technology Initiative Week0 Recap
Brixton Library Technology Initiative Week0 RecapBrixton Library Technology Initiative Week0 Recap
Brixton Library Technology Initiative Week0 RecapBasil Bibi
 
Cis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programmingCis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programmingHamad Odhabi
 
Oz_Chap 2_M3_Lesson Slides_Variables.pptx
Oz_Chap 2_M3_Lesson Slides_Variables.pptxOz_Chap 2_M3_Lesson Slides_Variables.pptx
Oz_Chap 2_M3_Lesson Slides_Variables.pptxALEJANDROLEONGOVEA
 
Computational thinking
Computational thinkingComputational thinking
Computational thinkingr123457
 
Speaking 'Development Language' (Or, how to get your hands dirty with technic...
Speaking 'Development Language' (Or, how to get your hands dirty with technic...Speaking 'Development Language' (Or, how to get your hands dirty with technic...
Speaking 'Development Language' (Or, how to get your hands dirty with technic...Julie Meloni
 
Prompt-Engineering-Lecture-Elvis learn prompt engineering
Prompt-Engineering-Lecture-Elvis learn prompt engineeringPrompt-Engineering-Lecture-Elvis learn prompt engineering
Prompt-Engineering-Lecture-Elvis learn prompt engineeringSaweraKhadium
 
Lab report walk through
Lab report walk throughLab report walk through
Lab report walk throughserenaasya
 
De vry math 221 all discussion+ilbs latest 2016 november
De vry math 221 all discussion+ilbs latest 2016 novemberDe vry math 221 all discussion+ilbs latest 2016 november
De vry math 221 all discussion+ilbs latest 2016 novemberlenasour
 

Similar to powerpoint 1-19.pdf (20)

Init() day2
Init() day2Init() day2
Init() day2
 
Init() Lesson 2
Init() Lesson 2Init() Lesson 2
Init() Lesson 2
 
powerpoint 2-7.pptx
powerpoint 2-7.pptxpowerpoint 2-7.pptx
powerpoint 2-7.pptx
 
Lecture 01 - Introduction and Review.ppt
Lecture 01 - Introduction and Review.pptLecture 01 - Introduction and Review.ppt
Lecture 01 - Introduction and Review.ppt
 
Recursion, debugging in c
Recursion, debugging in cRecursion, debugging in c
Recursion, debugging in c
 
To Loop or Not to Loop: Overcoming Roadblocks with FME
To Loop or Not to Loop: Overcoming Roadblocks with FMETo Loop or Not to Loop: Overcoming Roadblocks with FME
To Loop or Not to Loop: Overcoming Roadblocks with FME
 
Vba Class Level 1
Vba Class Level 1Vba Class Level 1
Vba Class Level 1
 
classVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptxclassVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptx
 
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGEINTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
 
Algebra prelims
Algebra prelimsAlgebra prelims
Algebra prelims
 
Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
 
Brixton Library Technology Initiative Week0 Recap
Brixton Library Technology Initiative Week0 RecapBrixton Library Technology Initiative Week0 Recap
Brixton Library Technology Initiative Week0 Recap
 
Cis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programmingCis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programming
 
Oz_Chap 2_M3_Lesson Slides_Variables.pptx
Oz_Chap 2_M3_Lesson Slides_Variables.pptxOz_Chap 2_M3_Lesson Slides_Variables.pptx
Oz_Chap 2_M3_Lesson Slides_Variables.pptx
 
Computational thinking
Computational thinkingComputational thinking
Computational thinking
 
Speaking 'Development Language' (Or, how to get your hands dirty with technic...
Speaking 'Development Language' (Or, how to get your hands dirty with technic...Speaking 'Development Language' (Or, how to get your hands dirty with technic...
Speaking 'Development Language' (Or, how to get your hands dirty with technic...
 
Prompt-Engineering-Lecture-Elvis learn prompt engineering
Prompt-Engineering-Lecture-Elvis learn prompt engineeringPrompt-Engineering-Lecture-Elvis learn prompt engineering
Prompt-Engineering-Lecture-Elvis learn prompt engineering
 
Code smells in PHP
Code smells in PHPCode smells in PHP
Code smells in PHP
 
Lab report walk through
Lab report walk throughLab report walk through
Lab report walk through
 
De vry math 221 all discussion+ilbs latest 2016 november
De vry math 221 all discussion+ilbs latest 2016 novemberDe vry math 221 all discussion+ilbs latest 2016 november
De vry math 221 all discussion+ilbs latest 2016 november
 

Recently uploaded

Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 

Recently uploaded (20)

Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 

powerpoint 1-19.pdf

  • 1. WELCOME TO SI SI LEADER: CALEB PEACOCK
  • 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.