Description
Lab 4
Attached Files:
lab4 help.txt (2.146 KB)
lab4-example.py (1.397 KB)
LAB4-Day1.py (921 B)
LAB4-Day2.py (1,021 B)
LAB4-Day3.py (926 B)
Objectives
- Doing more with lists/dictionaries and introducing files.
Overview
- This will extends the previous lab to allow the user to display the resulting story with several potential "dynamic" modifications to their input.
Instructions
- You should first create two files, one for the story template and one for the list of words.
- Your program should read a "story template" and "word dictionary" from input files and write the output to a file to the screen.
- The filenames and "conversion type" (see below) should be read from the "command line" when the program is launched.
- For example:
LAB4.py 1 story_template.txt input_words.txt
- If the user launched the program without the correct parameters, a usage message should be shown (such as):
- USAGE: LAB4.py <CONVERSION> <STORY_TEMPLATE> <INPUT_DICTIONARY>
CONVERSION: 1 for UPPER CASE, 2 for LOWERCASE, etc...
- USAGE: LAB4.py <CONVERSION> <STORY_TEMPLATE> <INPUT_DICTIONARY>
Conversion Types (of just your input words, not the whole story):
- All UPPER CASE
- All lower case
- All Capitalized Case
- As entered (i.e., no changes)
NOTES:
- For more information on strings:
- See http://www.diveinto.org/python3/strings.html
- And specifically http://www.diveinto.org/python3/strings.html#common-string-methods for manipulations you can perform on strings.
- For more information on files:
- Writing: http://www.diveintopython3.net/files.html#writing
- Reading one line at a time: http://www.diveintopython3.net/files.html#for
- (The Sample I provided reads the entire file into memory. Though this is fine for small files, a very large file would be better processed one line at a time.)
- (The Sample I provided reads the entire file into memory. Though this is fine for small files, a very large file would be better processed one line at a time.)
- Remember: You can make up your own story, or just grab a short piece of text from somewhere and edit it into your program, deleting the words you intend on filling in with your own. But In the interest of Academic Integrity, be sure to cite the source of any text you choose to grab!
Example input files:
Story file:
I have a dog named {PETNAME} who barks a lot
and loves to {ACTIVITY} every day.
Words dictionary:
PETNAME=Spot
ACTIVITY=Bark
Submit
- Your final Python program .py file and associated input files.
- Remember it should be able to run as a "command-line" application.
- Please call your program LAB4.py and be sure to include your name in the program comments.

User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Explanation & Answer
Review
Review

Anonymous
Very useful material for studying!

Studypool
4.7

Trustpilot
4.5

Sitejabber
4.4
24/7 Homework Help
Stuck on a homework question? Our verified tutors can answer all questions, from basic math to advanced rocket science!
Most Popular Content

Northern Virginia Community College Programming Repetition Discussion
In real-life almost every task that we do involves repetition. Discuss in 600 words your position and illustrate this usin ...
Northern Virginia Community College Programming Repetition Discussion
In real-life almost every task that we do involves repetition. Discuss in 600 words your position and illustrate this using a real-life situation.

