You will need to snarf files for this lab. Those files are also here.
To get credit for lab 2, you will need to do the following by Sunday night:
Answer the following questions on the online form.
Note that this is not the correct code. This is just for testing the APT.
Run the APT by loading it into the web page, selecting the button by Gravity and then clicking on the test/run button.
How many test cases does this pass? (how many greens do you get?).
For example if the velocity is 3.0 and the time is 2.0 then that line might print:
velocity is 3.0, time is 2.0, velocity*time is 6.0
When you run the APT with the APT tester, explain where the output is printed?
Cut and paste just your function into the form.
Run your program in Eclipse. What are the two answers?
and then make the two print statements the body of this if, both need to be indented four spaces.
Run your program in Eclipse, and then run your program on the APT tester. What is the difference between them? What is the purpose of this special if statement with main?
Even though you are working on this APT in lab, you will still have to turn it in on the APT page and fill out the README that goes with it. Also make sure your name is on it with a comment.
In the README you will note that it was solved as part of lab 2 and who you solved it with.
Consider the following common children's song:
Here we go 'round the mulberry bush, The mulberry bush, the mulberry bush. Here we go 'round the mulberry bush, So early in the morning. This is the way we wash our clothes, We wash our clothes, we wash our clothes. This is the way we wash our clothes, So early Monday morning. This is the way we iron our clothes, We iron our clothes, we iron our clothes. This is the way we iron our clothes, So early Tuesday morning. This is the way we scrub the floor, We scrub the floor, we scrub the floor. This is the way we scrub the floor, So early Wednesday morning. This is the way we mend our clothes, We mend our clothes, we mend our clothes. This is the way we mend our clothes, So early Thursday morning. This is the way we sweep the house, We sweep the house, we sweep the house. This is the way we sweep the house, So early Friday morning. This is the way we bake our bread, We bake our bread, we bake our bread. This is the way we bake our bread, So early Saturday morning. This is the way we go to church, We go to church, we go to church. This is the way we go to church, So early Sunday morning.
This song was originally posted here .
Write a Python module/program to print out the lyrics to this song.
Do not use more advanced features than what we have covered in class (use print statements and functions).
Each of you should be writing your own code, but discussing how you are doing it and help each other debug their code.
It is easy, of course, to write the program using a series of print statements for each line of the song. But the goal of this lab is to take advantage of the cumulative structure of the song to avoid redundancy. Look for ways to use functions to avoid simple redundancy and functions with parameters to avoid the structural redundancy within the songs. In particular, make sure that you use no more than one print statement for each distinct line of the song. Your output of the song lyrics should be as similar as possible to what appears above, including line breaks and blank lines. Although if you cannot easily match the capitalization or punctuation, that is okay.
To start, use Eclipse and snarf the sample file for lab today called Farmer.py. Run this file to see what it does. Then create a new file named Mulberry.py for this program.
Answer the following questions. For the last question, the person filling out the form would cut and paste their code to give an example of what the group came up with.
When you snarf lab2, you'll find the Python module Multiprint.py, the code is shown here:
word = "wonderful"
count = 1
def printit():
global count,word
print count,"\t",word
count = count + 1
def f1():
printit()
printit()
def verse():
f1()
f1()
if __name__ == "__main__":
verse()
When this code is run, the output is:
1 wonderful 2 wonderful 3 wonderful 4 wonderful
If you add one more call of printit() in the body of f1() and one more call of f1() in the body of verse(), so that there are three identical lines in f1() and three identical lines in verse() the output changes to:
1 wonderful 2 wonderful 3 wonderful 4 wonderful 5 wonderful 6 wonderful 7 wonderful 8 wonderful 9 wonderfulYou'll do two things with Multiprint.py. Answer these questions as you go along.
def f1():
f2()
f2()
def f2():
printit()
printit()
def verse():
f1()
f1()
When you run this program there are 8 lines printed. Your goal is to modify the program so that it prints 256 lines.
You can add more functions, rename functions, but the body of each function other than printit() must consist of the same function call repeated -- as shown above, for example where each line is repeated twice in the functions shown.
With these modifications, how many total functions does your program have?