Ch. 3 Flashcards
1
Q
the value 4! is
A
factorial of 4, 4 × 3 × 2 × 1 = 24.
2
Q
4.0 / 10.0 + 3.5 * 2
A
- and / from left to right.
- and - from left to right.
a) first divide 4.0 and 10.0, which equals 0.4
0.4 + 3.5 * 2
b) multiply 3.5 and 2, which equals 7.0
0.4 + 7.0
c) add, equation equals 7.4
- and - from left to right.
3
Q
10 % 4 + 6 / 2
A
- modulo %
- / and + from left to right
a) 10 % 4 equals 2 because % calculates remainder
2 + 6 / 2
b) divide 6 / 2, equals 3
2 + 3
c) add, equation equals 5
4
Q
abs (4 - 20 // 3) ** 3
A
- integer division //
- from left to right
- absolute value, abs()
- exponent **
a) 20 // 3 equals 6 because // 20 divided by 3 is 6.6667, so round down to get 6
abs(4 - 6) ** 3
b) subtract 4 and 6, equals -2
abs(-2) ** 3
c) abs makes neg to pos, abs(-2) equals 2
2 ** 3
d) 2 ** 3 equals 8 because 2 * 2 * 2 = 8
5
Q
sqrt(4.5 - 5.0) + 7 * 3
A
- subtract 4.5 and 5.0, equals -0.5
sqrt(-0.5) + 7 * 3 - multipy 7 and 3
sqrt(-0.5) + 21 - sqrt(-0.5) equals error?
6
Q
3 * 10 // 3 + 10 % 3
A
- multiply first
30 // 3 + 10 % 3 - divide
10 + 10 % 3 - modulo, remainder of 10 divided by 3 is 1
10 + 1 - add
11
7
Q
3 ** 3
A
- 3 *3 = 9
- 9 * 3= 27
8
Q
(3 + 5)(5)
A
(3 + 5) * 5
9
Q
n(n - 1)/2
A
n * (n -1) / 2
10
Q
range(5)
A
0,1,2,3,4
11
Q
range(3, 10)
A
3,4,5,6,7,8,9
12
Q
range(4, 13, 3)
A
4,7,10
start at 4, with increment of 3, and stop but not include 13
13
Q
range(15, 5, -2)
A
15,13,11,9,7
start at 15, with increment of -2, and stop but not include 5
14
Q
range(5,3)
A
error bc 5 is greater than 3
15
Q
for i in range(1,11):
print (i*i)
A
range is 1,2,3,4,5,6,7,8,9,10
1
4
9
16
25
36
49
64
81
100