NextClass Assignment 1
- Go through each exercise.
- Type in each one exactly.
- Make it run.
- Write the exercise using the Calico IDE file editor.
- From within Calico, Run the exercise you wrote.
- Fix the exercise if it is broken.
- Repeat.
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:- Write a print function invocation that displays your name.
- Write a print function invocation that displays the following text:
Python's the best!
- 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- Make sure Finder is the frontmost/active application.
- From Finder's Go menu, select Connect to Server...
- In the resultant dialog, enter cifs://ruby.cc.denison.edu for the "Server address".
- If offered a choice, select Shared as the volume to mount, and authenticate with your Denison credentials.
- Make sure Finder is the frontmost/active application.
- From Finder's Go menu, select Computer