| Assignment 1: Python Warm-up |
|
CSE 415: Introduction to Artificial Intelligence The University of Washington, Seattle, Spring 2026 |
|
The reading for this assignment is
Python as a Second Language.
|
|
Due Wednesday, April 9
at 23:59 PM, via GradeScope.
|
| Overview: This assignment consists of several Python exercises designed to help you get more familiar with the language. If you are new to Python, do the associated reading. Otherwise, this is mainly a refresher with a little problem-solving thrown in. We recommend Python 3.14 for this assignment. |
| Installing Python: You should use one of the following three choices for a Python installation for CSE 415:
|
| Starter Code: Starter code is available here: a1-starter-code.zip.
The file python -m unittest test_functions.py |
| Part 1: Defining Miscellaneous Functions (30 points).
Complete the definitions of the following functions...
def is_quintuple(n):
"""Return True if n is a multiple of 5; False otherwise."""
pass
def last_prime(m):
"""Return the largest prime number p that is less than or equal to m.
You might wish to define a helper function for this.
You may assume m is a positive integer."""
pass
def quadratic_roots(a, b, c):
"""Return the roots of a quadratic equation (real cases only).
Return results in tuple-of-floats form, e.g., (-7.0, 3.0)
Return the string "complex" if real roots do not exist."""
pass
def new_quadratic_function(a, b, c):
"""Create and return a new, anonymous function (for example
using a lambda expression) that takes one argument x and
returns the value of ax^2 + bx + c."""
pass
def perfect_shuffle(even_list):
"""Assume even_list is a list of an even number of elements.
Return a new list that is the perfect-shuffle of the input.
For example, [0, 1, 2, 3, 4, 5, 6, 7] => [0, 4, 1, 5, 2, 6, 3, 7]"""
pass
def list_of_5_times_elts_plus_1(input_list):
"""Assume a list of numbers is input. Using a list comprehension,
return a new list in which each input element has been multiplied
by 5 and then has 1 added to it."""
pass
def double_vowels(text):
"""Return a new version of text, with all the vowels doubled.
For example: "The *BIG BAD* wolf!" => "Thee *BIIG BAAD* woolf!".
For this exercise assume the vowels are
the characters A,E,I,O, and U (and a,e,i,o, and u).
Maintain the case of the characters."""
pass
|
| Part 2: Defining Methods for States and Operators (20 points).
In this part of the assignment, you'll write methods for classes that deal with state-space search. These methods are not implementations of search algorithms; those will come in the second assignment. Rather, they deal with the basic infrastructure needed for problem formulation. In problem solving, a state is a data object that represents the components of a possible solution or partial construction in attempting to find a solution, in one particular configuration. For example, in Tic-Tac-Toe, a state is a representation of the board at one particular point in a game. At the beginning of the game, there is the initial state which represents the empty 3-by-3 grid. Each time a move is made in the game, one state is used to construct another. Consider the following class definition for states of Tic-Tac-Toe. class TTT_State: def __init__(self): '''Create an instance. This happens to represent the initial state for Tic-Tac-Toe.''' self.board = [[" ", " ", " "], [" ", " ", " "], [" ", " ", " "]] self.whose_move = 'X'Define the following methods for this class.
def __str__(self):
'''Return a string representation of the
state that show the Tic-Tac-Toe board as a 2-D ASCII display.'''
pass
def copy(self):
'''Return a new instance with the same board arrangement
and player to move.'''
pass
def __eq__(self, other):
'''Return True iff two states are equal.'''
pass
Consider the following class definition for operators of Tic-Tac-Toe.
class TTT_Operator:
def __init__(self, who, row, col):
self.who = who
self.row = row
self.col = col
Define the following methods for this class of operators.
def is_applicable(self, state):
'''Return True iff it would be legal to apply
this operator to the given state.'''
pass
def apply(self, state):
'''Return a new state object that represents the
result of applying this operator to the given state.'''
pass
|
| Part 3: Coding with Generative-AI Assistance (15 points + 35 points for the Learning Diary Entry).
In this part of the assignment, you'll prompt an AI agent such as Claude, Gemini, or ChatGPT to develop a text-processing program. The program should be written in Python (version 3.14). It may use any standard library that comes with the Python distribution and does not have to be separately installed. Your program will provide answers to questions of the form "How common are the words used in webpage X?". (Note that it does NOT have to read and understand any question like this, but it will simply compute the answer when given a webpage address.) It should accept as input a text string (given on the command line) representing a URL for a web page. The program should access the page and read its contents into a text buffer (which can be a list of strings, where each string is one line of the file). It will process each word by looking it up in a special dictionary (linked below) that indicates how common the word is. It will use that information to update a running sum, and to update entries in a type of histogram structure, that keeps track of how many words seen are in each of one-hundred "bins" (ranges of commonness values). At the end, your program will print out a report containing the overall indicator of the commonness of words on the web page, as well as the histogram normalized in terms of a list of percentages. The special dictionary to use is a list of 10000 words compiled by Google and listed in order of commonness, starting with "the" in position 0. It's in this file.
Name your program file The format of your output is suggested by the text below. This sample is not from an actual run of any code, but simply to show the desired format. REPORT OF WEB-PAGE COMMONNESS OF VOCABULARY. The analysis program was developed by John Doe with assistance from Gemini for CSE 415. Analysis and report created, April 1, 2026. Webpage address: https://www.warnerbros.com/movies/youve-got-mail Overall commonness of words: 0.237, on a scale of 0 to 1. Commonness Range Example word Bin percentage ---------------- ------------ -------------- 0-99 the 26 % 100-199 day 6 % ... 9900-9999 - 0 %We'll assume the overall commonness indicator c is computed by taking the mean index m and putting it into this formula: The mean index is computed by summing the indices of all the word occurrences, and dividing by the total number of occurrences. If some word occurs 19 times, then it will contribute more to the total and have more influence on the mean than a word occuring fewer times, since its index gets added into the total each time the word is seen in the webpage. Each bin or range is shown in the left column. The word "the" has index 0, which falls within the range of the first bin. The example word should be that word seen in the document that has the lowest index within its bin. If there is a bin in which no word from the document falls, then a dash is put in the example word column. The third column shows what percentage of words in the webpage fell into each bin. The example of the format above shows only 3 rows of data in table, with an additional line showing "...". Your program's actual output should have 100 rows, with one row per bin. |
| About Style
In Assignment 1, we do not plan to grade for coding style.
However, the staff reserves the right to deduct points for sloppy formatting or lack of comments or comments that are inconsistent, misleading, irrelevant or very unclear in their context. Also, we encourage students to become aware of PEP 8 -- Style Guide for Python Code, and code accordingly. The code we use in this course does not necessarily conform, but it is a good idea to be aware of these suggestions. |
Frequently Asked Questions
|
Turn-In Instructions
Turn in four files:
|
| Updates and Corrections
If needed, updates and corrections will be posted here, and/or in ED. Last updated: 2026-Mar-26@23:12. |