CPSC 1040
Test #1
Name: Answer Key
September 15, 2015
Closed notes, closed laptop, calculators OK. Please use a pencil. Weight of each section in parentheses. If
you need more space, use the back of the sheet.
A. (20 points) Multiple Choice.
ENIAC,
Main memory, RAM,
Machine language, ASCII, 255,
logic,
Pseudocode,
\,
Dell,
fetch-decode-execute,
Assembly language,
magnetically,
solid state drive, (any answer accepted),
**,
68,
24.0,
input(), Quotation
B. (15 points) True or False.
F F T F T T T T T T F T F T T
C. Python Programming (20 points)
1.
(10) A car’s miles per gallon (MPG) can be calculated with the following formula:
MPG = Miles driven / Gallons of gas used
Write a program that asks the user for the number of miles driven and the gallons of miles used. It should
calculate the car’s MPG and display the result. (You do not have to include comments.)
miles
= float(input('Enter number of miles driven:
'))
gallons = float(input('Enter number of gallons of gas: '))
mpg
= miles / gallons
print('Your gas mileage is: ', mpg)
2.
(5) Explain what the following Python program does. Be precise. (Don’t just say it prints out a number.
Explain what the significance of the number is.)
# An acre of land is equivalent to 43,560 square feet.
acre = 43560
x = int(input('Enter number of square feet: '))
print('The answer is: ', x/acre)
Ans: This program converts square feet into acres. The user is asked to enter a number of square feet
and the program prints out the equivalent number of acres.
3. (5) What is the output of the following Python code? Be precise.
# This is a print statement that prints a pretty pattern
print('
*\n
***\n
*****\n *******')
Ans:
*
***
*****
*******
D. Useful Formulas. (20 points, 4 points each) Simplify each of the following. Use G, K, T, Z, M, P, Y and E as appropriate. Show clearly how you arrived at your answer. All logarithms are base 2. You may use a calculator. 1. log ((A * BX) / (EY * W))
= log (A * BX) – log(EY * W)
= log A + X log B – (Y log E + log W)
(acceptable answer)
= log A + X log B – Y log E – log W
2.
15 + 16 + 17 + … + 129
= 129(130)/2 – 14(15)/2
= 129(65) – 105
= 8280
3.
1 + 4 + 9 + 16 + … + 352
= 35(35+1)(2*35+1)/6
= 35(36)(71)/6
= 14910
(acceptable answer)
(acceptable answer)
4.
(250) * (215) / (229)
= 250+15-29 = 236 = 64G
5.
(M*K/(G*T))*265
= (220 * 210 / (230 * 240)) * 265
= (230 / 270) * 265 = 225 = 32M
E. (15 points, 5 points each) Permutations and Combinations. Show clearly how you arrived at your
answers.
1.
How many permutations of 3 different digits are there, chosen from the ten digits 0 to 9 inclusive?
10 * 9 * 8 = 720
2.
How many different committees of 5 people can be chosen from 10 people?
10
3.
(acceptable answer)
C 5 = 10! / (5! 5!) = 10 * 9 * 8 * 7 * 6 / (5 * 4 * 3 * 2 * 1) = 252
(acceptable answer)
A special type of password consists of four different letters of the alphabet, where each letter is used
only once. How many different possible passwords are there?
26 * 25 * 24 * 23 = 358,800
(acceptable answer)
F. (10) Binary Representation
1.
(5) Convert the following decimal values to 8-bit binary. The first one has been done for you.
25 00011001
2.
39 00100111
117 01110101
214 11010110
(5) Convert the following binary values to decimal. The first one has been done for you.
27 00011011
90 01011010
143 10001111
G. (5 points) Bonus. Add the following binary numbers. What is the sum in binary? What is the sum in
decimal? Show clearly how you arrived at your answer.
011001001
010011011
Sum in Binary: 101100100
Sum in Decimal: 356
© Copyright 2026 Paperzz