CHAPTER 3 Intro to Programming Flashcards

(93 cards)

1
Q

In coding, IDLE, the color-coded text represents_____ and all the text that comes after “»” represents the______.

A

code output of the interactive shell

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Courier New is a type of fix-width (non-proportional) font often used to display programming text why ?

A

because each character has the same width, so indentation and other display characteristics of code alignment are easier to observe.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain what a comment is?

A

A comment is a line (or part of a line) of code written in English (or another language) preceded by a special symbol that tells the programming language you are using to ignore that line (or part of a line) of code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In Python, what symbol is used to create comment

A

pound symbol

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does a comment explain?

A

It explain what a line of code does

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Programmers use comments to

A

clarify why they did something to make the line of code easier to understand for whoever

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What can you write in a ‘COMMENT’?

A

You can write whatever you want in a comment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How long should the “comment” be

A

as long as it is only ONE LINE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When should you use comments

A

Use comments sparingly; do not comment on every line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Explain the use of a comment like this:

d = math.sqrt(l2 + w2) # length of the diagonal

A

Even if you understood exactly how this code works , you
still might not know how to calculate the length of a diagonal of a rectangle, which is why this
comment is useful.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Python programs are divided into

A

lines of code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Print is indented by how many spaces?

A

4 spaces

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Without proper _____, your program will not work.

A

spacing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Different kinds of data in Python are grouped into different

A

categories, or data types .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In python, each data value, like 2 or “Hello, World!” , is called an _____

A

object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

For now, think of An object as a

A

data value in Python with three properties: an identity, a data type and a value (IDV)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

The value of an object is the ______ it represents—

A

Data it represents; the number 2, for example, has a value of 2.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

The identity of an object is where it is

A

stored in memory, which never changes (and which we will be ignoring for now).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

The data type of an object is the ________of data the object belongs to

A

is the category of data the object belongs to, and determines the properties the object has.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What the determines the properties the object has?

A

The data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

When we refer to an object with a str data type, we call it a string; what is a string?

A

A string is a sequence of one or more characters surrounded by quotes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

You can use single quotes or double quotes, but the quotes at the beginning and end of a given string musT

A

match

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

“Hello World” is an example of what kind of data?

A

string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Strings are used to represent _______, and they have unique ______

A

