SlideShare uma empresa Scribd logo
1 de 24
An Introduction To Software
Development Using Python
Spring Semester, 2014
Class #16:
Problem Solving:
Flowcharts & Test
Cases, Boolean
Variables & Operators
What Is A Flowchart?
• A flowchart shows the
structure of decisions and
tasks that are required to
solve a problem.
• When you have to solve a
complex problem, it is a
good idea to draw a
flowchart to visualize the
flow of control.
Flowcharts: The Basic Idea
• Link tasks and input/output boxes in the sequence in which they should
be executed.
• Whenever you need to make a decision, draw a diamond with two
outcomes.
• Each branch can contain a sequence of tasks and even additional
decisions.
Flowcharts: Multiple Decisions
• If there are multiple
choices for a value, use
multiple diamonds.
Avoiding “Spaghetti Code”
• Unconstrained branching and merging can lead to
“spaghetti code”.
• Spaghetti code is a messy network of possible
pathways through a program.
• There is a simple rule for avoiding spaghetti code:
Never point an arrow inside another branch.
Image Credit: beni.hourevolution.org
Spaghetti Code Example
• Shipping costs are $5 inside the United States.
• Except that to Hawaii and Alaska they are $10.
• International shipping costs are also $10.
Need to add Hawaii &
Alaska shipping…
Spaghetti Code Example
• You may be tempted to reuse the “shipping cost = $10” task.
• Don’t do that! The red arrow points inside a different branch
Spaghetti Code Example
• Instead, add another task that sets the
shipping cost to $10
Flowchart Limits
• Flowcharts can be very
useful for getting an intuitive
understanding of the flow of
an algorithm.
• However, they get large
rather quickly when you add
more details.
• At that point, it makes sense
to switch from flowcharts to
pseudocode.
Verifying Code: Test Cases
• How would you test this program?
– Can’t test all possible martial status / income values
• If the program correctly computes one or two tax amounts in a given
bracket, then we have good reason to believe that all amounts will be
correct.
• You want to aim for complete coverage of all decision points.
Image Credit: theauthorsblogg.wordpress.com
Create A Testing Plan
• A plan for obtaining a comprehensive set of test
cases:
– There are two possibilities for the marital status and two
tax brackets for each status, yielding four test cases.
– Test a handful of boundary conditions, such as an income
that is at the boundary between two brackets, and a zero
income.
– Also test an invalid input, such as a negative income.
Image Credit: www.fotosearch.com
Planning Your Testing
• Make a list of the test cases and the expected
outputs:
Image Credit: www.canstockphoto.com
Use Flowcharts To Plan Tests
X
X X
X
X
Note: It is always a good idea to design
test cases before starting to code.
Working through the test cases gives
you a better understanding of the
algorithm that you are about to
implement.
Boolean Variables
• Sometimes, you need to evaluate a logical condition
in one part of a program and use it elsewhere.
• To store a condition that can be true or false, you use a Boolean variable.
• In Python, the bool data type has exactly two values, denoted False and
True.
• These values are not strings or integers; they are special values, just for
Boolean variables.
• Example:
Here is the initialization of a variable set to True:
failed = True
You can use the value later in your program to make a decision:
if failed : # Only executed if failed has been set to true
Image Credit: www.sourcecon.com
Boolean Operators
• When you make complex decisions, you often need
to combine Boolean values.
• An operator that combines Boolean conditions is
called a Boolean operator.
• In Python, the and operator yields True only when
both conditions are true.
• The or operator yields True if at least one of the
conditions is true.
Image Credit: www.java-n-me.com
Boolean Truth Table
Image Credit: www.clipartpanda.com
Boolean Example: And
• Write a program that processes temperature values.
• You want to test whether a given temperature corresponds to liquid water.
• At sea level, water freezes at 0 degrees Celsius and boils at 100 degrees.
• Water is liquid if the temperature is greater than zero and less than 100:
if temp > 0 and temp < 100 :
print("Liquid")
Boolean Example: Or
if temp <= 0 or temp >= 100 :
print("Not liquid")
Boolean Precedence
• The Boolean operators and and or have a lower precedence
than the relational operators.
• For that reason, you can write relational expressions on either
side of the Boolean operators without using parentheses.
• For example, in the expression
temp > 0 and temp < 100
the expressions temp > 0 and temp < 100
are evaluated fist. Then the and operator
combines the results
Image Credit: www.dreamstime.com
Invert A Condition
• Sometimes you need to invert a condition
with the not Boolean operator.
• The not operator takes a single condition and
evaluates to True if that condition is false and
to False if the condition is true.
if not frozen :
print("Not frozen")
Image Credit: www.clipartpanda.com
Boolean Operator Examples
Image Credit: industry-illustration.com
What’s In Your Python Toolbox?
print() math strings I/O IF/Else elif While For
Lists And / Or
What We Covered Today
1. Flowcharts
2. Creating testing plans
3. Boolean variables
4. Boolean operators
Image Credit: http://www.tswdj.com/blog/2011/05/17/the-grooms-checklist/
What We’ll Be Covering Next Time
1. Functions, Part 1
Image Credit: http://merchantblog.thefind.com/2011/01/merchant-newsletter/resolve-to-take-advantage-of-these-5-e-commerce-trends/attachment/crystal-ball-fullsize/

