reec06 review for Test ONE Print your name legibly:
circle your last name
Sign:
Poly-ID:
JUST LIKE THE REAL TEST – BRING ONLY A WRITING UTENSIL, YOUR ID, AND YOUR BRAIN TO THE TEST.
For the following questions, use these variable definitions.
a = 4444
b = 2
c = 11.11
d = "hello"
What is the value and type of each of the following expressions or, if it won't compile, circle that answer
type value circle if will not compile
(2 pts) a // b / c ______will not compile
(2 pts) b + 6 % b ______will not compile
(2 pts) a / d ______will not compile
(2 pts) math.ceil(c) + 1 ______will not compile
(2 pts) d * 0 ______will not compile
(2 pts) str(d) ______will not compile
(2 pts)
math.sqrt( b = float(c) ) ______will not compile
(2 pts) Circle the letters of ALL correct answers. NameError
a) is an exception
b) is run time error
c) is a compile time error
d) cannot happen once a program passed compilation without an error
(6 pts) What is the output when these statements are executed and the user hits these keys: 3 ENTER
WRITE ANSWERS TO THESE QUESTIONS IN THIS DOCUMENT page 4 of 7 pages (counting the cover sheet)
reec06 review for Test ONE Print your name legibly:
circle your last name
Sign:
Poly-ID:
x = int( raw_input( "Enter a digit: " ) )
print x, str(x)*(x // 3)
print x - 1
print x
Write the output here
OR
if there will be a runtime error, state that here.
WRITE ANSWERS TO THESE QUESTIONS IN THIS DOCUMENT page 4 of 7 pages (counting the cover sheet)
reec06 review for Test ONE Print your name legibly:
circle your last name
Sign:
Poly-ID:
(10 pts ) Draw arrows to show which values the variables refer to after the
statements are executed
Show the numbers in RAM also.
(It doesn't matter where the are in the program.)
WRITE ANSWERS TO THESE QUESTIONS IN THIS DOCUMENT page 4 of 7 pages (counting the cover sheet)
reec06 review for Test ONE Print your name legibly:
circle your last name
Sign:
Poly-ID:
1. x = 3
2. y = 4
3. y += x
4. x = y
Draw the arrow showing
where x refers to after line 1.
x
Draw the arrow showing
where y refers after line 2.
y
Draw the arrow showing
where y refers after line 3.
y
Draw the arrow showing
where x refers after line 4.
x
Write the values that will be in RAM
.
.
.
.
.
.
WRITE ANSWERS TO THESE QUESTIONS IN THIS DOCUMENT page 4 of 7 pages (counting the cover sheet)
reec06 review for Test ONE Print your name legibly:
circle your last name
ANSWER KEY Sign:
Poly-ID:
True False Circle your one answer
(5 pts ) This will compile:
floatVar = float( "one hundred and two point seven" )
True False
(5 pts ) Given that a module we want to use is in a file named ralph.py, this will run:
import ralph.py
True False
(5 pts ) There is a function named rrrrr that takes one parameters in the hmmm module and we have successfully imported hmmm and the math module. This will compile:
print math.sqrt( rrrrr( math.sqrt() ) )
True False
(3 pts ) There is no way to display a number in hexadecimal notation.
True False
(3 pts ) A test is not a statement.
True False
Short Answer Questions – NOTE: these are probably harder than the ones on the test
(5 pts )
How many programmers does it take to call a function?
What are their names?
Which can break the subproblem into more subparts? How?
Then how many programmers are involved?
(5 pts ) The run time system does what when it first encounters these lines of code (what happens during the compilation phase)?
def meme( prammy, sammy ):
return 2 ** (prammy + sammy)
(15 pts ) There is a builtin in function you have never used before named oblatt.
Here is a SnakePit session showing what help for that function displays:
IDLE 2.7.1
> help( oblatt )
Help on built-in function oblatt in module __builtin__:
oblatt(...)
oblatt(object, object) -> float, float
Return these two values:
1st parameter raised to the power of the 2nd parameter
and
2nd parameter raised to the power of the 1st parameter
Obviously you cannot define this function because it is built in.
Your job is to complete the following function by writing the needed parameters and python statements that
do what the docstring for drawWeirdString says it will do.
Even though it's not the best, your function MUST use the oblatt builtin function
You do not need to show any testing for your function.
Do NOT write a main function (obviously).
Do NOT write a complete program (obviously).
ONLY complete the definition for drawWeirdString (don't forget the parameters!)
def drawWeirdString( first, second ):
''' draw a string that is the string made of the value of first raised to
the power of second repeated second rasied to the power of irst
times.
E.g.: If the calls passes in 2 and 3, the string will be: '888888888\n'
2^3 is 8 and 3^2 is 9 so there are 9 '8' characters drawn
'''
(20 pts) Show that you can break a problem into its parts by writing only the main function.
Write ONLY variable definitions and function calls – we will hire professional python programmers to create the modules you'll use that will have the definitions for all the functions you need to solve the whole problem. (Of course they have to be able to know what to write based only on your good names for the functions they will write.)
Do NOT write any function defs except main.
Do NOT write a complete program, just import needed modules and define main
Whenever you need to call a function to solve a subproblem, choose a good name for the module you want it in and choose the name you want it to be called, and call it.
We will hire someone to define the module with the function in it for you (and it will work perfectly!).
Yes, you can have local variables to solve the problem.
You may also need to create global constants.
You may assume that any of the functions will have default parameter values but only if there are meaningful default values that the the programmer designing the module for you would consider when doing good design.
You have not requested any default parameters values be provided.
When the other programmers have finished writing the definitions of the functions in the modules they will provide, your main function should solve the following problem:
Get a name (last, first and middle initial) from a database of names.
Display a pentagon made out of the letter Q.
Display a hexagon made of the middle initial
Display a solid line made of the middle initial
Display a octagon made of the letter Q
You may NOT write any calls to raw_input or print in main.
Notice that the letter Q is used more than once as the letter value used in displaying shapes.
WRITE ANSWERS TO THESE QUESTIONS IN THIS DOCUMENT page 4 of 7 pages (counting the cover sheet)
WRITE YOUR ANSWER TO THIS QUESTION IN THE BLUE BOOK
If you need "scratch" paper, use the Blue Book but cross out anything you do not want graded.
PUT YOUR ANSWERS TO THIS QUESTION IN THE BLUE BOOK
rec06 - BLUE BOOK QUESTIONs
NOTE these are not programs but we had to put these questions somewhere.
On the actual midterm you might get a real problem to solve.
All functions MUST have docstrings (of course – they help you focus on solving the problem!).
(20 pts)
Define a function that draws a line using three characters.
The length of the line should be randomly determined.
The caller should be able to give 1, 2 or 3 characters to be used in drawing the line.
When the caller doesn't provide parameters, the function should use 'X', 'Y' and 'Z' as the default values.
The first part of the line is drawn using the first parameter which is printed between 3 and 17 times, the actual quantity is randomly determined.
The second part of the line is drawn using the second parameter which is printed between 5 and 22 times, the actual quantity is randomly determined.
The third part of the line is drawn using the third parameter which is printed between 2 and 14 times, the actual quantity is randomly determined.
Here are some sample calls to this function (here named f but that's a horrible name, so don't use it!).
> f( 'A', 'B', 'C' )
AAAAAAAABBBBBBBBBBBBBBBCCC
> f( 'A', 'B', 'C' )
AAAAAAAAAAAABBBBBBBBBBBBBCCCCCCCC
> f( 'A', 'B' )
AAAAAAABBBBBBBBBBBBBBBBZZZZZZ
> f( 'A' )
AAAAAAAYYYYYYYYYYYYYYYYZZZZ
> f( )
XXXYYYYYYYYYYYYYYZZZZZZZZZZZZZZ
WRITE ANSWERS TO THESE QUESTIONS IN THE BLUE BOOK page 7 of 7 pages (counting the cover sheet)