CSC 325 case problem 7
case problem 2Carly's Catering provides meals for parties and special events. In previous chapters, you have developed a c ...
CSC 325 case problem 7
case problem 2Carly's Catering provides meals for parties and special events. In previous chapters, you have developed a class that holds catering event information and an application that tests the methods using four objects of the class. Now modify the Event and EventDemo classes as follows:Modify the method that sets the event number in the Event class so that if the argument passed to the method is not a four-character String that starts with a letter followed by three digits, then the event number is forced to A000. If the initial letter in the event number is not uppercase, force it to be so.Add a contact phone number field to the Event class.Add a set method for the contact phone number field in the Event class. Whether the user enters all digits or any combination of digits, spaces, dashes, dots, or parentheses for a phone number, store it as all digits. For example, if the user enters (920) 872-9182, store the phone number as 9208729182. If the user enters a number with fewer or more than 10 digits, store the number as 0000000000.Add a get method for the phone number field. The get method returns the phone number as a String constructed as follows: parentheses surround a three-digit area code, followed by a space, followed by the three-digit phone exchange, followed by a hyphen, followed by the last four digits of the phone number.Modify the EventDemo program so that besides the event number and guests, the program also prompts the user for and retrieves a contact phone number for each of the sample objects. Display the phone number along with the other Event details. Test the EventDemo application to make sure it works correctly with valid and invalid event and phone numbers.Save the files as Event.java and EventDemo.java.case problem 1Sammy's Seashore Supplies rents beach equipment to tourists. In previous chapters, you have developed a class that holds equipment rental information and an application that tests the methods using four objects of the class. Now modify the Rental and RentalDemo classes as follows:Modify the method that sets the contract number in the Rental class so that if the argument passed to the method is not a four-character String that starts with a letter followed by three digits, then the contract number is forced to A000. If the initial letter in the contract number is not uppercase, force it to be so.Add a contact phone number field to the Rental class.Add a set method for the contact phone number field in the Rental class. Whether the user enters all digits or any combination of digits, spaces, dashes, dots, or parentheses for a phone number, store it as all digits. For example, if the user enters (920) 872-9182, store the phone number as 9208729182. If the user enters a number with fewer or more than 10 digits, store the number as 0000000000.Add a get method for the phone number field. The get method returns the phone number as a String constructed as follows: parentheses surround a three-digit area code, followed by a space, followed by the three-digit phone exchange, followed by a hyphen, followed by the last four digits of the phone number.Modify the RentalDemo program so that besides the contract number and minutes, the program also prompts the user for and retrieves a contact phone number for each of the sample objects. Display the phone number along with the other Rental details. Test the RentalDemo application to make sure it works correctly with valid and invalid contract and phone numbers.Save the files as Rental.java and RentalDemo.java.

NVCC Programming Variables and Methods Worksheet
Just like we developed the Fruit parent class in lesson 5, Come up with a Parent and two child class examples on your own. ...
NVCC Programming Variables and Methods Worksheet
Just like we developed the Fruit parent class in lesson 5, Come up with a Parent and two child class examples on your own. What variables/characteristics would remain in the parent class and what is different from the child classes in terms of variables and methods. Do not repeat any other student's classes that posted before you. You do not have to create/add the code. Just describe the classes in the discussion.

mySQL Worksheet
***Login information and student schema will be given***In this lab, you will learn how to write Advanced queries using Ag ...
mySQL Worksheet
***Login information and student schema will be given***In this lab, you will learn how to write Advanced queries using Aggregate Functions and Table Joins. You will write 10 SQL SELECT statements to query the STUDENT schema. Your Select Statements should run error-free and should be valid.Submit two separate files: one plain text file (.txt or .sql file) with your SELECT statements only; and the other document (doc/docx/pdf) include both your SELECT statements and your query results (copy and paste text or screen shots). The instructor and TA should be able to run your plain text source file as script and generate the same output as shown in your result document.Q1. List all courses that have "Intro to Information Systems" as prerequisite. (HINT: use a subquery)Q2. List all courses with above average cost. Display course description, cost, and the average cost of all courses. (HINT: use a subquery)Q3. For each zip that has at least one instructor, list the total number of instructors in that zipcode.Q4. For each city in the state of CT, list the total number of students live in that city. Display city, state, number of students in descending order.-- AGGREGATION OF FULL RESULT SETQ5. Find the minimum, maximum, and average grade of final exams in sections taught by Todd Smythe.Q6: For all students who took "Intro to Information Systems", calculate the highest, lowest, and average midterm exam grade for each section. Display Section No and calculation results.-- TABLE JOIN WITH HAVING-CLAUSEQ7. List the instructor id and name of the instructors that teach fewer than 10 sections regardless of student enrollment.Q8. Show which city has the most students. Display city and state, and number of students.Q9: List all zipcodes where at least three students AND at least four instructor reside. Show zip, state and city.Q10: List all cities that have 10 or more students and instructor combined. Show city, state, number of student residents, number of instructor residents, and total student/instructor residents in that city. Sort by total in descending order. Learning Resourceshttps://www.w3schools.com/sql/sql_join.asphttps://docs.oracle.com/database/121/SQLRF/functions.htm#SQLRF006

