At the end of this lesson, you will be able to:
A3.2 write subprograms (e.g., functions, procedures) that use parameter passing and appropriate variable scope (e.g., local, global), to perform tasks within programs.
A4.1 demonstrate the ability to identify and correct syntax, logic, and run-time errors in computer programs;
A4.3 demonstrate the ability to interpret error messages displayed by programming tools (e.g., compiler, debugging tool), at different times during the software development process (e.g., writing, compilation, testing) ;
A4.4 use a tracing technique to understand pro - gram flow and to identify and correct logic and run-time errors in computer programs;
B1.1 use various problem-solving strategies (e.g., stepwise refinement, divide and conquer, working backwards, examples, extreme cases, tables and charts, trial and error) when solving different types of problems;
use local and global variables in a program
find errors in a program and classify the type of error
With a pencil and paper, answer the following questions:
What does each of the following code output?
a) print(10-2**3)
b)print("{:.3f}".format(0.462519))
d) print("The remainder of 10/3 is {}.".format(10%3))
e) print ("8 - 4 / 2 = {}". format(8-4/2))
Explain the difference between a constant and a variable.
Declare a constant called "MAX_LIVES" as an integer with a value of 3 in Python and C++. Make sure to put a comment above the line.
Declare a variable called "username" as a string with a value of "Guest" in Python and C++. Make sure to put a comment above the line.
Why do we need test cases?
Create 1 test case for a program that calculates and displays the area of a triangle (Note: A = base * height / 2). Make sure to include units.
What is pseudocode?
Create the top-down design, flowchart and pseudocode for a program that asks the user for number of answers they got correct and the total questions asked. It then tells them the percentage they got on the test.
storyboard, top-down design, flowcharts & pseudocode
variables vs constants
read "Python Local, Glocal and Nonlocal Variables"
watch the video within
what are global variables in Python?
global variables can be seen throughout the entire program
go over setting breakpoints and stepping through a program with the debugger
go over types of errors:
i.e. mispelling a variable name or function name inPython
i.e. forgetting a ";" at the end of a line in C++
i.e. calculating the "area" of a rectangle but your program states that it is displaying the "perimeter"
i.e. dividing by 0 in your calculation, which will make your program crash
i.e. having an infinite loop in a program that never ends
from the online book Computer Based Problem Solving by Patrick Coxall, read:
create the program in Python
complete the Daily Assignment section in Hãpara Workspace for this day
if Hãpara is not working, make a copy of this document
move it to your IMH-ICS folder for this course
recreate the program above in C++
set breakpoints and step through it with the debugger to understand what is happening