Lab 6

Lab 6

ITP 115 – Programming in Python

p. 1 of 5

Lab 6 – Sentence Generator

Goals


Familiarity with lists and list manipulation



Use of the random library

Setup


Create a new PyCharm file in your desired directory



When you name the code, use the following naming convention
ITP115_l#_lastname_firstname
(replace # with this lab number)
Your new file must begin with comments in the following format (replace the



name and email with your actual information):
# Name
# ITP 115, Fall 2016
# Lab practical L^ (replace ^ with this lab number)
# USC email

Requirements
Your program must perform the following:


Write a program that will generate a sentence with the following format:



ARTICLE NOUN VERB ARTICLE NOUN
Use lists to store words of each type (i.e. have a list of articles, a list of nouns,
etc.). The program will start with a few words in each list.



Allow the user to select from 5 different options:
1. View all words
2. Add new words
3. Delete old words
4. Generate sentence
5. Exit



When the user selects from options 2 or 3, ask the user what type of word they
would like to view, add, or delete.



If the user enters an option other than 1-5, display an error message.



Hints:
o numbers = [1, 3, 4]

ITP 115 – Programming in Python

p. 2 of 5

num = random.choice(numbers)
returns an element from numbers selected randomly
o numbers.append(6)
adds 6 to the list
o numbers.remove(6)
removes 6 from the list
Remember that in order to remove an item from a list, it must first already
exist in the list.

Sample Output
Example 1:
Welcome to the Sentence Generator
Menu
1) View Words
2) Add Words
3) Remove Words
4) Generate Sentence
5) Exit
> 1
articles: ['a', 'the']
nouns: ['person', 'place', 'thing']
verbs: ['danced', 'ate', 'froliced']
Welcome to the Sentence Generator
Menu
1) View Words
2) Add Words
3) Remove Words
4) Generate Sentence
5) Exit
>...

Similar Essays