Computer Science 110
Foundations of Computer Science

Denison

NextClass Assignment 1

This assignment is expected to be completed in Calico and consists of basic exercises to get our feet wet with Python. It is more about the actual doing of the exercise than it is about "turning something in", although in the process, you will create a number of simple Python script files and will turn them in as a result of completing this assignment. In learning to program, you will need to
  1. Go through each exercise.
  2. Type in each one exactly.
  3. Make it run.
You must type each of these exercises in manually. If you copy and paste, you might as well just not even do them. The point is to gain programmer-centric skills of paying attention to detail, ferreting out syntax and logical mistakes, and training ourselves to see small textual differences (in this case, between what is given to you and what you type in). You are training your hands, your brain, and your mind in how to read, write, and see code. All of these get lost if you copy and paste. For this assignment, the plan is very simple:
  1. Write the exercise using the Calico IDE file editor.
  2. From within Calico, Run the exercise you wrote.
  3. Fix the exercise if it is broken.
  4. Repeat.
You are encouraged to install the necessary software and create and execute the exercises on your own computer.

Exercise 1

Suppose you want to write a Python program that displays the following three lines of text:
Nudge nudge
Wink wink
Know what I mean?

To write the program, you should use the Calico IDE to create a new text file, name it
nc1-1.py, and edit its contents to contain the following statements:
def main():
    print('Nudge nudge')
    print('Wink wink')
    print('Know what I mean?')

main()

Using the green 'play' buton/circle, run the program and observe the output. If created and executed correctly, you should get exactly the desired lines of output.

Exercise 2

Next try a slightly more involved version, saving in a text file named nc1-2.py:
def main():
    print("Hello World!")
    print("Hello Again")
    print("I like typing this.")
    print("This is fun.")
    print('Yay! Printing.')
    print("I'd much rather you 'not'.")
    print('I "said" do not touch this.')

main()

There are some variations here from the first exercise. Before you run the program, predict what the output to the console window will be. Reason about how the print function works. If you get a syntax error, examine all of the error message and try to interpret what it is trying to tell you. Can you make sense of it? If you do not get a syntax error, introduce one by deleting the final " or ' (depending on the line). Then save the file and rerun it to see the syntax error message given by the Python interpreter. As above, try to make sense of the error message.

Before moving on to the next exercise, correct your nc1-2.py file so that there are no errors once again. The text in the output pane should match the following:


Hello World!
Hello Again
I like typing this.
This is fun.
Yay! Printing.
I'd much rather you 'not'.
I "said" do not touch this.

Exercise 3

The next exercise lets you write your own print statements. Create a text file named nc1-3.py in the Calico IDE with Python print functions that satisfy the following:
  1. Write a print function invocation that displays your name.
  2. Write a print function invocation that displays the following text:
    Python's the best!
    
  3. Write a print function invocation that displays the following text:
    The cat said "meow."
    

Like the above examples, the set of print function invocations should be indented and grouped together beneath a line that reads:

def main():
and the last line in the file is an unindented line that reads:
main()
So when I execute my version of nc1-3.py, I get the following output:
Tom Bressoud
Python's the best!
The cat said "meow."

Exercise 4

In this exercise, we will complicate things by making the exercise longer, thus increasing the chances for syntax errors, and we will also complicate things by having the print functions display more than one thing, and some of the work will involve how Python performs the evaluation of arithmetic expressions.

See if you can predict and/or reason about what the following program will do:


def main():
    print("I will now count my chickens:")
    
    print("Hens", 25 + 30 / 6)
    print("Roosters", 100 - 25 * 3 % 4)
    
    print("Now I will count the eggs:")
    print(3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6)
    
    print("Is it true that 3 + 2 < 5 - 7?")
    
    print(3 + 2 < 5 - 7)
    
    print("What is 3 + 2?", 3 + 2)
    print("What is 5 - 7?", 5 - 7)
    
    print("Oh, that's why it's False.")
    
    print("How about some more.")
    
    print("Is it greater?", 5 > -2)
    print("Is it greater or equal?", 5 >= -2)
    print("Is it less or equal?", 5 <= -2)

main()

The correct result when the above program executes should match the following. If it does not, then you should look for subtle differences in what you typed versus the code given on this page. Be prepared to explain why the result came out as it did. You may have to explore the meaning of some of the Python operators (like '%') in order to arrive at satisfactory explanations.
I will now count my chickens:
Hens 30.0
Roosters 97
Now I will count the eggs:
6.75
Is it true that 3 + 2 < 5 - 7?
False
What is 3 + 2? 5
What is 5 - 7? -2
Oh, that's why it's False.
How about some more.
Is it greater? True
Is it greater or equal? True
Is it less or equal? False

Submitting Your Work

Each of you have access to a Network Drive here at Denison called your "Share" drive. It becomes accessible through the file system on the majority of lab computers around campus, including when you use your Denison credentials to log in to one of the Desktop machines in Olin 217. On Windows based computers, it may be mounted as the "S:" drive. On Macintosh computers, you may have to start by "mounting" the network drive. You do this by
  1. Make sure Finder is the frontmost/active application.
  2. From Finder's Go menu, select Connect to Server...
  3. In the resultant dialog, enter cifs://ruby.cc.denison.edu for the "Server address".
  4. If offered a choice, select Shared as the volume to mount, and authenticate with your Denison credentials.
If doing this the first time, this will give you a Finder windown with the Network Disk volume open in the window. If the mount happened on your login to the machine, and you just need to get a Finder window starting at the Share Drive, then take the following steps:
  1. Make sure Finder is the frontmost/active application.
  2. From Finder's Go menu, select Computer
This will open a Finder window and you can select the Shared volume. For all users, once you are at the Share drive, you will navigate from there through the BRESSOUD folder to the CS110-01 folder (for both class sections) to the ASSIGNMENT-INBOX folder to the folder with your own login-id. To submit this assignment, you simply gather the four Python script files into a newly created folder called NC1 and copy that folder, along with its Python script files (nc1-1.py to nc1-4.py), into your Assignment Inbox (the subfolder with your own login).