The following guidelines are expected for all homework submissions:
all over the mapon my computer or printer. USE SPACES INSTEAD. You can set up almost every modern text editor to insert spaces whenever you press the TAB key, or you can simply pound the spacebar.
pair programmingwhich is part of the Extreme Programming software development method. Feel free to collaborate in your pairs as much as you want, preferably doing the entire assignment together.
You must read chapters one and two of your textbook. Pay attention to the examples, some of which we will work (or will have worked) in class. Don't be afraid to try them out for yourself!
Check out the following web links for some interesting information. You don't have to write anything for this section, just read, watch, listen, and (above all) THINK. Be ready to talk about your thoughts in class.
natural scienceby Peter Denning
Which was the first mechanical computer?depends on a person's definition of a mechanical computing device, but there is a general agreement on which was the first computer that was both general purpose and electronic. What was it called? What was it designed to do? Who were its first programmers?
document.getElementById('scriptArea').style.backgroundColor="yellow"
document.getElementById('footer').innerHTML="blue"
var number = Math.floor( Math.random() * 100 ) + 1; for( var i = 1; i <= 10; i++ ) { var guess = prompt( "Enter guess #" + i + " (1..100)" ); if( guess < number ) { alert( "Too small" ); } else if( guess > number ) { alert( "Too big." ); } else { alert( "Got it!" ); } if( i === 10 ) { alert( "That's enough guessing" ); } }
alert( location );Why do you think something was alerted, even though you did not define the variable
location
?Windows version: Download and install Python from this location. Be sure you
are installing Python version 3.6.2, and install everything. When installation is completed, start
the Python command line from the START button. You will see a command window open with some text about the version
followed by the Python prompt of three greater-than
signs [>>>
]. This is the point at which
you type in the code that follows.
NOTES: DO NOT COPY AND PASTE THE CODE! Type the code in by hand. You DO NOT need to type the triple dots at the
start of the lines – python will output those for you to indicate you are continuing the same block. For
example, type def fib(n):
and press the enter key. You will see the triple dot prompt appear on the next line.
Leave some space and type the a, b = 0, 1
line, then press the enter key. You'll see the triple dots again on
the next line. Keep doing this until you get to the end. On the last line where it says [note: just press…
DO NOT enter the note text, simply press the enter key. This will end the function definition. Finally, type the line
fib(1000)
to run your function program. Here is the code:
>>> def fib(n): ... a, b = 0, 1 ... while a < n: ... print(a, end=' ') ... a, b = b, a+b ... print() ... [note: just press the enter key here] >>> fib(1000)
MAC version: Download and install Python from this location. Be sure you
are installing Python version 3.6.2, and install everything. When installation is completed, open the applications window
and start the IDLE Python GUI program. Select File -> New file
from the menu. You will see a second window open
into which you can type the program text. When you have typed it according to the following paragrah, select
Run -> Run module
to run your program. The window will change back to the IDLE GUI, and you should see the output
of your program appear. NOTE: you will likely be asked to save your program before running it. This is normal.
NOTES: DO NOT COPY AND PASTE THE CODE! Type the code in by hand.
MAC version 2: Use the Python version that is already installed, which comes with the Mac OS. Start a terminal
window from the Applications -> Utilities
folder in the finder, then type python
into the terminal window.
You will see the Python prompt of three greater-than
signs [>>>
]. This is the point at which
you type in the code that follows.
Be CAREFUL to maintain proper indentation — Python is sensitive to it! Here's the code:
>>> def fib(n): a, b = 0, 1 while a < n: print(a, end=' ') a, b = b, a+b print() >>> fib(1000)
If everything goes right, you should see the set of Fibonacci numbers for all values less than 1000. In other words, you should see: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
Now start the idle
Python Graphical User Interface (GUI) program. Create a new editor
window by selecting File->New File
, and enter the following program into the window
(Cut and paste). Save the file using the File->Save As
menu selection, then select the
Run->Run Module
option. Describe what happens. Here is the code:
numbers = [2, 4, 6, 8] product = 1 for number in numbers : product = product * number print( 'The product is:', product )
If everything goes right, you should see the Python GUI window respond with a RESTART
message, followed by four lines of text which contain the product of 1*2, 1*2*4, 1*2*4*6, and
1*2*4*6*8; the results should be 2, 8, 48, and 384.
You have now installed Python, and can use it for the rest of the exercises that will occur during this semester (and beyond!). Feel free to experiment with some of the problems in the book that you have been given on line.