Mais conteúdo relacionado

Semelhante a An Introduction To Python - Problem Solving: Flowcharts & Test Cases, Boolean Variables & Operators

Cse115 lecture03problemsolving
Cse115 lecture03problemsolvingCse115 lecture03problemsolving
Cse115 lecture03problemsolvingMd. Ashikur Rahman
 
Intro To C++ - Class 12 - For, do … While
Intro To C++ - Class 12 - For, do … WhileIntro To C++ - Class 12 - For, do … While
Intro To C++ - Class 12 - For, do … WhileBlue Elephant Consulting
 
classVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxclassVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxssusere336f4
 
Test Coverage: An Art and a Science
Test Coverage: An Art and a ScienceTest Coverage: An Art and a Science
Test Coverage: An Art and a ScienceTeamQualityPro
 
Intro To C++ - Class 10 - Control Statements: Part 2
Intro To C++ - Class 10 - Control Statements: Part 2Intro To C++ - Class 10 - Control Statements: Part 2
Intro To C++ - Class 10 - Control Statements: Part 2Blue Elephant Consulting
 
An Introduction To Software Development - Final Review
An Introduction To Software Development - Final ReviewAn Introduction To Software Development - Final Review
An Introduction To Software Development - Final ReviewBlue Elephant Consulting
 
Python-Certification-Training-Day-1-2.pptx
Python-Certification-Training-Day-1-2.pptxPython-Certification-Training-Day-1-2.pptx
Python-Certification-Training-Day-1-2.pptxmuzammildev46gmailco
 
'A critique of testing' UK TMF forum January 2015
'A critique of testing' UK TMF forum January 2015 'A critique of testing' UK TMF forum January 2015
'A critique of testing' UK TMF forum January 2015 Georgina Tilby
 
SE UNIT 5 part 2 (1).pptx
SE UNIT 5 part 2 (1).pptxSE UNIT 5 part 2 (1).pptx
SE UNIT 5 part 2 (1).pptxPraneethBhai1
 
2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life CycleFrankie Jones
 
Intro To C++ - Class 09 - Control Statements: Part 1
Intro To C++ - Class 09 - Control Statements: Part 1Intro To C++ - Class 09 - Control Statements: Part 1
Intro To C++ - Class 09 - Control Statements: Part 1Blue Elephant Consulting
 
Entity matching of web offers, from html to similarity score.
Entity matching of web offers, from html to similarity score. Entity matching of web offers, from html to similarity score.
Entity matching of web offers, from html to similarity score. Paul Puget
 
Java developer trainee implementation and import
Java developer trainee implementation and importJava developer trainee implementation and import
Java developer trainee implementation and importiamluqman0403
 
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
 
Web technologies-course 08.pptx
Web technologies-course 08.pptxWeb technologies-course 08.pptx
Web technologies-course 08.pptxStefan Oprea
 

