The assignments will be graded out of 100 points. Create a text document entitled answers.xxx (where you replace xxx with whatever extension is appropriate, depending on the file format you use). Acceptable file formats are plain text, Word document, OpenOffice document, and PDF. Put your name and UTA ID at the top. Your answers that are not part of a program will be added to this file. Each task below will instruct you where to put your answers.
count_letters(in_file, out_file)
that:
Each line of the output file should be a letter, followed by a space, followed by the number of occurrences for that letter. Letters should appear in alphabetical order (the program should NOT separate upper-case from lower-case letters). For example:
a 12 b 5 c 21 ...Save your function in task1_functions.py, and your main code in task1_main.py.
The file albums.txt contains a list of albums that are in Rolling Stone Magazine's list of top 100 albums of all time. Each line contains the name of a band, the name of an album, and the date the album was released. For example:
Beatles - Revolver (1966) ...
Design a function read_albums(filename)
that:
band1: number1 band2: number2 band3: number3
Save your function in task2_functions.py, and your main code in task2_main.py.
Design and program the game, Tic-Tac-Toe. Tic-Tac-Toe is a two-player game played on a 3x3 grid in which the players alternate turns and select a grid square in which to place one of their pieces. One player uses the letter X for pieces, and the other uses the letter O. A player wins the game by placing three of his pieces in a row, either vertically, diagonally or horizontally. For example, X wins the following game:
X X X O O X X O O
You are free to make any design decisions you see fit. For example, which data structure you choose to represent the playing board. This is what you must complete (anything additional is up to you):
It should be stressed that you will receive partial credit if you design and implement some useful functions for the game, even if you can't finish everything.
In answers.xxx document, describe the design of your program. What functions are you creating, and what are their arguments and return values? What does each function do, in English? What functions you deem necessary is entirely up to you. Just be sure to discuss each one you create. This is NOT the place to say HOW a function is implemented, the goal in this document is to clearly describe WHAT useful thing each function computes.
Also, please state explicitly which function is the top-level function (i.e., the function that a user needs to call to play a game).Implement the code for your functions and save them in a file named tic_tac_toe_functions.py.
The file system on a computer can be represented as a tree. The directories are connected with branches and the files are the leaves on the tree. Consider the following directory structure:
___________[C:]___________________ | | | __[dir1]____________ file6 [dir5] | | | | file1 [dir2] __[dir4]_____ file7 | | | | [dir3] file3 file4 file5 | file2
This directory structure can be represented by nested lists in which each directory is a list containing files and/or other directories (also represented as lists). For example, the above directory structure could be represented as:
C = [ ['file1', [ ['file2'] ], ['file3', 'file4', 'file5'] ], 'file6', ['file7'] ] # | | | |_______| | |_________________________| | |_______| | # | | | dir3 | dir4 | dir5 | # | | |___________| | | # | | dir2 | | # | |____________________________________________________| | # | dir1 | # |____________________________________________________________________________| C:
The C directory is the external list. Inside the C list is another list representing dir1, file6, and another list representing dir5. Each of those directories contains either more lists representing subdirectories, files, or both. Write a function that traverses a tree structure represented by such nested lists and prints the filenames one per line. The tree can be arbitrarily deep and each directory may or may not contain files or other directories. Here are a few example lists and their respective output:
# Input 1 C = [['file1', [['file2']], ['file3', 'file4', 'file5']], 'file6', ['file7']] # Output 1 file1 file2 file3 file4 file5 file6 file7 # Input 2 C = [[['answers.txt'], 'task12.py', [['hello.txt'], 'pagefile.sys']], 'explorer.exe'] # Output 2 answers.txt task12.py hello.txt pagefile.sys explorer.exe # Input 3 C = ['a.txt', 'file.txt', [[[[['hello.txt', 'bye.txt'], 'b.txt']]], 'last.txt']] # Output 3 a.txt file.txt hello.txt bye.txt b.txt last.txt # Input 4 C = [[[[[[[[[[[[[[[[[[['my_file.txt']]]]]]]]]]]]]]]]]]] # Output 4 my_file.txt
If your output is in a different order, that is fine, as long as it is all there. Save your function in task5_functions.py. Save your main program in task5_main.py.
Mr. Style is needing a program to help him get dressed in the morning. He needs a function, dress_me, that:
For example, if he ran:
shirts = ['white', 'blue'] ties = ['purple', 'yellow'] suits = ['grey', 'blue'] combinations = dress_me(shirts, ties, suits) for combo in combinations: print combo
It would print something like:
('white', 'purple', 'grey') ('white', 'purple', 'blue') ('white', 'yellow', 'grey') ('white', 'yellow', 'blue') ('blue', 'purple', 'grey') ('blue', 'purple', 'blue') ('blue', 'yellow', 'grey') ('blue', 'yellow', 'blue')
Write a function that meets Mr. Style's requirements. The lists can be
arbitrarily long (i.e., they can have more than 3 elements). You may find it useful to use nested for
loops. Save your function as task6_functions.py. Save your main program (that contains your tests) as task6_main.py. Your main program
should contain your selection of good test cases.
The assignment should be submitted via Blackboard. Submit a ZIPPED directory called assignment7.zip (no other forms of compression accepted, contact the instructor or TA if you do not know how to produce .zip files). The zipped directory should contain your answers.xxx document and all the Python code files (task5.py, task6.py, etc).