Unit 2 Flashcards

Variables and Expressions

1
Q

2.1 - Variables and Assignments

What is a variable?

A

a named item that holds a value

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

2.1 - Variables and Assignments

What are the two types of statements in programming?

A

declarative: create/assign variables
executable: instructs the computer to perform a task

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

2.2 - Identifiers

What is an identifier?

A

the name of a variable

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

2.2 - Identifiers

What are the requirements of an identifier?

A

starts with a letter, can use letters, underscores, and numbers, cannot contain spaces

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

2.2 - Identifiers

IsnumPizzas the same as numpizzas?

A

No

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

2.3 - Objects

What is an object?

A

something that represents a value, is mutable

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

2.3 - Objects

What are the 3 properties of an object?

A

value, type, and identity

type: int, string, etc.
identity: describes object

value; number

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

2.3 - Objects

What is mutability?

A

indicates if an object’s value can be changed

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

2.4 - Numeric Types: Floating-Point

What is a floating-point number?

comonnly referred to as a float

A

a number that uses a decimal

ex. 3.14159

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

2.4 - Numeric Types: Floating-Point

How do you use float()?

A

like int(), it converts numbers to a float

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

2.4 - Numeric Types: Floating-Point

What is a floating-point literal?

A

a number with an unnecessary decimal

ex. 99 -> 99.0

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

2.4 - Numeric Types: Floating-Point

How do you round a float?

within a print statement, to nearest 100th of a decimal

A

print(f'{myFloat:.2f}')

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

2.5 - Arithmetic Expressions

What is an expression?

A

a combination of values that evaluates to a number

like 2 + 2

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

2.5 - Arithmetic Expressions

What is a literal?

A

a specific value indepentent of an expression

2 + 2

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

2.5 - Arithmetic Expressions

What type of precedence rules does Python use?

A

PEMDAS

parenthesis, exponents, multiplication, division, addition, subtraction

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

2.6 - Python Expressions

What is a compound operator used for?

A

a quicker way to type variable = variable + 1, used as +=

17
Q

2.7 - Division and Modulo

What is floor division, and what symbol do you use for it

A

// divides a number, but rounds the answer downward

5 // 2 = 2

18
Q

2.7 - Division and Modulo

What is modulo, and what symbol do you use for it?

A

% finds the remainder of a division problem

4 % 2 = 0

19
Q

2.8 - Module Basics

What is a module?

also called a library

A

a file with pre-written Python code used in other programs; must be imported via dot notation

ex. universe.speed_of_light

20
Q

2.9 - Math Module

What does the math module do?

A

allows for more complex mathematical functions

ex. square roots

21
Q

2.9 - Math Module

What code from the math module would you use for powers? For square roots?

power - x^y
square root - √x

A

power: math.pow(x, y)
square root: math.sqrt(x)

22
Q

2.10 - Random Numbers

What code would you use to import the random numbers module?

A

import random

23
Q

2.10 - Random Numbers

Why is there no “true random” in computing?

A

randomization is based on a unique seed that creates a series of psuedo-random numbers

24
Q

2.10 - Random Numbers

What is the difference between inclusive and exclusive numbers?

A

inclusive - includes the number in range
exclusive - excludes the number in range