Week 0, Problem 1:
Orientation Problem - Running Python
[30
points; individual]
Welcome!
By
completing this first EECS 110 homework problem in orientation, we hope
to
introduce you to three things:
1.
Using
the python computer language, which you'll use
in EECS 110.
2.
Using
python's IDLE editor to write and save
plain-text files (python programs).
3.
Submitting files
to Canvas.
If
you have any account problems or other questions/concerns, please ask!
Opening
up python/IDLE
1.
These
directions presume python is installed, which it should be on lab PCs. If
you're on your own machine, visit one of these two links first in order to install
Python:
for Windows PCs
for Macs
(Linux users probably already have python installed.)
- On a PC, right-click on the link below and choose
"Save Target As..." in order to download to
the desktop the file named hw0pr1.txt
from this link .
3.
On
a Mac computer, you can control-click to do download the file.
- On your desktop,
you should see the newly-downloaded file named hw0pr1.py.
You may not see the .py
extension, depending on the computer's settings.
- Right-click
that hw0pr1.py
file and choose "Edit with IDLE" or "Open with IDLE."
IDLE is the name of an editor and interactive "shell" --
basically an area for experimentation -- that comes with Python.
- You should see
an editing window with the contents of the hw0pr1.py
file -- a python program. You might also see a "Python Shell"
window. If you don't see the "Python Shell" window, you
should get one by going to the editing window's "Run" menu and
choosing "Python Shell."
Trying
out python at the python shell
- The shell is an
area for experimenting with the python language. The "prompt" is
three greater-than signs
>>>, which tells you that python is
ready to go. You might try 6*7 as a first
computation at the prompt. Caution: deep wisdom may result.
- Try computing a
googol (ten to the hundredth power). The power operator in python is two
asterisks **.
So, you would type
10**100 at the prompt. Admittedly not too
enlightening, but the
L at
the end of the result is python's indication that this is a Long number.
Running
a program from a file
- Click on the
editor window to return to the program in the hw0pr1.py file.
- You don't need
to understand this code (not yet, at least). However, you might take a
moment to see if you can guess the behavior of any of the pieces you see
there...
- To run the
program, hit the F5 key or choose "Run
Module" from the "Run" menu.
- The shell window
will automatically come up and start running the program. This program
first asks you for your name, and the cursor will already be in the right
spot to start typing. (The python shell is a bit picky about where the
cursor is -- if you move it and start typing, odd things might happen...)
- Type in your
name, hit Enter, and the program will finish running with a follow-up
message.
- You can try
again by repeating these steps and/or edit the program to change its
behavior.
- To see how
python handles errors, you might try removing one of the two equals signs
in the if line, so that it
reads if
name = 'Ionut'.
Then
hit F5 to run -- it
will tell you there is a "syntax error" and give you a chance to
fix it.
- The second
problem for this week's hw asks you to alter this program to play a
(fairly lopsided) game of rock-paper-scissors. You can do that right away
(during orientation) or you can come back to it later.
- For this
problem, the final step is simply submitting the hw0pr1.py file. It's
completely OK if you've changed it -- this is simply to ensure you can
login into Canvas and submit your homework.
Next
hw0pr2
Homework 0