SlideShare a Scribd company logo
Variables, Expressions, and
Statements
Chapter 2
Copyright 2010- Charles Severance
These slides are a derivative work based on the original slides, “Python for Informatics : Exploring Information”, created by Charles Severance. The original
slides are located at www.pythonlearn.com
This modified set of slides was done by John Alexander (2013).
The primary purpose of this derivative work is to make the highest quality Python courseware available to instructors so that they can teach Python, and insure
that the slides are properly formatted for easy, out-of-the-box, use by both Microsoft PowerPoint and OpenOffice Impress.
Unless otherwise noted, the content of this course material is licensed under a Creative Commons Attribution 3.0 License (The “BY” variant of the license)
http://creativecommons.org/licenses/by/3.0/.
Creative Commons Attribution 3.0 License
Constants
• Fixed values such as numbers, letters, and strings are
called “constants” - because their value does not change
• Numeric constants are as you expect
• String constants use single-quotes (')
or double-quotes (")
>>> print 123
123
>>> print 98.6
98.6
>>> print 'Hello world'
Hello world
Variables
• A variable is a named place in the memory where a programmer
can store data and later retrieve the data using the variable “name”
• Programmers get to choose the names of the variables
• You can change the contents of a variable in a later statement
12.2
12.2
x
14
14
y
x = 12.2
y = 14
100
x = 100
Python Variable Name Rules
• Can consist of letters, numbers, or underscores (but cannot
start with a number)
• Case Sensitive
• Good: spam eggs spam23 _speed
• Bad: 23spam #sign var.12
• Different: spam Spam SPAM
Reserved Words
• You can NOT use reserved words as variable names /
identifiers
and del for is raise assert elif
from lambda return break else
global not try class except if or while
continue exec import pass
yield def finally in print
Statements
x = 2
x = x + 2
print x
Variable Operator Constant Reserved Word
Assignment Statement
Assignment with expression
Print statement
Assignment Statements
• We assign a value to a variable using the assignment
statement (=)
• An assignment statement consists of an expression on the
right hand side and a variable to store the result
x = 3.9 * x * ( 1 - x )
x = 3.9 * x * ( 1 - x )
0.6
0.6
x
Right side is an expression.
Once expression is evaluated,
the result is placed in
(assigned to) x.
0.6 0.6
0.4
0.936
A variable is a memory
location used to store a value
(0.6).
0.936
0.936
x
x = 3.9 * x * ( 1 - x )
0.6 0.93
0.6 0.93
x
Right side is an expression.
Once expression is evaluated,
the result is placed in
(assigned to) the variable on
the left side (i.e. x).
0.93
A variable is a memory
location used to store a value.
The value stored in a variable
can be updated by replacing
the old value (0.6) with a new
value (0.93).
Numeric Expressions
• Because of the lack of
mathematical symbols on
computer keyboards - we use
“computer-speak” to express the
classic math operations
• Asterisk is multiplication
• Exponentiation (raise to a power)
looks different from in math.
+ Addition
- Subtraction
* Multiplication
/ Division
** Power
% Remainder
Numeric Expressions
>>> x = 2
>>> x = x + 2
>>> print x
4
>>> y = 440 * 12
>>> print y
5280
>>> z = y / 1000
>>> print z
5
>>> j = 23
>>> k = j % 5
>>> print k
3
>>> print 4 ** 3
64
+ Addition
- Subtraction
* Multiplication
/ Division
** Power
%
Remainder
(Modulus)
5 23
4 R 3
20
3
Order of Evaluation
• When we string operators together - Python must know
which one to do first
• This is called “operator precedence”
• Which operator “takes precedence” over the others
x = 1 + 2 * 3 - 4 / 5 ** 6
Operator Precedence Rules
• Highest precedence rule to lowest precedence rule
• Parenthesis are always respected
• Exponentiation (raise to a power)
• Multiplication, Division, and Remainder
• Addition and Subtraction
• Left to right
Parenthesis
Power
Multiplication
Addition
Left to Right
Parenthesis
Power
Multiplication
Addition
Left to Right
x = 1 + 2 ** 3 / 4 * 5
Parenthesis
Power
Multiplication
Addition
Left to Right
x = 1 + 2 ** 3 / 4 * 5 1 + 2 ** 3 / 4 * 5
1 + 8 / 4 * 5
1 + 2 * 5
1 + 10
11
Note 8/4 goes before
4*5 because of the left-
right rule.
Operator Precedence
• Remember the rules -- top to bottom
• When writing code - use parenthesis
• When writing code - keep mathematical expressions simple
enough that they are easy to understand
• Break long series of mathematical operations up to make
them more clear
Parenthesis
Power
Multiplication
Addition
Left to Right
Exam Question: x = 1 + 2 * 3 - 4 / 5
Integer Division
• Integer division truncates
• Floating point division
produces floating point
numbers
>>> print 10 / 2
5
>>> print 9 / 2
4
>>> print 99 / 100
0
>>> print 10.0 / 2.0
5.0
>>> print 99.0 / 100.0
0.99
This changes in Python 3.0
Mixing Integer and Floating
Numbers in Arithmetic Expressions
• When you perform an
operation where one
operand is an integer
and the other operand is
a floating point the result
is a floating point
• The integer is converted
to a floating point before
the operation
>>> print 99 / 100
0
>>> print 99 / 100.0
0.99
>>> print 99.0 / 100
0.99
>>> print 1 + 2 * 3 / 4.0 - 5
-2.5
>>>
Some Data Types in Python
• Integer (Examples: 0, 12, 5, -5)
• Float (Examples: 4.5, 3.99, 0.1 )
• String (Examples: “Hi”, “Hello”, “Hi there!”)
• Boolean (Examples: True, False)
• List (Example: [ “hi”, “there”, “you” ] )
• Tuple (Example: ( 4, 2, 7, 3) )
Data Types
• In Python variables, literals,
and constants have a “data
type”
• In Python variables are
“dynamically” typed. In some
other languages you have to
explicitly declare the type
before you use the variable
In C/C++:
int a;
float b;
a = 5
b = 0.43
In Python:
a = 5
a = “Hello”
a = [ 5, 2, 1]
More on “Types”
• In Python variables, literals,
and constants have a “type”
• Python knows the difference
between an integer number
and a string
• For example “+” means
“addition” if something is a
number and “concatenate” if
something is a string
>>> d = 1 + 4
>>> print d
5
>>> e = 'hello ' + 'there'
>>> print e
hello there
concatenate = put together
Type Matters
• Python knows what “type”
everything is
• Some operations are
prohibited
• You cannot “add 1” to a string
• We can ask Python what type
something is by using the
type() function.
>>> e = 'hello ' + 'there'
>>> e = e + 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot concatenate
'str' and 'int' objects
>>> type(e)
<type 'str'>
>>> type('hello')
<type 'str'>
>>> type(1)
<type 'int'>
>>>
Several Types of Numbers
• Numbers have two main types
• Integers are whole numbers: -14, -
2, 0, 1, 100, 401233
• Floating Point Numbers have
decimal parts: -2.5 , 0.0, 98.6, 14.0
• There are other number types -
they are variations on float and
integer
>>> x = 1
>>> type (x)
<type 'int'>
>>> temp = 98.6
>>> type(temp)
<type 'float'>
>>> type(1)
<type 'int'>
>>> type(1.0)
<type 'float'>
>>>
Type Conversions
• When you put an integer
and floating point in an
expression the integer is
implicitly converted to a
float
• You can control this with
the built in functions int()
and float()
>>> print float(99) / 100
0.99
>>> i = 42
>>> type(i)
<type 'int'>
>>> f = float(i)
>>> print f
42.0
>>> type(f)
<type 'float'>
>>> print 1 + 2 * float(3) / 4 - 5
-2.5
>>>
String
Conversions
• You can also use int()
and float() to convert
between strings and
integers
• You will get an error if
the string does not
contain numeric
characters
>>> sval = '123'
>>> type(sval)
<type 'str'>
>>> print sval + 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int'
>>> ival = int(sval)
>>> type(ival)
<type 'int'>
>>> print ival + 1
124
>>> nsv = 'hello bob'
>>> niv = int(nsv)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int()
User Input
• We can instruct
Python to pause and
read data from the
user using the
raw_input() function
• The raw_input()
function returns a
string
name = raw_input(‘Who are you?’)
print 'Welcome ', name
Who are you? Chuck
Welcome Chuck
Converting User Input
• If we want to read a
number from the user,
we must convert it
from a string to a
number using a type
conversion function
• Later we will deal with
bad input data
inp = raw_input(‘Europe floor?’)
usf = int(inp) + 1
print “US floor: ”, usf
Europe floor? 0
US floor : 1
Comments in Python
• Anything after a # is ignored by Python
• Why comment?
• Describe what is going to happen in a sequence of code
• Document who wrote the code or other ancillary
information
• Turn off a line of code - perhaps temporarily
# Get the name of the file and open it
name = raw_input("Enter file:")
handle = open(name, "r") # This is a file handle
text = handle.read()
words = text.split()
String Operations
• Some operators apply to strings
• + implies “concatenation”
• * implies “multiple
concatenation”
• Python knows when it is dealing
with a string or a number and
behaves appropriately
>>> print 'abc' + '123‘
Abc123
>>> print 'Hi' * 5
HiHiHiHiHi
Mnemonic Variable Names
• Since we programmers are given a choice in how we
choose our variable names, there is a bit of “best
practice”
• We name variables to help us remember what we
intend to store in them (“mnemonic” = “memory aid”)
• This can confuse beginning students because well
named variables often “sound” so good that they
must be keywords
x1q3z9ocd = 35.0
x1q3z9afd = 12.50
x1q3p9afd = x1q3z9ocd * x1q3z9afd
print x1q3p9afd
hours = 35.0
rate = 12.50
pay = hours * rate
print pay
a = 35.0
b = 12.50
c = a * b
print c
What is this
code doing?
Exercise
Write a program to prompt the user for hours
and rate per hour to compute gross pay.
Enter Hours: 35
Enter Rate: 2.75
Pay: 96.25
Summary
• Types (int, float, boolean, string, list, tuple, …)
• Reserved words
• Variables (mnemonic)
• Operators and Operator precedence
• Division (integer and floating point)
• Conversion between types
• User input
• Comments (#)

More Related Content

PDF
python2oxhvoudhuSGFsughusgdogusuosFU.pdf
PPTX
Lec2_cont.pptx galgotias University questions
PDF
03-Variables, Expressions and Statements (1).pdf
PPTX
Pythonlearn-02-Expressions123AdvanceLevel.pptx
PPTX
PPT_1_9102501a-a7a1-493e-818f-cf699918bbf6.pptx
PPTX
Lecture-2-Python-Basic-Elements-Sep04-2018.pptx
PPTX
Basics of Python Programming
PPTX
Basic concept of Python.pptx includes design tool, identifier, variables.
python2oxhvoudhuSGFsughusgdogusuosFU.pdf
Lec2_cont.pptx galgotias University questions
03-Variables, Expressions and Statements (1).pdf
Pythonlearn-02-Expressions123AdvanceLevel.pptx
PPT_1_9102501a-a7a1-493e-818f-cf699918bbf6.pptx
Lecture-2-Python-Basic-Elements-Sep04-2018.pptx
Basics of Python Programming
Basic concept of Python.pptx includes design tool, identifier, variables.

Similar to PythonCourse_02_Expressions.ppt Python introduction turorial for beginner. (20)

PPTX
An Introduction : Python
PPTX
Intro to CS Lec03 (1).pptx
PPTX
Review of C programming language.pptx...
PDF
Introduction to Python for Plone developers
PPTX
Python Details Functions Description.pptx
PPTX
Python basics
PPTX
Python basics
PPTX
Python basics
PPTX
Python basics
PPTX
Python basics
PPTX
Python basics
PPTX
Python basics
PPTX
Python Basics by Akanksha Bali
PPT
Python
PPTX
PDF
Sessisgytcfgggggggggggggggggggggggggggggggg
PPT
Python programming
PPTX
java Basic Programming Needs
PPSX
Java Tutorial
PPTX
Python basics
An Introduction : Python
Intro to CS Lec03 (1).pptx
Review of C programming language.pptx...
Introduction to Python for Plone developers
Python Details Functions Description.pptx
Python basics
Python basics
Python basics
Python basics
Python basics
Python basics
Python basics
Python Basics by Akanksha Bali
Python
Sessisgytcfgggggggggggggggggggggggggggggggg
Python programming
java Basic Programming Needs
Java Tutorial
Python basics
Ad

Recently uploaded (20)

PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Cloud computing and distributed systems.
PDF
Sensors and Actuators in IoT Systems using pdf
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
GamePlan Trading System Review: Professional Trader's Honest Take
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Reach Out and Touch Someone: Haptics and Empathic Computing
NewMind AI Monthly Chronicles - July 2025
Advanced methodologies resolving dimensionality complications for autism neur...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
NewMind AI Weekly Chronicles - August'25 Week I
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Empathic Computing: Creating Shared Understanding
Review of recent advances in non-invasive hemoglobin estimation
Cloud computing and distributed systems.
Sensors and Actuators in IoT Systems using pdf
Ad

PythonCourse_02_Expressions.ppt Python introduction turorial for beginner.

  • 2. Copyright 2010- Charles Severance These slides are a derivative work based on the original slides, “Python for Informatics : Exploring Information”, created by Charles Severance. The original slides are located at www.pythonlearn.com This modified set of slides was done by John Alexander (2013). The primary purpose of this derivative work is to make the highest quality Python courseware available to instructors so that they can teach Python, and insure that the slides are properly formatted for easy, out-of-the-box, use by both Microsoft PowerPoint and OpenOffice Impress. Unless otherwise noted, the content of this course material is licensed under a Creative Commons Attribution 3.0 License (The “BY” variant of the license) http://creativecommons.org/licenses/by/3.0/. Creative Commons Attribution 3.0 License
  • 3. Constants • Fixed values such as numbers, letters, and strings are called “constants” - because their value does not change • Numeric constants are as you expect • String constants use single-quotes (') or double-quotes (") >>> print 123 123 >>> print 98.6 98.6 >>> print 'Hello world' Hello world
  • 4. Variables • A variable is a named place in the memory where a programmer can store data and later retrieve the data using the variable “name” • Programmers get to choose the names of the variables • You can change the contents of a variable in a later statement 12.2 12.2 x 14 14 y x = 12.2 y = 14 100 x = 100
  • 5. Python Variable Name Rules • Can consist of letters, numbers, or underscores (but cannot start with a number) • Case Sensitive • Good: spam eggs spam23 _speed • Bad: 23spam #sign var.12 • Different: spam Spam SPAM
  • 6. Reserved Words • You can NOT use reserved words as variable names / identifiers and del for is raise assert elif from lambda return break else global not try class except if or while continue exec import pass yield def finally in print
  • 7. Statements x = 2 x = x + 2 print x Variable Operator Constant Reserved Word Assignment Statement Assignment with expression Print statement
  • 8. Assignment Statements • We assign a value to a variable using the assignment statement (=) • An assignment statement consists of an expression on the right hand side and a variable to store the result x = 3.9 * x * ( 1 - x )
  • 9. x = 3.9 * x * ( 1 - x ) 0.6 0.6 x Right side is an expression. Once expression is evaluated, the result is placed in (assigned to) x. 0.6 0.6 0.4 0.936 A variable is a memory location used to store a value (0.6). 0.936 0.936 x
  • 10. x = 3.9 * x * ( 1 - x ) 0.6 0.93 0.6 0.93 x Right side is an expression. Once expression is evaluated, the result is placed in (assigned to) the variable on the left side (i.e. x). 0.93 A variable is a memory location used to store a value. The value stored in a variable can be updated by replacing the old value (0.6) with a new value (0.93).
  • 11. Numeric Expressions • Because of the lack of mathematical symbols on computer keyboards - we use “computer-speak” to express the classic math operations • Asterisk is multiplication • Exponentiation (raise to a power) looks different from in math. + Addition - Subtraction * Multiplication / Division ** Power % Remainder
  • 12. Numeric Expressions >>> x = 2 >>> x = x + 2 >>> print x 4 >>> y = 440 * 12 >>> print y 5280 >>> z = y / 1000 >>> print z 5 >>> j = 23 >>> k = j % 5 >>> print k 3 >>> print 4 ** 3 64 + Addition - Subtraction * Multiplication / Division ** Power % Remainder (Modulus) 5 23 4 R 3 20 3
  • 13. Order of Evaluation • When we string operators together - Python must know which one to do first • This is called “operator precedence” • Which operator “takes precedence” over the others x = 1 + 2 * 3 - 4 / 5 ** 6
  • 14. Operator Precedence Rules • Highest precedence rule to lowest precedence rule • Parenthesis are always respected • Exponentiation (raise to a power) • Multiplication, Division, and Remainder • Addition and Subtraction • Left to right Parenthesis Power Multiplication Addition Left to Right
  • 16. Parenthesis Power Multiplication Addition Left to Right x = 1 + 2 ** 3 / 4 * 5 1 + 2 ** 3 / 4 * 5 1 + 8 / 4 * 5 1 + 2 * 5 1 + 10 11 Note 8/4 goes before 4*5 because of the left- right rule.
  • 17. Operator Precedence • Remember the rules -- top to bottom • When writing code - use parenthesis • When writing code - keep mathematical expressions simple enough that they are easy to understand • Break long series of mathematical operations up to make them more clear Parenthesis Power Multiplication Addition Left to Right Exam Question: x = 1 + 2 * 3 - 4 / 5
  • 18. Integer Division • Integer division truncates • Floating point division produces floating point numbers >>> print 10 / 2 5 >>> print 9 / 2 4 >>> print 99 / 100 0 >>> print 10.0 / 2.0 5.0 >>> print 99.0 / 100.0 0.99 This changes in Python 3.0
  • 19. Mixing Integer and Floating Numbers in Arithmetic Expressions • When you perform an operation where one operand is an integer and the other operand is a floating point the result is a floating point • The integer is converted to a floating point before the operation >>> print 99 / 100 0 >>> print 99 / 100.0 0.99 >>> print 99.0 / 100 0.99 >>> print 1 + 2 * 3 / 4.0 - 5 -2.5 >>>
  • 20. Some Data Types in Python • Integer (Examples: 0, 12, 5, -5) • Float (Examples: 4.5, 3.99, 0.1 ) • String (Examples: “Hi”, “Hello”, “Hi there!”) • Boolean (Examples: True, False) • List (Example: [ “hi”, “there”, “you” ] ) • Tuple (Example: ( 4, 2, 7, 3) )
  • 21. Data Types • In Python variables, literals, and constants have a “data type” • In Python variables are “dynamically” typed. In some other languages you have to explicitly declare the type before you use the variable In C/C++: int a; float b; a = 5 b = 0.43 In Python: a = 5 a = “Hello” a = [ 5, 2, 1]
  • 22. More on “Types” • In Python variables, literals, and constants have a “type” • Python knows the difference between an integer number and a string • For example “+” means “addition” if something is a number and “concatenate” if something is a string >>> d = 1 + 4 >>> print d 5 >>> e = 'hello ' + 'there' >>> print e hello there concatenate = put together
  • 23. Type Matters • Python knows what “type” everything is • Some operations are prohibited • You cannot “add 1” to a string • We can ask Python what type something is by using the type() function. >>> e = 'hello ' + 'there' >>> e = e + 1 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: cannot concatenate 'str' and 'int' objects >>> type(e) <type 'str'> >>> type('hello') <type 'str'> >>> type(1) <type 'int'> >>>
  • 24. Several Types of Numbers • Numbers have two main types • Integers are whole numbers: -14, - 2, 0, 1, 100, 401233 • Floating Point Numbers have decimal parts: -2.5 , 0.0, 98.6, 14.0 • There are other number types - they are variations on float and integer >>> x = 1 >>> type (x) <type 'int'> >>> temp = 98.6 >>> type(temp) <type 'float'> >>> type(1) <type 'int'> >>> type(1.0) <type 'float'> >>>
  • 25. Type Conversions • When you put an integer and floating point in an expression the integer is implicitly converted to a float • You can control this with the built in functions int() and float() >>> print float(99) / 100 0.99 >>> i = 42 >>> type(i) <type 'int'> >>> f = float(i) >>> print f 42.0 >>> type(f) <type 'float'> >>> print 1 + 2 * float(3) / 4 - 5 -2.5 >>>
  • 26. String Conversions • You can also use int() and float() to convert between strings and integers • You will get an error if the string does not contain numeric characters >>> sval = '123' >>> type(sval) <type 'str'> >>> print sval + 1 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: cannot concatenate 'str' and 'int' >>> ival = int(sval) >>> type(ival) <type 'int'> >>> print ival + 1 124 >>> nsv = 'hello bob' >>> niv = int(nsv) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid literal for int()
  • 27. User Input • We can instruct Python to pause and read data from the user using the raw_input() function • The raw_input() function returns a string name = raw_input(‘Who are you?’) print 'Welcome ', name Who are you? Chuck Welcome Chuck
  • 28. Converting User Input • If we want to read a number from the user, we must convert it from a string to a number using a type conversion function • Later we will deal with bad input data inp = raw_input(‘Europe floor?’) usf = int(inp) + 1 print “US floor: ”, usf Europe floor? 0 US floor : 1
  • 29. Comments in Python • Anything after a # is ignored by Python • Why comment? • Describe what is going to happen in a sequence of code • Document who wrote the code or other ancillary information • Turn off a line of code - perhaps temporarily
  • 30. # Get the name of the file and open it name = raw_input("Enter file:") handle = open(name, "r") # This is a file handle text = handle.read() words = text.split()
  • 31. String Operations • Some operators apply to strings • + implies “concatenation” • * implies “multiple concatenation” • Python knows when it is dealing with a string or a number and behaves appropriately >>> print 'abc' + '123‘ Abc123 >>> print 'Hi' * 5 HiHiHiHiHi
  • 32. Mnemonic Variable Names • Since we programmers are given a choice in how we choose our variable names, there is a bit of “best practice” • We name variables to help us remember what we intend to store in them (“mnemonic” = “memory aid”) • This can confuse beginning students because well named variables often “sound” so good that they must be keywords
  • 33. x1q3z9ocd = 35.0 x1q3z9afd = 12.50 x1q3p9afd = x1q3z9ocd * x1q3z9afd print x1q3p9afd hours = 35.0 rate = 12.50 pay = hours * rate print pay a = 35.0 b = 12.50 c = a * b print c What is this code doing?
  • 34. Exercise Write a program to prompt the user for hours and rate per hour to compute gross pay. Enter Hours: 35 Enter Rate: 2.75 Pay: 96.25
  • 35. Summary • Types (int, float, boolean, string, list, tuple, …) • Reserved words • Variables (mnemonic) • Operators and Operator precedence • Division (integer and floating point) • Conversion between types • User input • Comments (#)

Editor's Notes

  • #6: Like a dog .... food ... food ...