text; properties

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Whole numbers have the data type int , short for _____
integer.
26
Numbers like 2 , 3 , 4 and 10 all have the data type int. Another way of saying this is they are all
integer
27
Like strings, integers have their own
properties.
28
Whole numbers are integers, fractional numbers (numbers with a decimal point) have a different data type called
float
29
Like all data types, floats have their own
properties and behave in a certain way.
30
Objects with a bool data type have a value of either TRUE OR FALSE are called what?
have a value of either True or False and are called | booleans:
31
Objects with a data type NoneType always have the value
None
32
Objects with a | NoneType data type are used to represent the
absence of a value:
33
What is a constant?
A value that never changes\ | for example : the value 2 does not change
34
A variable , on the other hand, refers to a value; but that value cha____cant/can change
can
35
A variable consists of ______
a name made up of one or more characters
36
Often programmers want to increment or decrement variables, Python has a special syntax—a shortcut—for incrementing and decrementing variables. To increment a variable
you assign the variable to itself, and on the other side of the equals sign you add the variable to the number you want to increment by
37
Provide an example on how you can increment the variable--> x =12 but you want to increase to 14
x=12 x=x+2 x >>>14
38
Provide an example on how you can decrement the variable--> x =12 but you want to decrease to 10
x=12 x=x-2 x >>>10
39
What is a shorter method for incrementing and decrementing variables you should use instead:
``` x + = 1 x >> 11 x = 10 ________ x - = 1 x >> 9 ```
40
Variables are not limited to storing integer values—they can refer to any data type:
``` my_string = “Hello, World!” >> my_float = 2.2 >> my_boolean = True >> ```
41
You can name variables whatever you’d like, as long as you follow 4 rules:
1. Variables can’t have spaces. If you want to use two words in a variable, put an underscore between them: i.e., my_variable = “A string!” 2.Variable names can only contain letters, numbers and the underscore symbol. 3. You cannot start a variable name with a number. Although you can start a variable with an underscore, it has a special meaning that we will cover later , so avoid using it until then. 4. You cannot use Python keywords for variable names. You can find a list of keywords here: http://zetcode.com/lang/python/keywords
42
The set of rules, principles, and processes that govern the structure of sentences in a given language, specifically word order
Syntax
43
Python has syntax meaning Python also has a set of rules that must be followe d, so it also has syntax. For example: In Python, strings are always surrounded
by quotes. This is an example of Python’s syntax.
44
Not following the rules can lead to a
Syntax error
45
Can a program run with a syntax error?
no
46
When there is an error in your code, you should
go to the line number the problem | occurred on, and try to figure out what you did wrong.
47
Python has two kinds of errors:
syntax errors and exceptions.
48
In python, Any error that is not a syntax error is an .
exception
49
A ZeroDivisionError is an example of an
exception that occurs if you try dividing by zero.
50
The difference between a syntax error and an exception is exceptions are
NOT necessarily fatal
51
If you incorrectly indent your code, you get an
IndentationError
52
Remember, when you run | into a syntax error or exception, what should you do?
go to the line where the problem occurred and stare at it until you figure out the solution (or search the internet for the error or exception if you are stumped).
53
Most common arithmetic operators in Python --> **
Exponent
54
Most common arithmetic operators in Python --> %
Modulo/remainder
55
Most common arithmetic operators in Python --> //
integer division/floored quotient
56
Most common arithmetic operators in Python --> /
Division
57
Most common arithmetic operators in Python --> *
Multiplication
58
Most common arithmetic operators in Python --> -
Substraction
59
Most common arithmetic operators in Python --> +
Addition
60
When two numbers are divided there is a QUOTIENT and a REMAINDER. The ________ is the result of the division and the _______ what is left over. The modulo operator (%) returns the
remainder when two numbers are divided
61
There are two different operators for division. The first is //, which returns the____
quotient: 14 // 3 > 4
62
The second is /, which returns the result of the first number divided by the second as a ______: provide example
floating point number: 14 / 3 > 4.666666666666667
63
The values (in this case numbers) on either side of an operator are called .
operands (2 **2 ; the two 2s are called operands)
64
Together, two operands and an operator form an
expression
65
Python evaluates each______ and returns a single value.
expression
66
The order of operations is a
set of rules used in mathematical calculations to evaluate | an expression.
67
Order of Operations mnemonic
Please Excuse My Dear Aunt Sally ?(PEMDAS)
68
PEMDAS stands for
``` Parentheses Exponents, Multiplication Division Addition Subtraction. ```
69
Pythons follows what order of operations?
Python follows t he same order of operations when it evaluates mathematical expressions
70
Comparison Operators are operators used in expression with _________.
expressions with operands on either side
71
How are comparison operators different from arithmetic operators?
Comparison operators evaluate to either True or False .
72
> Operator : meaning
Greater than
73
< Operator : meaning
Less than
74
>= Operator : meaning
Greater than or equal
75
<= Operator : meaning
Less than or equal
76
== Operator : meaning
Equal
77
!= Operator : meaning
Not equal
78
An expression with the > operator returns the value _____if the number on the right is than the number on the left, and False if it is not:???
True; bigger
79
= is used to assign a value to a variable, not to
check for equality.
80
The comparison operator == is used to check for _____therefore if you see x=100, what should you think ?
equality, so if you see x == | 100 , then you should think “x equals 100”
81
Logical operators: Expression with logical operators are similar to expression with comparisons operators how?
They both evaluate to true or false
82
When Python evaluates a statement with the 'and' keyword it stops evaluating the statement as soon as an
expression evaluates to False
83
For example, if one of your expressions takes a long time to evaluate, you should put it first OR last, why?
last, because it will be less likely to be evaluated there.
84
The keyword 'or" takes two or more expressions and evaluates to True if _______
if any of the expressions evaluate to True
85
When evaluating statements with OR in them, as soon | as one expression evaluates to True , Python does what?
stops evaluating the rest of the expressions | because it is going to return True regardless of how they evaluate.
86
You can place the keyword "not" in front of an expression, and it will
change the result of the expressions evaluation to the opposite of what it would have otherwise evaluated to .
87
If the expression would have evaluated to True , it will evaluate to _____when preceded by not , and if it would have evaluated to False , it will evaluate to ____when preceded by not .
False ; True
88
Conditional statements are a type of
control structure
89
What is control structure?
block of code that can make decisions by analyzing the values of variables.
90
A conditional statement is code that is able to
execute additional code circumstantially
91
The keywords____and ___are used in conditional statements
if , elif and else
92
``` Here an example of two conditional statement definitions: Explain what they mean. If (expression) Then (code_area1) Else (code_area2) ```
This pseudocode explains that you can define two conditional statements that work together. If the expression defined in the first conditional statement is True , all of the code defined in code_area1 gets executed. If the expression defined in the first conditional statement is False , all of the code defined in code_area2 gets executed
93
In a two conditional statement The first part of the example is called an______ , and the latter is called an ______
if statement; else statement .Together, they form an if else statement: a way for programmers to say “if this happens do this, otherwise do that”.