Python 3 Program
Program 4 should first tell users that this is a word analysis software. For any user-given text file, the program will read, analyze, and write each word with the line numbers where the word is found in an output file. A word may appear in multiple lines. A word shows more than once at a line, the line number will be only recorded one time.
Ask a user to enter the name of a text file. Using try/except for invalid user input. Then the program reads the contents of the text file and create a dictionary in which the key-value pairs are described as follows:
Key. The key are the individual words found in the file.
Value. Each value is a list that contains the line numbers in the file where the word (the key) is found. Be aware that a list may have only one element.
Once the dictionary has been built, the program should create another text file for otuput, named “words_index.txt”. Next, write the contents of the dictionary to the file as an alphabetical listing of the words that are stored as keys in the dictionary (sorting the keys), along with the line numbers where the words appear in the original file. Please see the sample file for your reference.
Looking to seeing everyone to submit a well-done program! Here are some tips:
Documents/Comments of your program (Never more)
Testing your program by the given two files, Kennedy.txt . The output file of the Kennedy_index.txt, Kennedy_index_B.txt, Kennedy_index_C.txt, for input file “kennedy.txt”
Remember the output file name of your program is words_index.txt.
For this program, not running one (syntax error) will receive NO point.
Example of original text- Kennedy.txt
We observe today not a victory of party but a celebration of freedom symbolizing an end as well as a beginning signifying renewal as well as change
New text example - Kennedy_index.txt
Text File to be analyzed: Kennedy.txt We: 1 a: 1, 2, 4 an: 3 as: 4, 5, 6 beginning: 4 but: 2 celebration: 2 change: 6 end: 3 freedom: 3 not: 1 observe: 1 of: 2, 3 party: 2 renewal: 5 signifying: 5 symbolizing: 3 today: 1 victory: 1 well: 4, 5
example- Kenndy_index_B.txt
Text File to be analyzed: kennedy.txt We : 1 a : 1, 2, 4 an : 3 as : 4, 5, 6 beginning : 4 but : 2 celebration : 2 change : 6 end : 3 freedom : 3 not : 1 observe : 1 of : 2, 3 party : 2 renewal : 5 signifying : 5 symbolizing : 3 today : 1 victory : 1 well : 4, 5
example- Kenndy_index_C.txt
Text File to be analyzed: kennedy.txt We : 1 a : 1, 2, 4 an : 3 as : 4, 5, 6 beginning : 4 but : 2 celebration : 2 change : 6 end : 3 freedom : 3 not : 1 observe : 1 of : 2, 3 party : 2 renewal : 5 signifying : 5 symbolizing : 3 today : 1 victory : 1 well : 4, 5
In: Computer Science
A firm with a current value (cost) of $800 and will return $1,000 next year. The firm also has a potential project that costs $500 and will return $550 next year, but the firm does not have the money to invest and must raise it from outside investors. However, outside investors mistakenly believe the firm will be worth $820 in one year without the project and $13,030 with the project. For simplicity, assume a zero discount rate. Does the project have a positive NPV? Acting on behalf of existing shareholders, should you take the project?
In: Finance
Shell script program that asks a number between 5 to 9. If the input is not between 5 and 9, display an error message and ask again.
Output
1
22
333
4444
55555
666666
7777777
88888888
999999999
In: Computer Science
Draw an ER diagram containing the ConferenceSeries, the ConferenceEvent, and the ConferenceTrack entitysets where each ConferenceSeries can be linked to zero or many ConferenceEvent entities, and each Conference Event may be linked to one or many ConferenceTracks. ConferenceTrack should not exists without a ConferenceEvent. Choose an appropriate relationship name. Then augment the model with an entityset Venue and a relationship named OrganizedAt associating each ConferenceEvent with exactly one Venue. Assume that a Venue must have run at least one ConferenceEvent. Your ER diagram should show all details. Show a translation into tables for a SQL database (topic covered in class on Tue Sept 9). Note: Add 3 attributes to each of the entity type with appropriate primary key.
In: Computer Science
does a zombie process use CPU time true or false
and is it true or false that a orphan process will find a new parent and will not use CPU time.
In: Computer Science
The right to vote and hold office are civil disabilities that affect many felons, especially those who are minority and from impoverished communities. Do you believe that felons should be granted their right to vote upon parole? Determine any pros and cons to the issue? Should former inmates be granted the opportunity to seek an elected office? Is there a difference between them and those currently in office?
In: Psychology
Show the encoding of the following machine instructions and convert into hexadecimal.
1. STUR X7, [X9, #32]
2. SUBI X16, X4, #52
3. AND X5, X20, X3
In: Computer Science
The following table lists the components needed to assemble an
end item, lead times (in weeks), and quantities on hand.
Item | Lead Time | Amount on Hand |
Direct Components | |||
End | 2 | 0 | L(2), C(1), K(3) | |||
L | 2 | 11 | B(2), J(3) | |||
C | 3 | 14 | G(2), B(2) | |||
K | 3 | 20 | H(4), B(2) | |||
B | 2 | 31 | ||||
J | 3 | 28 | ||||
G | 3 | 4 | ||||
H | 2 | 0 | ||||
a. If 43 units of the end item are to be
assembled, how many additional units of B are needed?
(Hint: You don’t need to develop an MRP plan.)
Additional units ___
b. An order for the end item is scheduled to be
shipped at the start of week 11. What is the latest week that the
order can be started and still be ready to ship on time?
(Hint: You don’t need to develop an MRP plan.)
The latest week ___
In: Operations Management
To become familiar with using the image of one instrument as the object of the next and tracing rays through a system of multiple instruments.
Multiple optics refers to any system of more than one optical instrument through which light passes. Most devices related to optics, such as cameras, microscopes, and telescopes, contain multiple optics systems.
In multiple optics, the image of one optical instrument becomes the object of the next one. Thus, in multiple optics problems, you need to find the image created by the first optical instrument that the rays encounter. Then, you will use that image as the object of the next optical instrument, repeating this pattern until you have followed the rays all the way through the system. It is very important to be alert to the geometry and to signs when you find the object distance for one instrument from the location of the previous instrument's image. Sometimes, the image is formed on the virtual side of the instrument, leading to a virtual object. This may sound strange, but in practice, its effect on your calculations is simply to make the object distance negative instead of positive.
Several optical instruments are placed along the x axis, with their axes aligned along the x axis. A plane mirror is located at x=0. A converging lens with focal length 5.00 m is located at x=12.5m. An object is placed at x=22.5m.
Part A: First, find the location of the image created by the lens by itself (as if no other instruments were present).
ANSWER
x = |
2.50 |
m |
Part B: Next, find the location of the image created by the plane mirror (after the light has passed through the lens).
ANSWER
x = |
-2.50 |
m |
Part C: What is the location of the final image, as seen by an observer looking toward the mirror, through the lens? Keep in mind that the light must pass back through the lens, and thus you must do one more calculation with the thin lens equation.
ANSWER
x = |
20.0 |
m |
Part D: First, find the magnitude mlens1 of the magnification of the image created when light from the object passes through the lens the first time (as if the mirror were not present).
ANSWER
mlens1 = |
1 |
Part E: Next, find the magnitude mmirror of the magnification of the plane mirror.
ANSWER
mmirror = |
1 |
Part F: Now find the magnitude mlens2 of the magnification of the image created when light from the object passes through the lens the second time (after reflecting off the mirror).
Part G: What is the magnitude of the magnification of the final image?
In: Physics
If nominal and inflation rates were 11% and 1.5%, respectively, what was the true real return? Please show equation and work.
In: Finance
chapter 8: Human Development
Assignment: Developmental Psychology
Instructions:
Select an adult to study (someone who is a prominent person, singer/actor, politician, athlete, or someone in the news), I prefer president Donald Trump
Prepare a 700-1000 word paper in which assess the following issues:
In: Psychology
This code is an expression of cp command in c language. But I don't understand this code very well. Please explain in notes one by one.(in detail)
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<errno.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
int main(int argc, char *argv[])
{
char ch;
int src, dst;
struct stat st;
if(argc != 3)
{
printf("argument error \n");
printf("usage: ./a.out src dest \n");
exit(0);
}
if (stat(argv[1], &st) == -1) {
perror("stat : ");
exit(-1);
}
src = open(argv[1], O_RDONLY);
if(src == -1){
perror("open source");
exit(errno);
}
dst = open(argv[2], O_WRONLY | O_CREAT|O_TRUNC);
if(dst == -1){
perror("open source");
exit(errno);
}
while(read(src, &ch,1)){
write(dst,&ch,1);
}
close(src);
close(dst);
if (chmod(argv[2], st.st_mode)) {
perror("chmod : ");
return -1;
}
return 0;
}
In: Computer Science
discuss how the united states government has provided good, bad, or indifferent customer service to its customers i.e. individuals, businesses, states, etc. you may focus on a particular chapter in the book or take a more general approach. support your argument with facts, situations, customer service principles
In: Operations Management
I need to make changes to code following the steps below. The code that needs to be modified is below the steps. Thank you.
1. Refactor Base Weapon class:
a. Remove the Weapon abstract class and create a new Interface class named WeaponInterface.
b. Add a public method fireWeapon() that returns void and takes no arguments.
c. Add a public method fireWeapon() that returns void and takes a power argument as an integer type.
d. Add a public method activate() that returns void and takes an argument as an boolean type.
2. Refactor the specialization Weapon Classes:
a. Refactor the Bomb class so that it implements the WeaponInterface class.
b. Refactor the Gun class so that that it implements the WeaponInterface class.
3. Refactor the Game Class:
a. Remove all existing game logic in main().
b. Create a private helper method fireWeapon() that takes a WeaponInterface as an argument as a weapon. For the passed in weapon activate the weapon then fire the weapon.
c. Create an array of type WeaponInterface that can hold 2 weapons.
d. Initialize the first array element with a Bomb.
e. Initialize the second array element with a Gun.
f. Loop over the weapons array and call displayArea() for each weapon.
------
// Weapon.java
public abstract class Weapon {
public void fireWeapon(int power)
{
System.out.println("Class Name
:"+this.getClass().getSimpleName());
System.out.println("Mathod Name
:"+new Throwable().getStackTrace()[0].getMethodName());
System.out.println("Power
:"+power);
}
public abstract void activate(boolean enable);
}
______________________
// Bomb.java
public class Bomb extends Weapon {
@Override
public void fireWeapon(int power)
{
System.out.println("Class Name
:"+this.getClass().getSimpleName());
System.out.println("Mathod Name
:"+new Throwable().getStackTrace()[0].getMethodName());
System.out.println("Power
:"+power);
}
public void fireWeapon()
{
System.out.println("Class Name
:"+this.getClass().getSimpleName());
System.out.println("Mathod Name
:"+new Throwable().getStackTrace()[0].getMethodName());
super.fireWeapon(67);
}
@Override
public void activate(boolean enable) {
System.out.println("Class Name
:"+this.getClass().getSimpleName());
System.out.println("Mathod Name
:"+new Throwable().getStackTrace()[0].getMethodName());
System.out.println("Enable
:"+enable);
}
}
_____________________________
// Gun.java
public class Gun extends Weapon {
@Override
public void fireWeapon(int power)
{
System.out.println("Class Name
:"+this.getClass().getSimpleName());
System.out.println("Mathod Name
:"+new Throwable().getStackTrace()[0].getMethodName());
System.out.println("Power
:"+power);
}
public void fireWeapon()
{
System.out.println("Class Name
:"+this.getClass().getSimpleName());
System.out.println("Mathod Name
:"+new Throwable().getStackTrace()[0].getMethodName());
super.fireWeapon(98);
}
@Override
public void activate(boolean enable) {
System.out.println("Class Name
:"+this.getClass().getSimpleName());
System.out.println("Mathod Name
:"+new Throwable().getStackTrace()[0].getMethodName());
System.out.println("Enable
:"+enable);
}
}
_____________________________
// Game.java
public class Game {
public static void main(String args[]) {
Bomb b = new Bomb();
Gun g = new Gun();
b.fireWeapon(45);
g.fireWeapon(60);
}
}
In: Computer Science
Q1. what is the social contract theory?
Q2. How does a society come out about as a result of said theory?
Q3. what do you ultimately believe is the origin of ethics? Is ethics an innate human trait that comes about while creating human societies? Or is it the result of of something else? Explain your reasoning.
In: Psychology