02 Slide
02 Slide
# Display results
print("The area for the circle of radius“,
radius, " is "area)
# Display results
print("The area for the circle of radius",
radius, "is", area)
var = eval(stringVariable)
ComputeAreaWithConsoleInput ComputeAverage
Run Run
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved.
8
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
x = 3.9 * x * ( 1 - x )
0.6 0.6
x = 3.9 * x * ( 1 - x )
0.4
x = 3.9 * x * ( 1 - x )
x = x + 1
i = j = k = 1
x, y = y, x # Swap x with y
ComputeAverageWithSimultaneousAssignment
Run
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved.
20
Named Constants
The value of a variable may change during the
execution of a program, but a named constant or
simply constant represents permanent data that
never changes. Python does not have a special
syntax for naming constants. You can simply
create a variable to denote a constant. To
distinguish a constant from a variable, use all
uppercase letters to name a constant.
integer: e.g., 3, 4
float: e.g., 3.0, 4.0
+ Addition 34 + 1 35
// Integer Division 1 // 2 0
% Remainder 20 % 3 2
2 3 3 1 Quotient
3 7 4 12 8 26 Divisor 13 20 Dividend
6 12 24 13
1 0 2 7 Remainder
DisplayTime Run
>>>245.0 ** 1000
OverflowError: 'Result too large'
is translated to
Parenthesis
Power 1 + 10
Multiplication
Addition 11
Left to Right
round(4.6) => 5
round(4.5) => 4
SalesTax Run
System
Analysis
System
Design
Implementation
Testing
Deployment
Maintenance
Implementation
Testing
Implementation
Testing
Part of the analysis entails modeling
the system’s behavior. The model is
Deployment
intended to capture the essential
elements of the system and to define
Maintenance
services to the system.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved.
45
System Design
Requirement
Specification
The process of designing the
system’s components.
System
Analysis
System
Design
Implementation
Testing
System
Analysis Input, Process, Output
System
Design
Implementation
Testing
Maintenance
Implementation
Testing
This phase requires the use of a
programming language like Python. Deployment
The implementation involves
coding, testing, and debugging. Maintenance
Implementation
Testing
An independent team of software
engineers not involved in the design Deployment
and implementation of the project
usually conducts such testing. Maintenance
System
Design
Implementation
Testing
Deployment
Maintenance
Implementation
Testing
A software product must continue to
perform and improve in a changing Deployment
environment. This requires periodic
upgrades of the product to fix newly Maintenance
discovered bugs and incorporate changes.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved.
51
Problem:
Computing Loan Payments
This program lets the user enter the interest
rate, number of years, and loan amount, and
computes monthly payment and total
payment.
loanAmount monthlyInterestRate
monthlyPayment =
1− 1
(1 + monthlyInterestRate) numberOfYears12
ComputeLoan Run
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved.
52
Case Study: Computing Distances
ComputeDistance Run
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved.
53
Case Study: Computing Distances
ComputeDistanceGraphics Run
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved.
54