Week 1-5 Flashcards
What is computer programming?
The process of explaining how to solve a problem in a way that a computer can understand. Which can be referred to as an “algorithm”.
What is an algorithm?
An algorithm is a precise and unambiguous ordered list of instructions that eventually ends with a correct solution.
What is the proper Problem Solving Strategy?
Define (IPO Chart), Design (Pseudo Code & Flow Chart), Test, Implement (Programming Language), Test.
We cannot solve problems we don’t understand. Understanding a problem begins with defining it. How do we define a problem?
To define a problem we need to identify 3 parts: the input, the process to follow, and the output.
Define the Input stage of an IPO.
input: information we know that helps solve the problem.
Define the processing stage of an IPO.
Processing: the algorithm that takes us from input to output.
Define the output stage of an IPO.
output: the result we want to solve for.
What is the purpose of an IPO chart?
An IPO chart helps organize our thinking so we don’t get confused - this stage can be considered brainstorming.
Does the IPO chart use detailed information?
No, the IPO chart helps define a general solution to a problem, you don’t include the specific date from the problem. That way, you can use the same IPO chart regardless how many times the input values change.
What is pseudocode?
Once we know what information is available, and what is required as output we can design an algorithm to solve the problem. We do this in a language which is less open to interpretation than english but is also less formal than a programming language. We call this language pseudocode.
What are some verbs used in the input stage of pseudocode?
Read, Get, Obtain… etc
What are some verbs used in the processing stage of pseudocode?
Compute, Calculate, Set…etc
What are some verbs used in the output stage of pseudocode?
Print, Display, Show….etc
Why do we build flow charts?
It is often helpful to visualize a design with a flow chart.
How is a flow chart designed?
We use circles to identify the start and end of the algorithm, and rectangles to contain the pseudocode instructions.
What are the orders of a design?
1 - IPO Chart 2 - Pseudocode & Assumptions 3 - Flow Chart 4 - TRACE or Truth Table 5 - Code & Test
How can we develop confidence that our design solves the problem?
We must test the design carefully: first with any sample values and then with any other possible values.
When designing tests we need to be very clear on what we are trying to accomplish. What are the 3 main things we test for?
- test that our code works as expected.
- test that our code works reasonably when bad values are put in.
- test that we have explored all the paths through our code.
What is a variable?
- the part of a program that can “remember” values.
- boxes in memory that can hold 1 thing at a time
ex. length = 3, word = “hello”
What is an expression?
- any piece of code that provides a value.
ex. 3, 3 + 2, x > 10, “Hi”, len( “hi” )
What is a statement?
- the smallest complete action of a program.
- comparable to a sentence.
ex. print( “hello” )
What does an input expression look like?
input( “What is your name? “ )
What is a literal?
A value that is explicitly defined in your source code is called a literal.
What is the primary difference between a literal and a variable?
The variable may change over the course of the program’s execution. A literal will remain the same.
What would a literal statement look like?
myNumber = 15
myNumber is a variable and 15 is a literal.
What does an assignment statement look like?
variableName = expression.
what does “=” mean?
this means “save to” or “assign to”, which is used to attach an expression to a variable. it does not mean equals to**
in python what is this statement saying;
x - 2 = 3
- load the value of x from memory.
- subtract 2 from that value.
- save the number 3 into the number 3 into the number you just calculated.
how to you say equals to in python?
==
how does python go through the execution process when it runs a program?
It is important to note that the program runs one line at a time from start to finish. There are no automatic actions, everything is specified.
What are the rules of python variable names?
- must begin with a letter or underscore.
- may contain numbers.
- are case sensitive.
- is not one of Python’s reserved keywords.
What is the most common method of giving an output to the screen?
The print statement;
print( “hello world” )
What are strings?
A string is a data type, defined as a sequence of characters contained between a pair of quotation marks. Note that characters can have letters, number or symbols, but they are always read as text.
what are the two style types for variable naming convention?
my_name
myName
What are the 4 Data Types?
Boolean Values
Integer Numbers
Real Numbers
Strings
What is a boolean data type?
boolean - true or false
what is an integer data type?
int - numbers without decimals
what is a real number data type?
float - numbers with decimals
what is a string data type?
str - characters enclosed in quotes
Can you mix data types?
Absolutely not
What does precedence mean?
Order of operations
What are the arithmetic operations in python from highest ranking to lowest.
1: () brackets trump all
2: ** exponents
3: - negation
4: * multiplication
4: / division
4: // integer division
4: %modulo (remainder)
5: + addition
5: - subtraction
** NOTE that there are many on the 4th and 2 on the 5th line of importance.. They have equal importance and are read from left to right **
What is the symbol to represent exponents in python?
**
What is the symbol to represent multiplication in python?
*
What is the symbol to represent division in python?
/
What is the symbol to represent integer division in python?
//
What is the symbol to represent modulo (remainders) in python?
%
What is the symbol to represent addition in python?
+
What is the symbol to represent substraction in python?
-
What are the Relational operations in python.
> Greater than >= Greater than or equals < Less than <= Less than or equals == Equal to != Not equal to **ALWAYS TRUE OR FALSE**
Where do you find the ranking of all python symbols?
ASCII Chart
is “a > A > 3” true or false?
This is true
For boolean operators, what does the “and” truth table look like?
a | b | a and b true | true | true true | false | false false | true | false false | false | false
for boolean operators, what does the “or” truth table look like?
a | b | a and b true | true | true true | false | true false | true | true false | false | false
for boolean operators, what does the “not” truth table look like?
a | not
false | true
true | false
What is Demorgan’s Law?
not (a and b) = not(a) or not (b)
not (a or b) = not(a) and not (b)
What is the symbol to represent “greater than” in python?
>
What is the symbol to represent “greater or equals” in python?
> =
What is the symbol to represent “less than” in python?
What is the symbol to represent “less or equals” in python?
<=
What is the symbol to represent “equal to” in python?
==
What is the symbol to represent “not equal to” in python?
!=
What are the string operations in python.
\+ Concatenation * Repitition [n] Substring (slice) [m:n] Substring (slice) in Membership
What is the symbol to represent “concatenation” and how does it work?
+
“hi” + “there” == “hithere”
What is the symbol to represent “repetition” and how does it work?
*
“hi” * 2 == “hihi”
What is the symbol to represent “single substring slice” and how does it work?
[n]
“hello” [1] Gives “e”
What is the symbol to represent “multi substring slice” and how does it work?
[m:n]
“hello” [1:4] Gives “ello”
What are the Grouping Priorities in python from highest ranking to lowest.
1 - String (slice, concatenation) 2 - Arithmetic and String repetition 3 - Relational & String membership 4 - Logical 5 - Assignment
Whats the main rule when dealing with exponents in python?
ALWAYS USE BRACKETS
What are operators?
operators are symbols that represent functions, the data they work with are called operands.
in the expression 3 + 5, what are the operands and what is the operator?
3 and 5 are operands, + is the operator.
What is string concatenation?
you use the plus sign (+) to join strings together.
What do you need to watch out for when dealing with integer division?
Caution: integer division can act unexpectedly if one of the operands is negative - it will always round AWAY from 0.
eg. -12//5 is -3
What is the precedence (order of operations) for boolean operators?
not, and, or… respectively
Can you use 0 and 1 to mean true and false?
ABSOLUTELY NOT
what is the general structure of the IF statement?
if boolean-expressions:
code block
(if the boolean expression evaluates to true then the statements in the indented code block should be run.)
What does an if-else statement look like?
if boolean-expression: code block else: code block (this gives us a basic "this or that" decision making pattern)
what does an if-elif-else statement look like?
if boolean-expression: code block elif boolean-expression: code block else: code block (you may have several elif statements with their own condition. the else statement can be left out if your logic doesn't require it.)