Expressions and Variables Flashcards

1
Q

Two types of numbers? Their Functions?

A

Integers “int()” and decimals “float()”

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

Arithmetic operators? Symbols?

A
arithmetic operators
\+	plus		        addition
-	minus	        subtraction
*	times	        multiplication
/	divided by 	division
**      power	        exponentiation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How many decimal places in Python?

A

15

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

“Please excuse my dear aunt Sallie” or BEDMAS

A

Operator Precedence (Parantheses [or brackets], exponent, multiplication, division [equal precedent so do from left to right], addition, subtraction

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

What is a variable?

A

Placeholder for important values; used to avoid recomputing values and to give values names that help reader to understand code

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

Features of a valid variable name?

A

Consists of letters, numbers, underscores; starts with a letter; case-sensitive (capitalization matters

Eg. legal name: ninja, Ninja, n_i_n_j_a

illegal name: 1337,1337ninja

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

+= operator

A

Used to update a variable to a new value . Eg. my_age = my_age + 1 can instead be my_age += 1

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

Which of the following are syntactically correct strings in Python? Why?

  1. “This course is great!”
  2. “It’s a beautiful day.”
  3. “Hello
  4. “Goodbye’
  5. ‘Hello, world.’
A

Correct:

  1. “This course is great!”
  2. “It’s a beautiful day.”
  3. ‘Hello, world.’

Strings need to start and end with the same type of quotation mark. 3 and 4 don’t.

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

To display a value in the console, what Python keyword do you use?

A

print

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

What does it mean when a line in Python starts with a “#”.

Eg. #yo

A

That means it’s a comment.

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

Which of the following arithmetic expressions are syntactically correct in Python?

  1. 3 * ((2 - 9) + 4)) * (2 + (1 - 3))
  2. 8 / -2
  3. 5 * 3 (7 - 2)
  4. (7 - 2) / (3 ** 2)
  5. 5 - 1 - 3 - 7 - 0
A
  1. Incorrect. Extra closing parentheses after the 4
  2. Correct
  3. Incorrect. Missing an operator between 3 and (7 - 2)
  4. Correct
  5. Correct
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which of the following can be used as a variable name in Python?

  1. ounces
  2. my.number
  3. __number__
  4. my_number
    5, MYnumber
    6, ounce(s)
A
  1. valid
  2. “my.number” is not valid bc a single variable can’t contain a period; only when the first part is a class
  3. Valid; though variables rarely start with underscores
  4. Valid
  5. Valid, though convention says don’t start a variable with a capital
  6. “ounce(s)” is not valid bc variables can’t contain parentheses
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Assume you have values in the variables x and y. Which statement(s) would result in x having the sum of the current values of x and y?

  1. y += x
  2. x = y + x
  3. x += y
  4. x += x + y
A
  1. Wrong
  2. Right
  3. Right
  4. Wrong
How well did you know this?
1
Not at all
2
3
4
5
Perfectly