SlideShare a Scribd company logo
An Introduction To Software
Development Using Python
Spring Semester, 2015
Class #3:
Variables, Math
An Example Python Job Description
Python Developer: Cadatasoft,
Richardson, TX, 3 weeks ago
Job Description:
• Candidate mindset should align to the
agile manifesto…
• Individuals and interactions over
processes and tools
• Working software over comprehensive
documentation
• Customer collaboration over contract
negotiation
• Responding to change over following a
plan
Core Technology Competence:
• Python, Django, JavaScript, MongoDB
• Valued Technology Competence
• HTML5, Angular.js, RabbitMQ, Git,
Jenkins, Agile
Experience:
• Candidates should value software design
patterns
• Have a level of maturity allowing them to
work with a diverse set of clients
• Be able to demonstrate above average
competence with 3 out of 4 core
technologies
• Revel in using their mind and all it has to
offer
Let’s Talk About Variables…
• Variables are reserved memory locations to store values. This means that
when you create a variable you reserve some space in memory.
• Variables in Python consist of an alphanumeric name beginning in a letter
or underscore. Variable names are case sensitive.
• Python variables do not have to be explicitly declared to reserve memory
space. The declaration happens automatically when you assign a value to
a variable. The equal sign (=) is used to assign values to variables.
• The operand to the left of the = operator is the name of the variable and
the operand to the right of the = operator is the value stored in the
variable.
• Examples:
counter = 100
miles = 1000.0
name = "John"
Image Credit: ClipArt Best
Python variable
names can have
unlimited length –
but keep them short!
Variable Names:
The Good, The Bad, The Ugly
Examples
• X -- bad
• student_ID -- good
• numStudents -- good
• numberofstudentsenrolledinclass
--- bad
• stuff --- bad
Bad Names
• Single-letter names: x
• Naming thing after their type:
my_number = 20, my_string =
"Homo sapiens“
• Extremely vague names:
do_stuff(), process_files()
• Sequential names: dna, dna2,
dna3
• Re-using names
• Names that only vary by case or
punctuation: mydna, myDNA
A good variable name
should indicate its use
Let’s Talk About Python Math!
Normal Stuff
Weird Stuff
5%2 = 1
Modulo (%) Is Your Friend
• A man has 113 cans of Coke. He also has a group of boxes that can hold 12 cans
each. How many cans will he have left over once he’s loaded all of the boxes?
• On a military base the clock on the wall says that the time is 23:00. What time of
day is this?
• My friend has 10,432 ping pong balls that he needs to put into storage. My car can
transport 7,239 balls. How many will be left after I leave?
What Comes First?
Precedence Rules
• The precedence rules you learned in algebra apply during the evaluation
of arithmetic expressions in Python:
– Exponentiation has the highest precedence and is evaluated first.
– Unary negation is evaluated next, before multiplication, division, and
remainder.
– Multiplication, division, and remainder are evaluated before addition and
subtraction.
– Addition and subtraction are evaluated before assignment.
– With two exceptions, operations of equal precedence are left associative,
so they are evaluated from left to right. Exponentiation and assignment
operations are right associative, so consecutive instances of these are evaluated from
right to left.
– You can use parentheses to change the order of evaluation
• "PEMDAS", which is turned into the phrase "Please Excuse My Dear Aunt
Sally". It stands for "Parentheses, Exponents, Multiplication and Division,
and Addition and Subtraction".
3**2
-5
2+3*4/6
sum = 2+3
2+3*4/6
sum = 3**2**5
(2+3)*4/5
Image Credit: www.pinterest.com
Precedence Rules: Examples
• Simplify 4 + 32
• Simplify 4 + (2 + 1)2
• Simplify 4 + [–1(–2 – 1)]2
• Simplify 4( –2/3 + 4/3)
• Three people ate dinner at a restaurant and want to split the
bill. The total is $35.27, and they want to leave a 15 percent
tip. How much should each person pay?
Image Credit: pixgood.com
Errors: Syntax & Sematic
• A syntax error occurs when you mistype something
and create an invalid statement.
• A semantic error is detected when the action which
an expression describes cannot be carried out, even
though that expression is syntactically correct.
Example: Although the expressions 45 / 0 and 45 % 0
are syntactically correct, they are meaningless,
because the computer cannot carry them out.
Image Credit: www.canstockphoto.com
Really, Really Long Expressions
• When an expression becomes long or
complex, you can move to a new line by
placing a backslash character  at the
end of the current line.
Not All Numbers Are Created Equal
• Integers are the numbers you can easily count, like 1,
2, 3, as well as 0 and the negative numbers, like –1, –2,
–3.
• Decimal numbers (also called real numbers) are the
numbers with a decimal point and some digits after it,
like 1.25, 0.3752, and –101.2.
• In computer programming, decimal numbers are also
called floating-point numbers, or sometimes floats for
short (or float for just one of them). This is because the
decimal point “floats” around. You can have the
number 0.00123456 or 12345.6 in a float.
Image Credit: www.clipartpanda.com
Mixed-Mode Arithmetic
and Type Conversions
• Performing calculations involving both integers and
floating-point numbers is called mixed-mode
arithmetic.
• Conversions
– Determine type: type()
– Drop decimal: int()
– Round up / down: round()
– Change to decimal: float()
– Change to string: str()
Image Credit: personaltrainerbusinesssystems.com
Cool Kid Stuff:
Increment / Decrement / E-Notation
• Incrementing: sum = sum + 1
– sum += 1
• Decrementing: sum = sum – 1
– sum -= 1
• E-Notation
– 1,000,000 = 1 x 10**6 = 1e6
Image Credit: www.toonvectors.com
What’s In Your Python Toolbox?
print() math
What We Covered Today
1. What variables are.
2. What makes a good / bad
variable name.
3. How to do math in
Python.
4. Operator precedence
5. Mixed-Mode Arithmetic
Image Credit: http://www.tswdj.com/blog/2011/05/17/the-grooms-checklist/
What We’ll Be Covering Next Time
1. Strings,
2. Input / Output
Image Credit: http://merchantblog.thefind.com/2011/01/merchant-newsletter/resolve-to-take-advantage-of-these-5-e-commerce-trends/attachment/crystal-ball-fullsize/