Semelhante a An Introduction To Python - Problem Solving: Flowcharts & Test Cases, Boolean Variables & Operators (20)

Testing
TestingTesting
Testing
 
Cse115 lecture03problemsolving
Cse115 lecture03problemsolvingCse115 lecture03problemsolving
Cse115 lecture03problemsolving
 
Intro To C++ - Class 12 - For, do … While
Intro To C++ - Class 12 - For, do … WhileIntro To C++ - Class 12 - For, do … While
Intro To C++ - Class 12 - For, do … While
 
classVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxclassVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptx
 
An Introduction To Python - WHILE Loop
An Introduction To  Python - WHILE LoopAn Introduction To  Python - WHILE Loop
An Introduction To Python - WHILE Loop
 
Test Coverage: An Art and a Science
Test Coverage: An Art and a ScienceTest Coverage: An Art and a Science
Test Coverage: An Art and a Science
 
Intro To C++ - Class 10 - Control Statements: Part 2
Intro To C++ - Class 10 - Control Statements: Part 2Intro To C++ - Class 10 - Control Statements: Part 2
Intro To C++ - Class 10 - Control Statements: Part 2
 
An Introduction To Software Development - Final Review
An Introduction To Software Development - Final ReviewAn Introduction To Software Development - Final Review
An Introduction To Software Development - Final Review
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
Python-Certification-Training-Day-1-2.pptx
Python-Certification-Training-Day-1-2.pptxPython-Certification-Training-Day-1-2.pptx
Python-Certification-Training-Day-1-2.pptx
 
'A critique of testing' UK TMF forum January 2015
'A critique of testing' UK TMF forum January 2015 'A critique of testing' UK TMF forum January 2015
'A critique of testing' UK TMF forum January 2015
 
SE UNIT 5 part 2 (1).pptx
SE UNIT 5 part 2 (1).pptxSE UNIT 5 part 2 (1).pptx
SE UNIT 5 part 2 (1).pptx
 
2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle
 
Intro To C++ - Class 09 - Control Statements: Part 1
Intro To C++ - Class 09 - Control Statements: Part 1Intro To C++ - Class 09 - Control Statements: Part 1
Intro To C++ - Class 09 - Control Statements: Part 1
 
Entity matching of web offers, from html to similarity score.
Entity matching of web offers, from html to similarity score. Entity matching of web offers, from html to similarity score.
Entity matching of web offers, from html to similarity score.
 
Java developer trainee implementation and import
Java developer trainee implementation and importJava developer trainee implementation and import
Java developer trainee implementation and import
 
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
 
linear optimization.pptx
linear optimization.pptxlinear optimization.pptx
linear optimization.pptx
 
Web technologies-course 08.pptx
Web technologies-course 08.pptxWeb technologies-course 08.pptx
Web technologies-course 08.pptx
 

Último

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 

Último (20)

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 

