# Peer Instruction: Variable Multiple Choice QuestionsΒΆ

- Ints only have 2 decimal places
- Try again. Ints do not have any decimal places.
- Ints don't have any decimals
- Correct! Because ints do not have any decimal places,therefore by multipling it with 100, the two decimal places can be transformed into ones and tens place.
- It's easier to multiply ints
- Try again. Try to consider why we multiply the number by 100. Becausen we want the two decimal places to be transformed into ones and tens place.
- Funsies
- Try again. Good point but we want the funsies?
- I don't know
- Try again. Try to consider why we multiply the number by 100. Because ints do not have any decimal places,therefore by multipling it with 100, the two decimal places can be transformed into ones and tens place.

csp-10-2-1: Recall that when we wanted to cut off all but two decimal places of a float, we multiplied it by 100, cast it as a integer, and then divided it by 100 using float division. Why did we cast it as an int?

- Yes
- Try again. Step 3 ends with returning to step 1. It never ends. But an algorithm must halt.
- No, because it contains an infinite number of steps
- Try again. B is incorrect because there are three steps.
- No, because it never halts
- Correct! Because step 3 ends with returning to step 1. It never ends.
- No, because step 3 is not well-defined
- Try again. It is true that there are problems with step 3. But it is because step 3 makes it never halt.

csp-10-2-2: Is the following an algorithm?

```
Step 1: write down the number 0
Step 2: add 3
Step 3: return to step 1
```

- Nothing. They are both 1
- Try again. 1 and 1.0 represent different types in programming.
- Nothing. They might be of different types, but types don't matter in programming
- Try again. 1 and 1.0 are different types. And types are very important in programming.
- 1 is an integer and 1.0 is a string, because of the character
- Try again. 1 is an integer but 1.0 is not a string. It has a decimal place, so 1.0 is a float.
- 1 is an integer and 1.0 is a floating-point number
- Correct! 1 and 1.0 represent different types in programming. And 1.0 with a decimal place is a float.
- 1.0 is an integer and 1 is a floating-point number
- Try again. An integer does not have any decimal place but a float does.

csp-10-2-3: What is the difference between the literals 1 and 1.0?

- 39
- Correct! + operator adds x and 2 together, and x equals to 37. Therefore, y equals to the sum of 37 and 2.
- 22
- Try again. + operator adds x and 2 together, and x equals to 37. Therefore, y equals to the sum of 37 and 2. Integers are immutable in Python. The later changes in x do not affect the value of y.
- 35
- Try again. + operator adds x and 2 together, and x equals to 37. Therefore, y equals to the sum of 37 and 2.
- 20
- Try again. + operator adds x and 2 together, and x equals to 37. Therefore, y equals to the sum of 37 and 2. Integers are immutable in Python. The later changes in x do not affect the value of y.
- 18
- Try again. + operator adds x and 2 together, and x equals to 37. Therefore, y equals to the sum of 37 and 2. Integers are immutable in Python. The later changes in x do not affect the value of y.

csp-10-2-4: What is the value of `y`

after this code runs?

```
x = 37
y = x + 2
x = 20
```

- 39
- Try again. - operator means x substracts 2, and x equals to 37. Therefore, y equals to the 35.
- 22
- Try again. - operator means x substracts 2, and x equals to 37. Therefore, y equals to the 35. Integers are immutable in Python. The later changes in x do not affect the value of y.
- 35
- Correct! - operator means x substracts 2, and x equals to 37. Therefore, y equals to the 35.
- 20
- Try again. - operator means x substracts 2, and x equals to 37. Therefore, y equals to the 35. Integers are immutable in Python. The later changes in x do not affect the value of y.
- 18
- Try again. - operator means x substracts 2, and x equals to 37. Therefore, y equals to the 35. Integers are immutable in Python. The later changes in x do not affect the value of y.

csp-10-2-5: What is the value of `y`

after this code runs?

```
x = 37
y = x - 2
x = 20
```

- True
- Try again. != means not equal. Because a equals to 3, it returns bool value False. Therefore, b = False.
- False
- Correct! != means not equal. Because a equals to 3, it returns bool value False. Therefore, b = False.
- 3
- Try again. != means not equal. Because a equals to 3, it returns bool value False. Therefore, b = False.
- Syntax error
- Try again. != means not equal. Because a equals to 3, it returns bool value False. Therefore, b = False.

csp-10-2-6: What does the following code print?

```
a = 3
b = (a != 3)
print(b)
```

- True
- Correct! == tests for equality. Because a equals to 3, it returns bool value True. Therefore, b = True.
- False
- Try again. == tests for equality. Because a equals to 3, it returns bool value True. Therefore, b = True.
- 3
- Try again. == tests for equality. Because a equals to 3, it returns bool value True. Therefore, b = True.
- Syntax error
- Try again. == tests for equality. Because a equals to 3, it returns bool value True. Therefore, b = True.

csp-10-2-7: What does the following code print?

```
a = 3
b = (a == 3)
print(b)
```

- a == b == 5
- Try again. The expression here means a and b are equal to 5.
- a == b or a == 5
- Correct! or produces True exactly when at least one of its operands is True.
- a == b and a == 5
- Try again. And produces True exactly when both of its operands are True. The expression here evaluates to true when both of the two conditions are true.
- a == (b == 5)
- Try again. b == 5 returns a bool value. The expression here evaluates to true when b equals to 5 and a equals to bool value True.

csp-10-2-8: I would like an expression that evaluates to True exactly when at least one of the following two conditions is true: (1) `a`

and `b`

are equal, (2) when `a`

has value 5. Which of these expressions does that?

- True
- Correct! not a returns false. False and b returns False. or produces True exactly when at least one of its operands is True. Therefore, the final result returns True.
- False
- Try again. not a returns false because 'not' is a Logical operator in Python that will return True if the expression is False. And produces True exactly when both of its operands are True. So False and b returns False. or produces True exactly when at least one of its operands is True. Therefore, the final result returns True.

csp-10-2-9: What is the value of the last expression? (Remember that `not`

has the highest precedence, then `and`

, then `or`

.)

```
a = True
b = False
c = True
not a and b or c
```

- (a // 10) % 10
- Try again. A is correct but b is also right. a % 100 returns the middle and right digit of a. // 10 returns the middle digit.
- (a % 100) // 10
- Try again. B is correct but a is also right. a // 10 returns the left and middle digit of a. % 10 returns the middle digit.
- (a % 10) // 10
- Try again. C cannot return the middle digit. a % 10 returns the right digit of a. // 10 still gets the right digit.
- More than one of the above
- Correct! Both A and B are correct!
- None of the above
- Try again. A and B are both correct! In the option A, a % 100 returns the middle and right digit of a. // 10 returns the middle digit. In the option B, a // 10 returns the left and middle digit of a. % 10 returns the middle digit.

csp-10-2-10: Assume that a refers to a three-digit integer. Which of the following evaluates to the middle digit of `a`

? (For example, if a referred to value 456, we want an expression with value 5.)