Part 3 - Decision Structures

This section will introduce you to one of the most fundamentally important concepts in programming. The use of decision structures. You can have your program respond to different situations in different ways.

Back to main

What to do/Hand in

Decision Structures

1 - Read and work through "Part 3 - Decision Structures"

2 - Read through and complete Chapter 3 - Quiz Games and If Statements of ProgramArcadeGames.com

3 - Complete the Part 3 - Worksheet and hand it in. For this worksheet, you may write out the code by hand, or submit a program with the code implemented.

4 - Complete Exercise 3: Writing your own program.

5 - Upgrade your chatbot to version 1.1 using what you have learned in this section as described below.

Submit:

  1. Part 3 Worksheet

  2. Your Own Quiz program.

      • Make sure to meet the specified requirements

  3. Chatbot V1.1

      • Upgrade your Chatbot program from Part 2 using some of the skills you have learned in this chapter to make it even more convincing.

      • See below for details.

Here is a link to the Python Math API where you can see all of the available mathematical functions available to you as long as you import the Math Library using the line of code at the beginning of your program:

import math

Part 3 - Decision Structures.pdf

Chatbot V1.1

Part 3 - Chatbot v1.1.pdf

Hints and FAQ's

1 - When using "and" and "or" to combine boolean statements, you must provide complete statements that the computer can evaluate to be either True or False.

For example, the following statement:

if age > 12 and < 20:

print("You are a teenager")

does not work because the second part of the compound boolean statement ('<20') doesn't provide the computer with anything to compare 20 with.

The computer will not assume that you want to compare '20' to the variable age as you did with the number 12.

Here is what the above if statement should look like:

if age > 12 and age < 20:

print("You are a teenager")


2 - The assignment (=) and equality (==) operators are NOT interchangeable. Do not use the assignment operator; a single equal sign (=) in the condition of an 'if 'statement.

If you want the computer to test equality, you must use a double equal sign (==).


FAQ

Q: I copied and pasted the code from the chapter but it doesn't work. Why?

A: Levels of indentation determine whether code is inside various structures like 'if' statements. Sometimes copying code from a document or a web site messes up the tabs. You may need to make sure that they are where they should be.