CompSci 6 Fall 2011 - Assignment #2

Due: Tuesday, Sept 13 by 11:59pm

10 points

For this assignment, create one PyDev Project named cps6-fall11-assign2.

Part 1: Javabat

In the PyDev project created above, create a PyDev module named javabat. For this part we are NOT going to run Python in Eclipse but rather the Javabat website lets you write and test one method at a time. Then you will copy your code into the javabat file you created so you can turn it in. Once you copy it in, you do not need to try and run it.

Go to the javabat website at http://codingbat.com/python

Work the following problems and then cut and past the code from all of these problems into the one javabat file.

  1. String_1: hello_name
  2. String_1: make_abba
  3. String_1: make_tags

Part 2: Punishment can be Fun !?!

For this part you will need to create a PyDev module in the same PyDev project as above. This time you will run your program in Eclipse.

Write a program that prints the line below exactly 1,024 times.

We all make Duke what it is

You can only use print and function call statements. You may not use loops, if statements, or any other complex flow of control statements.

You should try to minimize the number of statements and string literals in your program. For example, the program below prints ten lines using ten string literals and ten statements.

    print("We all make Duke what it is")
    print("We all make Duke what it is")
    print("We all make Duke what it is")
    print("We all make Duke what it is")
    print("We all make Duke what it is")
    print("We all make Duke what it is")
    print("We all make Duke what it is")
    print("We all make Duke what it is")
    print("We all make Duke what it is")
    print("We all make Duke what it is")

However, you could write the program using only five string literals and seven statements as follows.

    def doFive ():
      print("We all make Duke what it is")
      print("We all make Duke what it is")
      print("We all make Duke what it is")
      print("We all make Duke what it is")
      print("We all make Duke what it is")
    
    doFive()
    doFive()

To earn any points on this assignment, you must first get your program to print out the correct number of statements. You can earn significant partial credit if your program uses fewer than 500 string literals/statements. You will get extra credit if your program uses fewer than 30 string literals/statements. 

Note, you can turn on line numbering within Eclipse for Editor view by selecting Preferences -> General -> Editors -> Text Editors and select Show Line Numbers. Unfortunately, there does not seem to be any way to do it directly in the Console view.

Submitting Your Work

When you are satisfied you have completed the problems above, you should electronically submit your project through Eclipse. A submission is not considered complete unless it includes all the Python code for the project and a README file as described here.