An Introduction To Python - Problem Solving: Flowcharts & Test Cases, Boolean Variables & Operators

  • 1. An Introduction To Software Development Using Python Spring Semester, 2014 Class #16: Problem Solving: Flowcharts & Test Cases, Boolean Variables & Operators
  • 2. What Is A Flowchart? • A flowchart shows the structure of decisions and tasks that are required to solve a problem. • When you have to solve a complex problem, it is a good idea to draw a flowchart to visualize the flow of control.
  • 3. Flowcharts: The Basic Idea • Link tasks and input/output boxes in the sequence in which they should be executed. • Whenever you need to make a decision, draw a diamond with two outcomes. • Each branch can contain a sequence of tasks and even additional decisions.
  • 4. Flowcharts: Multiple Decisions • If there are multiple choices for a value, use multiple diamonds.
  • 5. Avoiding “Spaghetti Code” • Unconstrained branching and merging can lead to “spaghetti code”. • Spaghetti code is a messy network of possible pathways through a program. • There is a simple rule for avoiding spaghetti code: Never point an arrow inside another branch. Image Credit: beni.hourevolution.org
  • 6. Spaghetti Code Example • Shipping costs are $5 inside the United States. • Except that to Hawaii and Alaska they are $10. • International shipping costs are also $10. Need to add Hawaii & Alaska shipping…
  • 7. Spaghetti Code Example • You may be tempted to reuse the “shipping cost = $10” task. • Don’t do that! The red arrow points inside a different branch
  • 8. Spaghetti Code Example • Instead, add another task that sets the shipping cost to $10
  • 9. Flowchart Limits • Flowcharts can be very useful for getting an intuitive understanding of the flow of an algorithm. • However, they get large rather quickly when you add more details. • At that point, it makes sense to switch from flowcharts to pseudocode.
  • 10. Verifying Code: Test Cases • How would you test this program? – Can’t test all possible martial status / income values • If the program correctly computes one or two tax amounts in a given bracket, then we have good reason to believe that all amounts will be correct. • You want to aim for complete coverage of all decision points. Image Credit: theauthorsblogg.wordpress.com
  • 11. Create A Testing Plan • A plan for obtaining a comprehensive set of test cases: – There are two possibilities for the marital status and two tax brackets for each status, yielding four test cases. – Test a handful of boundary conditions, such as an income that is at the boundary between two brackets, and a zero income. – Also test an invalid input, such as a negative income. Image Credit: www.fotosearch.com
  • 12. Planning Your Testing • Make a list of the test cases and the expected outputs: Image Credit: www.canstockphoto.com
  • 13. Use Flowcharts To Plan Tests X X X X X Note: It is always a good idea to design test cases before starting to code. Working through the test cases gives you a better understanding of the algorithm that you are about to implement.
  • 14. Boolean Variables • Sometimes, you need to evaluate a logical condition in one part of a program and use it elsewhere. • To store a condition that can be true or false, you use a Boolean variable. • In Python, the bool data type has exactly two values, denoted False and True. • These values are not strings or integers; they are special values, just for Boolean variables. • Example: Here is the initialization of a variable set to True: failed = True You can use the value later in your program to make a decision: if failed : # Only executed if failed has been set to true Image Credit: www.sourcecon.com
  • 15. Boolean Operators • When you make complex decisions, you often need to combine Boolean values. • An operator that combines Boolean conditions is called a Boolean operator. • In Python, the and operator yields True only when both conditions are true. • The or operator yields True if at least one of the conditions is true. Image Credit: www.java-n-me.com
  • 16. Boolean Truth Table Image Credit: www.clipartpanda.com
  • 17. Boolean Example: And • Write a program that processes temperature values. • You want to test whether a given temperature corresponds to liquid water. • At sea level, water freezes at 0 degrees Celsius and boils at 100 degrees. • Water is liquid if the temperature is greater than zero and less than 100: if temp > 0 and temp < 100 : print("Liquid")
  • 18. Boolean Example: Or if temp <= 0 or temp >= 100 : print("Not liquid")
  • 19. Boolean Precedence • The Boolean operators and and or have a lower precedence than the relational operators. • For that reason, you can write relational expressions on either side of the Boolean operators without using parentheses. • For example, in the expression temp > 0 and temp < 100 the expressions temp > 0 and temp < 100 are evaluated fist. Then the and operator combines the results Image Credit: www.dreamstime.com
  • 20. Invert A Condition • Sometimes you need to invert a condition with the not Boolean operator. • The not operator takes a single condition and evaluates to True if that condition is false and to False if the condition is true. if not frozen : print("Not frozen") Image Credit: www.clipartpanda.com
  • 21. Boolean Operator Examples Image Credit: industry-illustration.com
  • 22. What’s In Your Python Toolbox? print() math strings I/O IF/Else elif While For Lists And / Or
  • 23. What We Covered Today 1. Flowcharts 2. Creating testing plans 3. Boolean variables 4. Boolean operators Image Credit: http://www.tswdj.com/blog/2011/05/17/the-grooms-checklist/
  • 24. What We’ll Be Covering Next Time 1. Functions, Part 1 Image Credit: http://merchantblog.thefind.com/2011/01/merchant-newsletter/resolve-to-take-advantage-of-these-5-e-commerce-trends/attachment/crystal-ball-fullsize/

Notas do Editor

  1. 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.