Iglobal University Time Complexity Heap Operation Programming Solved Practice
1. What is the time complexity of 'Build Heap' operation? Build Heap is used in building a max(or min) binary heap f ...
Iglobal University Time Complexity Heap Operation Programming Solved Practice
1. What is the time complexity of 'Build Heap' operation? Build Heap is used in building a max(or min) binary heap from a given array. “Build Heap” is used in Heap Sort as a first step for sorting. (25 Points)
2. Build the Initial heap from the following array. Each element remains in its place after the build. (35 Points)
32, 8, 20, 5, 15, 14, 29, 9, 11, 1, 4
3a. Describe an 'array' data type. (what does the array data type mean.)
3b. Describe (with example) how to create an array in C/C++
3c. Describe (with example) how to create an array in Python.
3d. Describe (with example) how to create an array in Java.
4.What is heap sort? What are the pros and cons in using this sorting method. State some uses.
Similar Content
ENGR 102 ASU Climate Change Causes and Effects MATLAB Project
ENGR102: Engineering Problem Solving 2
Project 1 – Air Pollution
Project Description
Introduction to the Problem:
Air po...
Programming Essentials question 32
The call stack is where the computer stores the list of exceptions. True False ...
ISSC 431 American Military University The Process of Black Box Testing Paper
Assignment Instructions:The assignment must be a minimum of one (1) full
page in length with a minimum of two (2) outsid...
CUS Javascript Game Puzzle Question
Eight Puzzle
For your first project, you will develop the 8-puzzle game using JavaScript.
To turn in this assignment, you ...
EGN 4454 Qatar University Numerical and Computer Tools Project
Please read the file that it attached, all instructions are provided on the file in pdf...
Due Week 6 Fran’s Virtual Fruit Stand, programming homework help
Assignment 1: Fran’s Virtual Fruit Stand, Part 1 Due Week 6 and worth 190 pointsFran’s Virtual Fruit Stand is an onlin...
Script
Write a Powershell script that takes two inputs, a directory path and the name of a text file that will...
Erd Explanation And Code
An Entity Relationship Diagram shows the relationship between a set of entities stored in a database. It aids in providing...
Dependability Doc
Consider the four principal dimensions of dependability. Choose two dimensions, describe them, and explain the relationshi...
Related Tags
Book Guides
1984
by George Orwell
The Subtle Art of Not Giving a F*ck
by Mark Manson
The Adventures of Huckleberry Finn
by Mark Twain
The Underground Railroad
by Colson Whitehead
The Woman in the Window
by A. J. Finn
The Bell Jar
by Sylvia Plath
Slaughterhouse Five
by Kurt Vonnegut
The Hunger Games
by Suzanne Collins

Get 24/7
Homework help
Our tutors provide high quality explanations & answers.
Post question
Most Popular Content

Northern Virginia Community College Programming Repetition Discussion
In real-life almost every task that we do involves repetition. Discuss in 600 words your position and illustrate this usin ...
Northern Virginia Community College Programming Repetition Discussion
In real-life almost every task that we do involves repetition. Discuss in 600 words your position and illustrate this using a real-life situation.

CSC 325 case problem 7
case problem 2Carly's Catering provides meals for parties and special events. In previous chapters, you have developed a c ...
CSC 325 case problem 7
case problem 2Carly's Catering provides meals for parties and special events. In previous chapters, you have developed a class that holds catering event information and an application that tests the methods using four objects of the class. Now modify the Event and EventDemo classes as follows:Modify the method that sets the event number in the Event class so that if the argument passed to the method is not a four-character String that starts with a letter followed by three digits, then the event number is forced to A000. If the initial letter in the event number is not uppercase, force it to be so.Add a contact phone number field to the Event class.Add a set method for the contact phone number field in the Event class. Whether the user enters all digits or any combination of digits, spaces, dashes, dots, or parentheses for a phone number, store it as all digits. For example, if the user enters (920) 872-9182, store the phone number as 9208729182. If the user enters a number with fewer or more than 10 digits, store the number as 0000000000.Add a get method for the phone number field. The get method returns the phone number as a String constructed as follows: parentheses surround a three-digit area code, followed by a space, followed by the three-digit phone exchange, followed by a hyphen, followed by the last four digits of the phone number.Modify the EventDemo program so that besides the event number and guests, the program also prompts the user for and retrieves a contact phone number for each of the sample objects. Display the phone number along with the other Event details. Test the EventDemo application to make sure it works correctly with valid and invalid event and phone numbers.Save the files as Event.java and EventDemo.java.case problem 1Sammy's Seashore Supplies rents beach equipment to tourists. In previous chapters, you have developed a class that holds equipment rental information and an application that tests the methods using four objects of the class. Now modify the Rental and RentalDemo classes as follows:Modify the method that sets the contract number in the Rental class so that if the argument passed to the method is not a four-character String that starts with a letter followed by three digits, then the contract number is forced to A000. If the initial letter in the contract number is not uppercase, force it to be so.Add a contact phone number field to the Rental class.Add a set method for the contact phone number field in the Rental class. Whether the user enters all digits or any combination of digits, spaces, dashes, dots, or parentheses for a phone number, store it as all digits. For example, if the user enters (920) 872-9182, store the phone number as 9208729182. If the user enters a number with fewer or more than 10 digits, store the number as 0000000000.Add a get method for the phone number field. The get method returns the phone number as a String constructed as follows: parentheses surround a three-digit area code, followed by a space, followed by the three-digit phone exchange, followed by a hyphen, followed by the last four digits of the phone number.Modify the RentalDemo program so that besides the contract number and minutes, the program also prompts the user for and retrieves a contact phone number for each of the sample objects. Display the phone number along with the other Rental details. Test the RentalDemo application to make sure it works correctly with valid and invalid contract and phone numbers.Save the files as Rental.java and RentalDemo.java.