More Related Content

PPTX
Weak Slot and Filler Structures
PPTX
weak slot and filler structure
PPTX
PPT
Lesson 4 variables in Python
PDF
Python - the basics
PPTX
An Introduction To Python - Python Midterm Review
PPTX
Brixton Library Technology Initiative Week0 Recap
PPTX
Python for beginner, learn python from scratch.pptx
Weak Slot and Filler Structures
weak slot and filler structure
Lesson 4 variables in Python
Python - the basics
An Introduction To Python - Python Midterm Review
Brixton Library Technology Initiative Week0 Recap
Python for beginner, learn python from scratch.pptx

Similar to An Introduction To Python - Variables, Math (20)

PPTX
Review 2Pygame made using python programming
PPTX
C# 101: Intro to Programming with C#
PPTX
Python Programming | JNTUK | UNIT 1 | Lecture 4
PPTX
Lec2_cont.pptx galgotias University questions
PPTX
Ml ppt at
PPTX
Review old Pygame made using python programming.pptx
PPTX
An Introduction To Python - Working With Data
PDF
Foundations of Machine Learning - StampedeCon AI Summit 2017
PDF
DutchMLSchool. Logistic Regression, Deepnets, Time Series
PPTX
Genetic algorithm
PPTX
Pythonlearn-02-Expressions123AdvanceLevel.pptx
PPTX
Machine Learning on Azure - AzureConf
PPTX
Chapter 2: Elementary Programming
PDF
Nearest Neighbor And Decision Tree - NN DT
PPTX
Decision Tree.pptx
PPTX
Introduction to machine learning and model building using linear regression
PPT
PythonCourse_02_Expressions.ppt Python introduction turorial for beginner.
PPTX
probability.pptx
PDF
DutchMLSchool. Automating Decision Making
PDF
AmI 2015 - Python basics
Review 2Pygame made using python programming
C# 101: Intro to Programming with C#
Python Programming | JNTUK | UNIT 1 | Lecture 4
Lec2_cont.pptx galgotias University questions
Ml ppt at
Review old Pygame made using python programming.pptx
An Introduction To Python - Working With Data
Foundations of Machine Learning - StampedeCon AI Summit 2017
DutchMLSchool. Logistic Regression, Deepnets, Time Series
Genetic algorithm
Pythonlearn-02-Expressions123AdvanceLevel.pptx
Machine Learning on Azure - AzureConf
Chapter 2: Elementary Programming
Nearest Neighbor And Decision Tree - NN DT
Decision Tree.pptx
Introduction to machine learning and model building using linear regression
PythonCourse_02_Expressions.ppt Python introduction turorial for beginner.
probability.pptx
DutchMLSchool. Automating Decision Making
AmI 2015 - Python basics
Ad

