athena% add wtp-eecs athena% /mit/wtp-eecs/cs/env_setup.shYou have to press enter after each line.
athena% getcopy welcome_wtp athena% lsYou should see the file welcome_wtp listed. If you don't see it, talk to the staff.
Read section 1 through 5 in the "Getting Started with Idle" handout. Follow the instructions. You should be able to use the Python shell to print messages and make basic calculations. At the end, you should have created a file HelloWTP.py that will contain your first program.
Now create a new file and write a program that will print "Hello, <your name>!!!" in a box like this:
****************************************
* *
* Hello, Harry Potter!!! *
* *
****************************************
Hint: You will need to use more than one print command. You should put each command on a new line.
Save your file as hello.py.
At the beginning, you will be writing fairly small programs and it will seem easy to remember everything you did. As the size of your programs grow, it will be more and more difficult. There will come a time when you will have to go back and look at code you have written a few months, or even a few years ago. It will feel as if someone else wrote it. Instead of having to understand what every line of code does, you can add comments to your code that explain what you were trying to do. You can add a comment using the # sign, e.g.
# Print a message to the screen print 'Hello, WTP!!!'
The comments are ignored by the interpreter. They are only used by programmers for improving the readability of the code.
Now edit the program from the previous exercise and add a comment at the beginning of the file with the file name, your name, and a sentence about what it does. You should do that for all your future programs.
Print out your code and turn it in. Look at the How to Print handout for instructions on printing.
Then submit your code electronically by typing the following command at the athena prompt:
athena% submit ps1 hello.py
In Exercise 1, we saw that we can use the Python shell as a calculator. The basic operations are:
Operator |
Operation |
|---|---|
+ |
Addition |
- |
Subtraction |
* |
Multiplication |
/ |
Division |
** |
Exponentiation |
What does the Python shell output if you try to compute 5/2?
What about 5.0/2 ?
Interesting, no? You will find out why tomorrow.
Compute 2 to the power of 32. What answer does Python give you?
If you run a 5K race in 20 minutes 30 seconds, what is your average time per mile? What is your average speed in miles per hour? Use the Python shell to help you with the calculations and write down your answer.
Hint: There are 1.61 kilometers in a mile.
Note: This problem can be done at home if you run out of lab time.
Consider the following sentence:
Alice saw the boy on the hill with the telescope.
athena% submit ps1 hello.py