NVCC Programming Variables and Methods Worksheet
Just like we developed the Fruit parent class in lesson 5, Come up with a Parent and two child class examples on your own. ...
NVCC Programming Variables and Methods Worksheet
Just like we developed the Fruit parent class in lesson 5, Come up with a Parent and two child class examples on your own. What variables/characteristics would remain in the parent class and what is different from the child classes in terms of variables and methods. Do not repeat any other student's classes that posted before you. You do not have to create/add the code. Just describe the classes in the discussion.

mySQL Worksheet
***Login information and student schema will be given***In this lab, you will learn how to write Advanced queries using Ag ...
mySQL Worksheet
***Login information and student schema will be given***In this lab, you will learn how to write Advanced queries using Aggregate Functions and Table Joins. You will write 10 SQL SELECT statements to query the STUDENT schema. Your Select Statements should run error-free and should be valid.Submit two separate files: one plain text file (.txt or .sql file) with your SELECT statements only; and the other document (doc/docx/pdf) include both your SELECT statements and your query results (copy and paste text or screen shots). The instructor and TA should be able to run your plain text source file as script and generate the same output as shown in your result document.Q1. List all courses that have "Intro to Information Systems" as prerequisite. (HINT: use a subquery)Q2. List all courses with above average cost. Display course description, cost, and the average cost of all courses. (HINT: use a subquery)Q3. For each zip that has at least one instructor, list the total number of instructors in that zipcode.Q4. For each city in the state of CT, list the total number of students live in that city. Display city, state, number of students in descending order.-- AGGREGATION OF FULL RESULT SETQ5. Find the minimum, maximum, and average grade of final exams in sections taught by Todd Smythe.Q6: For all students who took "Intro to Information Systems", calculate the highest, lowest, and average midterm exam grade for each section. Display Section No and calculation results.-- TABLE JOIN WITH HAVING-CLAUSEQ7. List the instructor id and name of the instructors that teach fewer than 10 sections regardless of student enrollment.Q8. Show which city has the most students. Display city and state, and number of students.Q9: List all zipcodes where at least three students AND at least four instructor reside. Show zip, state and city.Q10: List all cities that have 10 or more students and instructor combined. Show city, state, number of student residents, number of instructor residents, and total student/instructor residents in that city. Sort by total in descending order. Learning Resourceshttps://www.w3schools.com/sql/sql_join.asphttps://docs.oracle.com/database/121/SQLRF/functions.htm#SQLRF006

Iglobal University Time Complexity Heap Operation Programming Solved Practice
1. What is the time complexity of 'Build Heap' operation? Build Heap is used in building a max(or min) binary heap f ...
Iglobal University Time Complexity Heap Operation Programming Solved Practice
1. What is the time complexity of 'Build Heap' operation? Build Heap is used in building a max(or min) binary heap from a given array. “Build Heap” is used in Heap Sort as a first step for sorting. (25 Points)
2. Build the Initial heap from the following array. Each element remains in its place after the build. (35 Points)
32, 8, 20, 5, 15, 14, 29, 9, 11, 1, 4
3a. Describe an 'array' data type. (what does the array data type mean.)
3b. Describe (with example) how to create an array in C/C++
3c. Describe (with example) how to create an array in Python.
3d. Describe (with example) how to create an array in Java.
4.What is heap sort? What are the pros and cons in using this sorting method. State some uses.
Earn money selling
your Study Documents