This exam can be administered after the students have completed Codecademy and the tours and exercises through Graphics.
The questions on this midterm are simple programming exercises that you should be able to complete without too much trouble. There are 5 questions and you have 110 minutes, so budget 20 minutes per question, with 10 minutes left over to check your work and push it to github. Make sure you give yourself time to address each question. If you get stuck on one, take it as far as you can go, then move on to the others.
Instructions: Create a notebook in your main repository directory called Midterm
. Give it a heading 1 cell title Midterm. Answer the questions posed on this page in your notebook.
Allowed resources:
Save your notebook when you are done and be sure to push it to github before you leave.
In Robert McCloskey’s book Make Way for Ducklings, the names of the ducklings are Jack, Kack, Lack, Mack, Nack, Ouack, Pack, and Quack. This loop outputs these names in order:
prefixes = 'JKLMNOPQ'
suffix = 'ack'
for letter in prefixes:
print letter + suffix
The output is:
Jack
Kack
Lack
Mack
Nack
Oack
Pack
Qack
Of course, that’s not quite right because “Ouack” and “Quack” are misspelled.
Modify the program to fix this error.
In [1]:
#Implement your solution here
Use ipythonblocks
to create an 8x8 grid with the first initial of your last name embedded in it in a different color. Use slices and/or loops to set the values rather than setting each block by hand. Here is an example:
In [20]:
#Implement your solution here
"99 Bottles of Beer" is a traditional song in the United States and Canada. It is popular to sing on long trips, as it has a very repetitive format which is easy to memorize, and can take a long time to sing. The song's simple lyrics are as follows:
99 bottles of beer on the wall, 99 bottles of beer.
Take one down, pass it around, 98 bottles of beer on the wall.
The same verse is repeated, each time with one fewer bottle. The song is completed when the singer or singers reach zero.
Your task here is to write a program capable of generating all the verses of the song.
In [21]:
#Implement your solution here
Plot a simple graph of a sine function in the range 0 to 3 with a step size of 0.1.
In [22]:
#Implement your solution here
Create a 100x5 NumPy array called arr
of random floating point numbers between 10.7 and 36.2.
numbers.txt
as 5 columns separated by 2 spaces and formatted with 3 places after the decimal.!date
).!head
command.arr2
and use a slice to print the first ten lines of the array.
In [28]:
#Implement your solution here