CHAPTER 3 Intro to Programming Flashcards

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
Q

Whole numbers have the data type int , short for _____

A

integer.

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

Numbers like 2 , 3 , 4 and 10 all have the data type int. Another way of saying this is they are all

A

integer

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

Like strings, integers have their own

A

properties.

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

Whole numbers are integers, fractional numbers (numbers with a decimal point) have a different data type called

A

float

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

Like all data types, floats have their own

A

properties and behave in a certain way.

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

Objects with a bool data type have a value of either TRUE OR FALSE are called what?

A

have a value of either True or False and are called

booleans:

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

Objects with a data type NoneType always have the value

A

None

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

Objects with a

NoneType data type are used to represent the

A

absence of a value:

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

What is a constant?

A

A value that never changes\

for example : the value 2 does not change

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

A variable , on the other hand, refers to a value; but that value cha____cant/can change

A

can

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

A variable consists of ______

A

a name made up of one or more characters

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

Often programmers want to increment or decrement variables, Python has a special syntax—a shortcut—for incrementing and decrementing variables. To
increment a variable

A

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

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

Provide an example on how you can increment the variable–> x =12 but you want to increase to 14

A

x=12
x=x+2
x
»>14

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

Provide an example on how you can decrement the variable–> x =12 but you want to decrease to 10

A

x=12
x=x-2
x
»>10

39
Q

What is a shorter method for incrementing and decrementing variables you should use instead:

A
x + = 1
x
>> 11
x = 10
\_\_\_\_\_\_\_\_
x - = 1
x
>> 9
40
Q

Variables are not limited to storing integer values—they can refer to any data type:

A
my_string = “Hello, World!”
>>
my_float = 2.2
>>
my_boolean = True
>>
41
Q

You can name variables whatever you’d like, as long as you follow 4 rules:

A
  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.
  2. 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.
  3. You cannot use Python keywords for variable names. You can find a list of keywords
    here: http://zetcode.com/lang/python/keywords
42
Q

The set of rules, principles, and processes that govern the structure of sentences in a given language, specifically word order

A

Syntax

43
Q

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

A

by quotes. This is an example of Python’s syntax.

44
Q

Not following the rules can lead to a

A

Syntax error

45
Q

Can a program run with a syntax error?

A

no

46
Q

When there is an error in your code, you should

A

go to the line number the problem

occurred on, and try to figure out what you did wrong.

47
Q

Python has two kinds of errors:

A

syntax errors and exceptions.

48
Q

In python, Any error that is not a syntax error is an .

A

exception

49
Q

A ZeroDivisionError is an example of an

A

exception that occurs if you try dividing by zero.

50
Q

The difference between a syntax error and an exception is exceptions are

A

NOT necessarily fatal

51
Q

If you incorrectly indent your code, you get an

A

IndentationError

52
Q

Remember, when you run

into a syntax error or exception, what should you do?

A

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
Q

Most common arithmetic operators in Python –> **

A

Exponent

54
Q

Most common arithmetic operators in Python –> %

A

Modulo/remainder

55
Q

Most common arithmetic operators in Python –> //

A

integer division/floored quotient

56
Q

Most common arithmetic operators in Python –> /

A

Division

57
Q

Most common arithmetic operators in Python –> *

A

Multiplication

58
Q

Most common arithmetic operators in Python –> -

A

Substraction

59
Q

Most common arithmetic operators in Python –> +

A

Addition

60
Q

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

A

remainder when two numbers are divided

61
Q

There are two different operators for division. The first is //, which returns the____

A

quotient:
14 // 3
> 4

62
Q

The second is /, which returns the result of the first number divided by the second as a ______: provide example

A

floating point number:
14 / 3
> 4.666666666666667

63
Q

The values (in this case numbers) on either side of an operator are called .

A

operands (2 **2 ; the two 2s are called operands)

64
Q

Together, two operands and an operator form an

A

expression

65
Q

Python evaluates each______ and returns a single value.

A

expression

66
Q

The order of operations is a

A

set of rules used in mathematical calculations to evaluate

an expression.

67
Q

Order of Operations mnemonic

A

Please Excuse My Dear Aunt Sally ?(PEMDAS)

68
Q

PEMDAS stands for

A
Parentheses
Exponents,
Multiplication
Division
Addition 
Subtraction.
69
Q

Pythons follows what order of operations?

A

Python follows t he same order of operations when it evaluates mathematical expressions

70
Q

Comparison Operators are operators used in expression with _________.

A

expressions with operands on either side

71
Q

How are comparison operators different from arithmetic operators?

A

Comparison operators evaluate to either True or False .

72
Q

> Operator : meaning

A

Greater than

73
Q

< Operator : meaning

A

Less than

74
Q

> = Operator : meaning

A

Greater than or equal

75
Q

<= Operator : meaning

A

Less than or equal

76
Q

== Operator : meaning

A

Equal

77
Q

!= Operator : meaning

A

Not equal

78
Q

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:???

A

True; bigger

79
Q

= is used to assign a value to a variable, not to

A

check for equality.

80
Q

The comparison operator == is used to check for _____therefore if you see x=100, what should you think ?

A

equality, so if you see x ==

100 , then you should think “x equals 100”

81
Q

Logical operators: Expression with logical operators are similar to expression with comparisons operators how?

A

They both evaluate to true or false

82
Q

When Python evaluates a statement with the ‘and’ keyword it stops evaluating the statement as
soon as an

A

expression evaluates to False

83
Q

For example, if one of your expressions takes a long time to evaluate, you should put it first OR last, why?

A

last, because it will be less likely to be evaluated there.

84
Q

The keyword ‘or” takes two or more expressions and evaluates to True if _______

A

if any of the expressions evaluate to True

85
Q

When evaluating statements with OR in them, as soon

as one expression evaluates to True , Python does what?

A

stops evaluating the rest of the expressions

because it is going to return True regardless of how they evaluate.

86
Q

You can place the keyword “not” in front of an expression, and it will

A

change the result of the expressions evaluation to the opposite of what it would have otherwise evaluated to .

87
Q

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 .

A

False ; True

88
Q

Conditional statements are a type of

A

control structure

89
Q

What is control structure?

A

block of code that can make decisions by analyzing the values of variables.

90
Q

A conditional statement is code that is able to

A

execute additional code circumstantially

91
Q

The keywords____and ___are used in conditional statements

A

if , elif and else

92
Q
Here an example of two conditional statement definitions: Explain what they mean. 
If (expression) Then
(code_area1)
Else
(code_area2)
A

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
Q

In a two conditional statement The first part of the example is called an______ , and the latter is called an ______

A

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