Recently uploaded (20)

PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Institutional Correction lecture only . . .
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Cell Structure & Organelles in detailed.
PPTX
Cell Types and Its function , kingdom of life
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Insiders guide to clinical Medicine.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Pharma ospi slides which help in ospi learning
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
2.FourierTransform-ShortQuestionswithAnswers.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Institutional Correction lecture only . . .
Supply Chain Operations Speaking Notes -ICLT Program
Cell Structure & Organelles in detailed.
Cell Types and Its function , kingdom of life
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
O7-L3 Supply Chain Operations - ICLT Program
Insiders guide to clinical Medicine.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Microbial diseases, their pathogenesis and prophylaxis
Pharma ospi slides which help in ospi learning
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Complications of Minimal Access Surgery at WLH
Renaissance Architecture: A Journey from Faith to Humanism
Ad

An Introduction To Python - Variables, Math

  • 1. An Introduction To Software Development Using Python Spring Semester, 2015 Class #3: Variables, Math
  • 2. An Example Python Job Description Python Developer: Cadatasoft, Richardson, TX, 3 weeks ago Job Description: • Candidate mindset should align to the agile manifesto… • Individuals and interactions over processes and tools • Working software over comprehensive documentation • Customer collaboration over contract negotiation • Responding to change over following a plan Core Technology Competence: • Python, Django, JavaScript, MongoDB • Valued Technology Competence • HTML5, Angular.js, RabbitMQ, Git, Jenkins, Agile Experience: • Candidates should value software design patterns • Have a level of maturity allowing them to work with a diverse set of clients • Be able to demonstrate above average competence with 3 out of 4 core technologies • Revel in using their mind and all it has to offer
  • 3. Let’s Talk About Variables… • Variables are reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. • Variables in Python consist of an alphanumeric name beginning in a letter or underscore. Variable names are case sensitive. • Python variables do not have to be explicitly declared to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables. • The operand to the left of the = operator is the name of the variable and the operand to the right of the = operator is the value stored in the variable. • Examples: counter = 100 miles = 1000.0 name = "John" Image Credit: ClipArt Best Python variable names can have unlimited length – but keep them short!
  • 4. Variable Names: The Good, The Bad, The Ugly Examples • X -- bad • student_ID -- good • numStudents -- good • numberofstudentsenrolledinclass --- bad • stuff --- bad Bad Names • Single-letter names: x • Naming thing after their type: my_number = 20, my_string = "Homo sapiens“ • Extremely vague names: do_stuff(), process_files() • Sequential names: dna, dna2, dna3 • Re-using names • Names that only vary by case or punctuation: mydna, myDNA A good variable name should indicate its use
  • 5. Let’s Talk About Python Math! Normal Stuff Weird Stuff 5%2 = 1
  • 6. Modulo (%) Is Your Friend • A man has 113 cans of Coke. He also has a group of boxes that can hold 12 cans each. How many cans will he have left over once he’s loaded all of the boxes? • On a military base the clock on the wall says that the time is 23:00. What time of day is this? • My friend has 10,432 ping pong balls that he needs to put into storage. My car can transport 7,239 balls. How many will be left after I leave?
  • 7. What Comes First? Precedence Rules • The precedence rules you learned in algebra apply during the evaluation of arithmetic expressions in Python: – Exponentiation has the highest precedence and is evaluated first. – Unary negation is evaluated next, before multiplication, division, and remainder. – Multiplication, division, and remainder are evaluated before addition and subtraction. – Addition and subtraction are evaluated before assignment. – With two exceptions, operations of equal precedence are left associative, so they are evaluated from left to right. Exponentiation and assignment operations are right associative, so consecutive instances of these are evaluated from right to left. – You can use parentheses to change the order of evaluation • "PEMDAS", which is turned into the phrase "Please Excuse My Dear Aunt Sally". It stands for "Parentheses, Exponents, Multiplication and Division, and Addition and Subtraction". 3**2 -5 2+3*4/6 sum = 2+3 2+3*4/6 sum = 3**2**5 (2+3)*4/5 Image Credit: www.pinterest.com
  • 8. Precedence Rules: Examples • Simplify 4 + 32 • Simplify 4 + (2 + 1)2 • Simplify 4 + [–1(–2 – 1)]2 • Simplify 4( –2/3 + 4/3) • Three people ate dinner at a restaurant and want to split the bill. The total is $35.27, and they want to leave a 15 percent tip. How much should each person pay? Image Credit: pixgood.com
  • 9. Errors: Syntax & Sematic • A syntax error occurs when you mistype something and create an invalid statement. • A semantic error is detected when the action which an expression describes cannot be carried out, even though that expression is syntactically correct. Example: Although the expressions 45 / 0 and 45 % 0 are syntactically correct, they are meaningless, because the computer cannot carry them out. Image Credit: www.canstockphoto.com
  • 10. Really, Really Long Expressions • When an expression becomes long or complex, you can move to a new line by placing a backslash character at the end of the current line.
  • 11. Not All Numbers Are Created Equal • Integers are the numbers you can easily count, like 1, 2, 3, as well as 0 and the negative numbers, like –1, –2, –3. • Decimal numbers (also called real numbers) are the numbers with a decimal point and some digits after it, like 1.25, 0.3752, and –101.2. • In computer programming, decimal numbers are also called floating-point numbers, or sometimes floats for short (or float for just one of them). This is because the decimal point “floats” around. You can have the number 0.00123456 or 12345.6 in a float. Image Credit: www.clipartpanda.com
  • 12. Mixed-Mode Arithmetic and Type Conversions • Performing calculations involving both integers and floating-point numbers is called mixed-mode arithmetic. • Conversions – Determine type: type() – Drop decimal: int() – Round up / down: round() – Change to decimal: float() – Change to string: str() Image Credit: personaltrainerbusinesssystems.com
  • 13. Cool Kid Stuff: Increment / Decrement / E-Notation • Incrementing: sum = sum + 1 – sum += 1 • Decrementing: sum = sum – 1 – sum -= 1 • E-Notation – 1,000,000 = 1 x 10**6 = 1e6 Image Credit: www.toonvectors.com
  • 14. What’s In Your Python Toolbox? print() math
  • 15. What We Covered Today 1. What variables are. 2. What makes a good / bad variable name. 3. How to do math in Python. 4. Operator precedence 5. Mixed-Mode Arithmetic Image Credit: http://www.tswdj.com/blog/2011/05/17/the-grooms-checklist/
  • 16. What We’ll Be Covering Next Time 1. Strings, 2. Input / Output Image Credit: http://merchantblog.thefind.com/2011/01/merchant-newsletter/resolve-to-take-advantage-of-these-5-e-commerce-trends/attachment/crystal-ball-fullsize/

Editor's Notes

  • #2: New name for the class I know what this means Technical professionals are who get hired This means much more than just having a narrow vertical knowledge of some subject area. It means that you know how to produce an outcome that I value. I’m willing to pay you to do that.