1. (TCO 1) The number represented by the relationship (1 x 2 2 ) + (1 x 2 1 ) +
ID: 3672054 • Letter: 1
Question
1. (TCO 1) The number represented by the relationship (1 x 22) + (1 x 21) + (1 x 20) equals _____. (Points : 10)
1
2
6
7
Question 2.
309h
039h
777h
1D4h
Question 3.
117
118
125
177
Question 4.
input student
get input student
input = student
student = input(‘Enter name’)
Question 5.
area = s * s
area = = s * s
area = 1.0 * s^2
area = s^2
Question 6.
First_name = “Carlos”
First_name = ‘Carlos’
First_Name = ‘Carlos’
‘First_Name’ = “Carlos”
Question 7.
2 3
1 2 3
2 3 4
0 1 2 3
Question 8.
x = (bit0 * 1) + (bit1 * 2) + (bit2 * 4) + (bit3 * 8)
x = (bit0 * 0) + (bit1 * 1) + (bit2 * 2) + (bit3 * 3) + (bit4 * 4) + (bit5 * 5) + (bit6 * 6) + (bit7 * 7)
(bit0 * 1) + (bit1 * 2) + (bit2 * 4) + (bit3 * 8) + (bit4 * 16) + (bit5 * 32) + (bit6 * 64) + (bit7 * 128)
(bit0 * 128) + (bit1 * 32) + (bit2 * 64) + (bit3 * 16) + (bit4 * 8) + (bit5 * 4) + (bit6 * 2) + (bit7 * 1)
Question 9.
1
10
21
43
Question 10.
01001
11111
10010
00100
Question 11.
x = = y
x > = y
x < y
x < = y
Question 12.
print x, 'AND', y, ' in binary form equals ', '0x%z' % z
print x, 'AND', y, ' in binary form equals ', z
print x, ‘XOR’, y, ' in binary form equals ', bin(z)
print x, 'AND', y, ' in binary form equals ', bin(z)
Question 13.
2, 3, 4, 5
4, 9, 16, 25
2, 4, 3, 9, 4, 16, 5, 25
2, 4, 16
Question 14.
1, 2, 3, 4, 5, 6, 7, 8, 9, done
4, 5, 5, 6, 6, 7, 7 done
1, 2, 2, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, done
8, 10, 10, 12, 12, 14, 14 done
Question 15.
CASE statements
if and elif statements
SWITCH statements
if and else if statements
1. (TCO 1) The number represented by the relationship (1 x 22) + (1 x 21) + (1 x 20) equals _____. (Points : 10)
1
2
6
7
Explanation / Answer
1. (TCO 1) The number represented by the relationship (1 x 22) + (1 x 21) + (1 x 20) equals 4 + 2 + 1 = 7.
2. (TCO 1) Convert 676 decimal to base 16. 676 / 16 = 42 with a remainder 4. 42 / 16 = 2 with a remainder A. 2 / 16 = 0 with a remainder 2. So, 67610 = 2A416. (So the answer is none of the given choice.)
3. (TCO 1) Convert binary 0111 0101 to decimal. 1 x 20 + 1 x 22 + 1 x 24 + 1 x 25 + 1 x 26 = 1 + 4 + 16 + 32 + 64 = 117
4. (TCO 2) Which of the following Python lines of code would set the variable student to a value provided by the user?
student = input(‘Enter name’). The function input() will read the value entered by the user from console, and will return. The returned value is stored to the variable student.
5. (TCO 2) Which line will yield the area of a square with side s to at least one decimal place? Hint: The area of square is given by s2. This can be simply done by area = s * s.
6. (TCO 2) Which of the following lines will assign the variable First_Name to the string “Carlos”?
First_Name = ‘Carlos’ will assign the right hand string value Carlos to the left side variable First_Name.
7. (TCO 3) What output will be displayed as a result of the following code?
Line 1: x = 1 # x is assigned a value of 1.
Line 2: while True: #This makes it an infinite loop.
Line 3: x = x + 1 # x is increased by 1, therefore x value is 2 now. Again x is increased by 1, and now the value is 3.
Line 4: print x # So 2 is printed. So, 3 is also printed.
Line 5: if x = 3: # The condition fails. The condition satisfies.
Line 6: break # And will break the infinite loop.
Therefore the output value is: 2 3
8. (TCO 3) Which of the following lines best computes the decimal representation for an 8-bit binary input?
(bit0 * 1) + (bit1 * 2) + (bit2 * 4) + (bit3 * 8) + (bit4 * 16) + (bit5 * 32) + (bit6 * 64) + (bit7 * 128)
9. (TCO 3) Reference the code below. What would be the result of x = x / 2 the second time Line 4 is executed?
Line 1: x = 43
Line 2: while (x > 0)
Line 3: print x % 2
Line 4: x = x / 2 First time, 43 / 2 = 21. Second time 21 / 2 = 10.
10. (TCO 4) What will be the result of the Python statement 01101 & 11011? 01001
11. (TCO 4) Given that x = 12 and y = 8, which of the following will yield a true result? x > = y
12. (TCO 4) The following code is missing a line. Which of the following options would output the desired result in binary form?
x = input(‘Enter Input X: ‘)
y = input(‘Enter Input Y: ‘)
z = x & y
print x, 'AND', y, ' in binary form equals ', bin(z)
13. (TCO 5) Which of the following best represents the output that will result from this code?
Line 1: for x in range(2, 5):
Line 2: print x^2 (Points : 10) 4 9 16 25
14. (TCO 5) Which of the following best represents the output that will result from this code?
a = 4
while a < 9:
print a
a = a + 1
if a > 7: continue
print a * 2
print ‘done’ (Points : 10) 4 10 5 12 6 14 7 8
15. (TCO 6) Which of the following can be used in Python to execute from alternate code options depending on a variable’s condition? (Points : 10)
SWITCH statements
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.