111 lab5a

Computer Science 111 – Fundamentals of Programming I Programming Project 5
Due date: 11:59PM Friday 16 October

In this project you will modify two programs that explore the capabilities of data structures.

Warmup

Run the following expressions or statements in the shell:

dir(list)
help(list.append)
numbers = [10, 5, 67, 99, 32]
numbers
print(numbers)
len(numbers)
max(numbers)
min(numbers)
sum(numbers)
numbers.append(100)
numbers
numbers[0]
numbers[-1]
numbers[0:3]
numbers.reverse()
numbers
numbers.sort()
numbers
import random
for count in range(len(numbers)):
    print(random.choice(numbers), end = " ")
for count in range(len(numbers)):
    print(random.randint(1, len(numbers) - 1), end = " ")
random.shuffle(numbers)
numbers

Create a project5 directory. You should then copy the file generator.py from the webpage to this directory. Open this program with idle3 and run it. Then immediately run it again by entering main() at the shell prompt.

To Turn in

Launch idle3 and complete the following exercises. Be sure to document both the modules and any new functions that you define.

1. Make the following modifications to the original sentence generator program:

a. The prepositional phrase is optional (it can appear with a certain probability – up to you).

b. A sentence can consist of an independent clause, followed by zero or more pairs of conjunctions and independent clauses. For example, “The boy took a drink and the girl played baseball.” The independent clauses are themselves just sentences.

c. An adjective is optional, and there can be zero or more adjectives preceding a noun: “The girl kicked the little red ball with a sore foot.”

You should add new variables for the sets of adjectives and conjunctions. You can determine a probability by using random.randint. You should not have to define any new functions, with the exception of a new one for adjectives.

2. For extra credit, make your generate produce sentences that look more like ordinary English. Two kinds of adjustments you might make are:

a. Selectional restrictions on verbs: fences shouldn’t be allow throw or eat things, for example.

b. Ordering of adjectives: We say a small red shoe but not a red small shoe.