After the lab, you should be proficient at
wc
command in LinuxYou will want to copy the files from your lab10 directory so that you can extend your Music Management program.
wc
Commandwc ../lab10/*.py
wc
stands for "Word Count". We called the "word
count" command on all the *.py files (i.e., the Python scripts, not
other files or directories) in your lab10 directory. The first column
of output is the number of lines, the second is the number of words,
and the third is the number of characters in each file. The total for
all the files is listed in the last line of output.
wc
command so that you only see the number of
lines, using the command-line argument "-l", i.e.,
wc -l ../lab10/*.py
>
operator, i.e.,
wc -l ../lab10/*.py > mywc.txt
more
or cat or opening it in a text editor,
such as jEdit. We will come back to this file later.
You may want to get one of the new albums files
added by your peers to help with your testing. They've been added to
the handouts/lab10/albums
directory too.
Example Run:
Select one of the following options: (V)iew the library (I)mport songs into the library (S)ort the library (F)ind songs by title E(X)port the library to a file (Q)uit the program Which option do you want? f What is the title of the song you want to find? misunderstood 2 songs match that title: Misunderstood Better Than Ezra Closer 00:03:47 Misunderstood Better Than Ezra Greatist Hits 00:03:45 Select one of the following options: (V)iew the library (I)mport songs into the library (S)ort the library (F)ind songs by title E(X)port the library to a file (Q)uit the program Which option do you want? f What is the title of the song you want to find? change Your mind 2 songs match that title: Change Your Mind Sister Hazel Fortress 00:04:22 Change Your Mind The Killers Hot Fuss 00:03:10
wc
command again. This time, view the size of
the .py files in your lab11 directory. Add the output from this
command to your mywc.txt
file using
the >>
operator. An example of
running wc
from your lab11 directory is
wc -l *.py >> mywc.txt
Now, when you view your mywc.txt file, you should be able to compute how many more lines of code you added to your files for this part of the project. Document this difference in comments in your driver program.
After you've developed a correct solution to each program, restart IDLE or close and reopen the IDLE "shell" by running the program again (using F5), demonstrate that the program works using several good test cases, and save the output to a file named lab11.x.out, where x is the problem number.
[ [0,1,2], [1,3,5], [2,5,8] ]
Simply print the list; do not worry about formatting yet.
To make each row, you can either use the range
function or append to a list, but do not create the list by
typing twod=[ [0,1,2], [1,3,5], [2,5,8] ]
0 1 2 1 3 5 2 5 8
connectfour.py
, csplot.py
,
and games.py
from /home/courses/cs111/handouts/lab11
.
games.py
and look at
the ConnectFour
class. Familiarize yourself with its
attributes and how other methods we discussed are implemented.
python connectfour.py
makeMove
method and its comment
and implement the method. Adhere to the method's comment
description when implementing the method.
play
method, as
described in the code. Run and test your game.
You should only have to modify games.py
and
none of the other files.
You won't submit any output from this program.
In groups of one to three people, implement the _isDraw (up to 5 pts) and/or _isWon methods (up to 10 pts) of the ConnectFour class. You can receive partial credit.
Alternatively, you can create simulate a player (so that you make
it a one-player game). Write a method
called makeBestMove
that chooses the "best" column to
place the checker (up to 10 pts). A naive first approach is to
randomly pick a column. A more sophisticated approach is to assign a
score to each column that says how "good" a column is for you and
select the column with the highest score. What properties would make
the column's score increase?
If you work in a group, indicate all group members in comments in the code.
turnin
directory. (Review the UNIX handout if
you don't remember how to do that.)
printLab.sh
command to create a file to
print out. You should probably print from the labs
directory. You may get a warning about the directory containing
subdirectories. As long as you don't get an
enscript
error about unknown special escape, you
should be okay.
gv
command, such as gv lab11.ps
Print the file using the lpr
command
introduced in the first lab.
Labs are due at the beginning of Friday's class. You should hand
in the printed copy at the beginning of class, and the electronic
version should be in the turnin
directory before 1:20
p.m. on Friday.
Ask well before the deadline if you need help turning in your assignment!