Trent King CIT 436 Lab 4
.docx
keyboard_arrow_up
School
University of Phoenix *
*We aren’t endorsed by this school
Course
0102
Subject
Computer Science
Date
May 4, 2024
Type
docx
Pages
6
Uploaded by ProfWillpower13160 on coursehero.com
Trent King CIT 436 2/4/2024 Lab 4
Here, we look at <Directory> containers. a. (2) Search forward for <Directory />. This is the first <Directory> container in the file. What does / reference?
Upon searching for <Directory /> in the httpd.conf file, I found that it references the root directory
of the entire file system. This directive is set to disallow all access by default, enhancing the security by preventing unauthorized access to the entire filesystem from the web.
The container disallows all access to this directory and all beneath it. (2) The next <Directory> container is for DocumentRoot. It contains Options, AllowOverride directives and Require all granted. What does the Require directive do and why is it necessary for this directory?
The Require all granted directive allows access to the DocumentRoot directory, making it necessary to ensure the website's content is accessible to all users.
Options allows us to specify what options are allowed or not allows for requests in this directory (and subdirectories as options are inherited). What Options are permited for DocumentRoot?
For the DocumentRoot, I permitted options Indexes, FollowSymLinks, and ExecCGI, enabling directory listings, following symbolic links, and executing scripts.
Create a new <Directory> container beneath the one for DocumentRoot for /usr/local/apache2/htdocs/second (recall the container will end with </Directory>). Place Options
-FollowSymLinks in this container, save your conf file, and (1) restart Apache. In your web browser, test second/users. What happens? You tested this earlier (prior to step 1) and it should
have worked, why did it not work now? What does -FollowSymLinks mean? If you had a subdirectory beneath second, would that subdirectory permit or not permit symbolic links to be followed?
After creating a new <Directory> container for /usr/local/apache2/htdocs/second with Options -
FollowSymLinks and restarting Apache, testing second/users in the web browser resulted in an error, specifically, the symbolic link to /etc/passwd could not be followed. Previously, this link worked because symbolic links were allowed by default. The -FollowSymLinks option disables the ability to follow symbolic links, enhancing security by preventing access to files outside of the intended directory structure. Consequently, with -FollowSymLinks set for the second directory, any subdirectory beneath second would also inherit this restriction, disallowing the following of symbolic links unless explicitly overridden by another directive at a deeper level.
In your web browser, try the URL ipaddress/second (no filename) which should result in either returning an index file or displaying the directory’s contents. Which one happens here?
When I tried accessing the URL ipaddress/second without specifying a filename, Apache returned the directory's contents as a listing. This behavior indicates that the Options directive for this directory includes Indexes, allowing the server to display a list of files in the directory when no specific index file is present or specified in the request.
Change the directive you added in 2b to Options -Indexes. Save the file and (1) restart Apache. Refresh your browser. Instead of the directory listing, you get an error. What error? Why didn’t you get an index file?
Changing to Options -Indexes and refreshing the browser led to a 403 Forbidden error because this setting prevents directory listings and no index file was available to be served.
Change the Options statement to Options Multiviews, save your conf file, (1) restart Apache and
refresh your browser. What happens this time?
Setting Options Multiviews, restarting Apache, and refreshing the browser enabled content negotiation, allowing Apache to serve the closest match for the request from the second directory.
Add a + before Multiviews in the Options directive, save your conf file, (1) restart Apache and refresh your browser. What happens now? What can you conclude about Options that have minus (-) versus Options that have no sign before them versus Options that have a plus (+)?
Adding +Multiviews, restarting Apache, and refreshing showed similar content negotiation as before. The + adds to existing options, - removes them, and no sign sets options directly, allowing precise control over Apache's directory behaviors.
With Options +MultiViews, Indexes is inherited again from DocumentRoot. Now we can change how the directory listing appears in the web browser. (2) In the <Directory> container for second, add the directive IndexOptions +FancyIndexing, save the conf file, (1) restart Apache, and refresh browser. How does the directory listing differ from how it appeared in 1c?
After adding IndexOptions +FancyIndexing, restarting Apache, and refreshing, the directory listing became more detailed and visually appealing, showing file icons, sizes, and modification dates, unlike the basic list seen before.
Replace +MultiViews with -Indexes and delete the IndexOptions directive. We do this because Indexes constitutes a security problem. Why?
Replacing +MultiViews with -Indexes and deleting the IndexOptions directive is done because allowing directory listings can be a security risk. It exposes the structure and contents of the server's directories to anyone, potentially revealing sensitive files or information about the server setup that could be exploited by attackers. Removing Indexes prevents unauthorized directory browsing, enhancing the server's security.
In your web browser, type the URL ipaddress. This loads your index file, but which one?
When I typed the URL ipaddress into my web browser, it loaded the index.html file. This is because the Apache configuration file's DirectoryIndex directive prioritizes index.html as the default file to display when no specific file is requested in the URL.
A little below the <Directory> container for second you should find the <IfModule> container for dir_module which has one directive, DirectoryIndex. This directive specifies valid names for index files. Add index.txt after index.html in this directive, save your conf file, (1) restart Apache and refresh your browser. What index file does Apache respond with?
After adding index.txt after index.html in the DirectoryIndex directive within the <IfModule> container for dir_module, saving the configuration file, restarting Apache, and refreshing my browser, Apache responded with the index.html file. This is because DirectoryIndex searches
for the listed files in the order they are specified, serving the first one it finds. Since index.html exists and is listed before index.txt, it is served to the client.
Reverse the order of the two file names in the directive, save the conf file, (1) restart Apache and refresh your browser. Which version loads now? What can you conclude about the DirectoryIndex directive?
After reversing the order of the file names in the DirectoryIndex directive to list index.txt before index.html, saving the configuration file, restarting Apache, and refreshing my browser, Apache served the index.txt file. This demonstrates that the DirectoryIndex directive prioritizes the files in the order they are listed. If the first listed file is found, it is served, and Apache does not continue to look for the subsequent files. This behavior allows for flexibility in specifying default documents for a directory.
In steps d and e you have seen the role of Options Indexes and DirectoryIndex. Describe all of the possibilities that Apache will respond with when it receives a URL which contains no filename, such as ipaddress or ipaddress/second.
If Indexes enabled and no DirectoryIndex file: Displays directory listing. If Indexes disabled and no DirectoryIndex file: Returns a 403 Forbidden error. If a DirectoryIndex file exists: Serves that file. If no DirectoryIndex file exists and Indexes disabled: Also returns a 403 Forbidden error.
You want to change Options or some other directives for your directory but you cannot add or modify the <Directory> container in the conf file. Should you ask the web administrator to make the changes? No, Apache gives us a better way: the access file.
Apache allows using an .htaccess file for directory-level configuration changes. This method enables me to modify Options and other directives without editing the main httpd.conf file, eliminating the need to ask the web administrator for these changes.
Type fg to resume vi. The <Files> container matches .htaccess and has one directive: to deny access. Does this mean that you, as the web developer, cannot use an access file? Explain.
The <Files> directive that denies access to .htaccess files is for security, ensuring they're not accessible via a web browser. However, this doesn't affect my ability to use .htaccess for configuration; the server still reads and applies these files, keeping the configurations effective while securing them from external access.
This creates .htaccess with the directive in place to permit Indexes (which overrides what the <Directory> container did in the conf file). In your web browser, enter the URL ipaddress/second. What happens? Why didn’t the access file override the Option in the <Directory> container as expected?
When I entered ipaddress/second in my web browser after creating .htaccess with Options +Indexes, it didn't override the -Indexes setting from httpd.conf as expected. This occurred because the AllowOverride directive for the directory in httpd.conf was set to None or didn't specifically allow overriding Options, preventing .htaccess from enabling directory listings.
Scroll back to the <Directory> container for htdocs and you will find AllowOverride None. Change this to AllowOverride All, save your conf file, (1) restart Apache and refresh your browser. Did these changes work? The AllowOverride directive is used to control what access
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
the File is being uploaded through /* TODO: while the file f is not emptyread a line get the name, gender, and rankingadd the data to the maps */
// My code so far, do I use length () or readline ()
for (File f : files) {
while (files != files.length) ) {
// while the file f is not empty
/// read a line get the name, gender, and ranking
}// add the data to the maps
arrow_forward
Please help me write the following function (please see the attached photos for context of the problem):
find_treasure(start_map_num):
Takes an integer between 0 and 9 as input. Loads the corresponding map file, and starts following the trail (at position 0, 0 of that file) as described above. Continues following the trail through other map files as needed. Places an 'X' at the conclusion of the trail and saves the updated treasure map to a new file with 'new_' prepended to the current map filename. Returns a tuple of the row and column index where the 'X' was placed in that file.
arrow_forward
How to code this assignment JSON objects.
Hint: Work on the methods in the order they are found in the documentation below.
def swap_value(file_path: str, key: str, replacement):
"""
This function will be given a file path and a key. The file that the file path points to contains a json object.
This function should, load the data in the file. Then replace the value associated with the key with replacement
value. Then it should overwrite the current data in the file with the new changes. Finally it should return the
old value.
:param file_path: A path to file
:param key: A key value in the JSON object saved in the file
:param replacement: The new value that the key will be mapped to
:return: The old value that the key used to be mapped to
"""
def update_transactions(file_path: str, transaction_list: list):
"""
You are part of a team tasked to create an application that helps bankers by saving their transactions for them.
Your job…
arrow_forward
Milestone #1 - Ask Quiz Type
In a file called main.py, implement a program that asks the user for a quiz type and prints the file name for that quiz type. The program
should have one input prompt: the integer value of the personality quiz number.
Your program should print the welcome message and the list of the personality quizzes, ask for the test number, and then print the file
name. You are required to use the provided dictionary with the personality quizzes names. The list of the personality quizzes should be
printed in alphabetical order. See example below.
Welcome to the Personality Quiz!
What type of Personality Quiz do you want to run?
1 BabyAnimals
2 Brooklyn99
3 Disney
4 Hogwarts
5 MyersBriggs
6 Sesame Street
7 - StarWars
8 - Vegetables
arrow_forward
Using only BufferedReader and BufferedWriter to read/write files and only arrays for any data structure needs, create a static method reverseLineOrder which accepts the arguments:
Filename to the input file as a String
Filename of the output file as a String
The method will create a new file with the lines from the given data set in reverse order.
Data.txt:
1 2 3 4 5 6 7 8 9 0
9 8 7 6 5 4 3 2 1 0
8 7 6 5 4 3 2 1 0 9
Subject: Java Programming
arrow_forward
2 CVS uses a simple text-based rule to identify overlaps during a merge: There is an overlap if the same line was
changed in both versions that are being merged. If no such line exists, then CVS decides there is no conflict and
the versions are merged automatically. For example, assume a file contains a class with three methods, a().
b(), and c(). Two developers work independently on the file. If they both modify the same lines of code, say the
first line of method a(), then CVS decides there is a conflict. Explain why this approach will fail to detect
certain types of conflict. Provide an example in your answer.
arrow_forward
Please help me with the assignment below
The assignment:
Make a telephone lookup program. Read a data set of 1,000 names and telephone numbers from a file that contains the numbers in random order. Handle lookups by name and also reverse lookups by phone number. Use a binary search for both lookups. This assignment needs a resource class and a driver class. The resource class and the driver class will be in two separate files. The driver class needs to have only 5 or 7 lines of code. The code needs to be written in Java. Please help me with exactly what I asked for help.
arrow_forward
Please help write the functions (context for the problem in the images):
write_X_to_map(filename, row, col): Takes as inputs a string corresponding to a filename, and two non-negative integers representing a row and column index. Reads in the map at the given filename, inserts an X into the given row and column position, then saves the map to a new file with 'new_' prepended to the given filename. You can assume the filename given to the function as argument refers to a file that exists.
arrow_forward
Focus on string operations and methodsYou work for a small company that keeps the following information about its clients: • first name• last name • a 5-digit user code assigned by your company.The information is stored in a file clients.txt with the information for each client on one line(last name first), with commas between the parts. For exampleJones, Sally,00345Lin ,Nenya,00548Fule,A,00000Smythe , Mary Ann , 00012Your job is to create a program assign usernames for a login system. First: write a function named get_parts(string) that will that will receive as its arguments a string with the client data for one client, for example “Lin ,Nenya,00548”, and return the separate first name, last name, and client code. You should remove any extra whitespace from the beginning and newlines from the end of the parts.You’ll need to use some of the string methods that we covered in this lessonYou can test your function by with a main() that is just the function call with the argument typed…
arrow_forward
Each line of a hockey file contains a four-digit year, a team name, and a two-digit number of wins.Here is one such file, hockey.txt:2003maple leafs452020maple leafs351995senators181996maple leafs302000senators482012canadiens48The first line of the file, for example, says that in 2003 (year), the maple leafs (team name) had 45 wins.Write a function that takes an open hockey file and returns a list of tuples,where each tuple refers to a team name and that team's maximum number of wins in any year.Here is a sample call of the function on hockey.txt:>>> teams_and_most_wins(open('hockey.txt'))[('maple leafs', 45), ('senators', 48), ('canadiens', 48)]"""from typing import TextIOdef teams_and_most_wins(f: TextIO) -> list[tuple[str, int]]:'''f is an open hockey file.Each year has 4 digits and each number of wins has 2 digits.Return a list of tuples where each tuple storesa team name and that team's maximum number of wins in any year.Every team should appear in exactly one of the…
arrow_forward
Focus on string operations and methodsYou work for a small company that keeps the following information about its clients: • first name• last name • a 5-digit user code assigned by your company.The information is stored in a file clients.txt with the information for each client on one line(last name first), with commas between the parts. For exampleJones, Sally,00345Lin ,Nenya,00548Fule,A,00000Smythe , Mary Ann , 00012Your job is to create a program assign usernames for a login system. First: write a function named get_parts(string) that will that will receive as its arguments a string with the client data for one client, for example “Lin ,Nenya,00548”, and return the separate first name, last name, and client code. You should remove any extra whitespace from the beginning and newlines from the end of the parts.You’ll need to use some of the string methods that we covered in this lessonYou can test your function by with a main() that is just the function call with the argument typed…
arrow_forward
The Directory class has a list of names in it. You should use dynamic memory to create anarray upon instantiation. You should create a copy constructor for the directory class and anassignment operator (i.e. operator=()). You should create a function called fillDirectory whichaccepts a size for the directory and the names for it both of which should be given by the user.In main, create directory1 and fill it with information. Use the assignment operator=() to setdirectory2 equal to directory1.
This is in c++
arrow_forward
The owner of Quick Breakfast Cafe (qbc), has provided a text file (see given qbc_menu_prices.txt) that contains menu items, separated by a space, the delimiter. Each record in the file contains the following two fields:
Item Description and the Sale Price.
Read the file and present the user with a Quick Breakfast Cafe Menu, which may look like this:
Quick Breakfast Cafe
--Menu--
[1] Coffee $2.20
[2] Tea $1.05
[3] Milk $1.5
[4] Donuts $2.85
[5] Bagel $3.25
[6] Logout Prompt the user for the item and quantity they wish to purchase, which may look like:
Enter your selection [1 - 6]:
1 Enter the quantity you wish to purchase: 1
To simplify the program, a user can only purchase one item at a time.
A receipt is printed after each transaction, which includes the item, qty and price, followed by the total price including an 8% tax. The receipt may look like:
Quick Breakfast Cafe
-- Sales Receipt --
Item Qty Cost
Coffee 1 $2.20
Total Cost With %8 Sales Tax: 2.38
After each transaction, the…
arrow_forward
In this laboratory work, you are expected to write a c# console application to make some
operations about the customers. Operations and required featurest that you need to cover in
your program are following:
• Add: This function adds a new person to json file. You need to get inputs from user
and adds the new one into json file.
• Display: This function displays all people in your json file.
• Search: This function let you search with the user id.
• Create Password: This function will create a random password for the user and user
may choose the length of the password. Password may include numbers and
characters.
• Exceptions: You need to handle exceptions as well. You should at least handle 3 of
exceptional cases. For the case that file can not be found, It is mandatory to catch the
exception.
Sample json string:
"FirstName": "Kaan",
"LastName": "OZAYDIN",
"EmployeeId": 101,
"Email": "",
"Password":
"Address": (
"ZipCode": "06460",
"State": "Ankara",
"Country": "Turkey"
"FirstName":…
arrow_forward
Repeat the example below but this time you should do the following :
- Maintain a database in a file:
- Add any new vehicle to the fleet. Vehicle information should include
-Model year
-Make Model name
-License plate number
-Rent a vehicle to the registered customer
-Receive rented vehicle back from customer
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct
{
int id;
char name[50];
char phone[15];
/* data */
} Customer;
void addCustomer(Customer *arr, int size);
void searchCustomer(Customer *arr, int size);
int main()
{
Customer arr[10];
int size = 0;
addCustomer(arr, size++);
addCustomer(arr, size++);
searchCustomer(arr, size);
}
void addCustomer(Customer *arr, int size)
{
int id;
char name[50];
char phone[15];
printf("Enter Customer ID\n");
scanf("%d", &arr[size].id);
printf("Enter name\n");
scanf("%s", arr[size].name);
printf("Enter phone\n");
scanf("%s", arr[size].phone);
}
void searchCustomer(Customer *arr, int size)
{…
arrow_forward
How to code this assignment JSON objects.
Hint: Work on the methods in the order they are found in the documentation below.
def read_last_line(file_path: str)->str:
"""
Reads the last line of the file at the specified file path. The function returns the last line of the file as a
string, if the file is empty it will return an empty string ("").
:param file_path: A path to a file
:return: The last line of the file
"""
def read(file_path: str)->str:
"""
Reads the entire file at the specified file path. The function returns all the text in the file as a string, if
the file is empty it will return an empty string ("").
:param file_path: A path to a file
:return: All the text in the file
"""
def write(file_path:str, text:str=''):
"""
Clears the file at the specified file path then writes the specified line to the file. If the function is invoked
without a line parameter or the line variable is None nothing is written to…
arrow_forward
In C++
Implement a simple version of the linux grep command in C++. grep - Looks through a file, line by line, trying to find a user-specified search term in the line. If a line has the word within it, the line is printed out, otherwise it is not. Use the system calls open(), getline(), close().
Requirements (examples run from. terminal)
Your program grep is always passed a search term and zero or more files to grep through (thus, more than one is possible). It should go through each line and see if the search term is in it; if so, the line should be printed, and if not, the line should be skipped.
[terminal]$ ./grep ! main.cpp main2.cppcout << "Hello, World!";cout << "Programming is great fun!";
The matching is case sensitive. Thus, if searching for world, lines with World will not match.
Lines can be arbitrarily long (that is, you may see many many characters before you encounter a newline character, \n). grep should work as expected even with very long lines. For…
arrow_forward
We have a text file with name "Data.txt". Assume, this text file is located under working directory of your source code. In given file we have student records and we don't know how
many records we have. For each student, first field is "Student Number", second field is "Name", third field is "Surname", fourth field is "Midterm Mark", and fifth field is "Final Mark".
For "Student Number", first two digits shows the registration year (like your student number). Midterm percentage is 40% and Final percentage is 60%. Structure of file is given below,
Data.txt
10
characters
20
characters
20
characters
4
4.
chr
chr
171732204 Anejo
171732208 Sherry
Highball
67
71
Adonis
38
45
181732014 Arnold
Palmer
74
84
191732011 Bramble
Gin
46
70
161732034 Shandy
Beer
64
56
18172
Jewel
78
Осean
56
Codder
Jalallbanger
Write a complete program that will open file and read all records. While reading file, your program will calculate the average grade of student (using midterm and final) and show on
screen…
arrow_forward
Assume that there is a valid file cards.txt in the current directory which contains 10 valid int values, each on its own line. Write a function which reads all the values from the file and
returns the maximum of the values. Your function must have the following signature:
int cardsMax ();
You do not need to demonstrate calling this function from main).
arrow_forward
Project 1-UNIX Shell
Design a C program that copy the file "input.txt" to "out.txt" using Ubuntu (Linux) system
calls.
The program will create the directory (~/OS-Project) to store the file "out.txt" inside it.
The program will skip m letters at a time.
The process of reading will start from the letter of index i.
The values of m and i must be provided by the user.
arrow_forward
The Loan class does not implementSerializable.Rewrite the Loan class to implement Serializable. Writea programthat creates five Loan objects and stores them in a file namedExercise17_ 06.dat.
arrow_forward
Bella is a psychology student who is carrying out an experiment in which she repeatedly
asks people to "think of an object, any object". Bella wants to see what objects people
think of under this situation. She enters each object into a text file, one object per line.
Help Bella analyse the data by writing a function make_dictionary (filename) that reads
the named file and returns a dictionary mapping from object names to occurrence
counts (the number of times the particular object was guessed). For example, given a file
data.txt containing the following
dog
triceratops
persian cat
dog
persian cat
large white fluffy thing
persian cat
the function would return the dictionary
{'dog': 2, 'triceratops': 1, 'persian cat': 3, 'large white fluffy thing': 1}
Notes:
• You may assume the given file exists, but it may be empty (i.e., containing no lines).
Keys must be inserted into the dictionary in the order in which they appear in the
input file.
• In some of the tests we display the keys in…
arrow_forward
If wrong answer this time will downvote it
Create a class with a static main that tests the ability to resolve and print a Path:
• Create an instance of a FileSystem class.
• Resolve an instance of a Path interface from a directory path and filename.
• Print the constructed Path with System.out.println() method.
2. Create a class with a static main that tests the ability to resolve and print a Path:
• Create an array of Path class.
• Instantiate instances of Path with absolute and relative paths.
• Print the constructed elements of the array of Path class with System.out.println() method.
3. Create a class to test serialisation class that implements serializable, it should implement the following:
• A static void method that serialises an object.
• A static void method that deserializes an object.
• A static main method that tests the two by moving an object from one to the other
arrow_forward
Unix assignment
Purpose: The purpose of this assignment is to use various concepts of
the C Shell.
0. Change your default login shell to the C Shell.
1. Create a .cshrc file in your home directory that will do
the following:
* Create the alias (lsall) that will do all of the following:
display the date, and a recursive long list of all files
in a directory.
* Create the alias (whoson) that will display the date and a sorted
list of users logged in.
* Declare the LOCAL variable that controls the size of your history
list to the value 200.
* Declare the shell variable that will cause the C Shell to send
a message to your terminal whenever one of your background
commands complete.
2. Create a .login file in your home directory to do the following.
* Declare the GLOBAL Terminal Type variable to the
value vt100. Display the value of the variable.
Logout and log back in to make sure your .cshrc and .login files
are automatically executed.
Create a lab8.scr…
arrow_forward
In Java programming
Write the code to print out a customer report. Your code must read each customer from a file, populate the object, place the object in a linked list, and display the data from the linked list.
Use the customer object name from
Customer customer = new Customer ( “ customer name” );
Assume you have opened a file and read a line into the customer object.
Write the signature line for this method
Write the line of code that will write the object to a linked list
Write the line of code that will print the customer object properties. Be sure to include a textual description of each property.
arrow_forward
Part Two: Implementing a rainbow table
You are to write a program, in C/C++, Java or Python, that should run using the following instruction:
$ ./Rainbow Passwords.txt
where the file Passwords.txt contains a list of possible passwords. The password file contains a password
per line, as in the provided words file and consists of strings of printable characters. Any password used
must be taken from this file, so the only stored hash information needs to relate to those entries in the file.
The program is used to find pre-images for given hash values. Rainbow tables can be used to solve
pre-image problems for hash functions. At the simplest level they can simply be a list of hash values
and the corresponding pre-images, often from some dictionary. This can be expensive in terms of storage
space however, and a more efficient way of identifying pre-images involves the use of the hash function
and reduction functions.
First step
The process is as follows:
1. Read in the list of possible…
arrow_forward
Need help to implement networking in python
Server.py
Load data from file This option will ask the user for a fully qualified path and will load a JSON file containing the information for users and pending messages. The format of the JSON file will be defined based on your implementation and it will the same used to save the data into file (menu option #4).
Functionalities the server must provide: 1)
User Sign Up: adds a user identified by a phone number to the system.
a) Protocol: USR|username|password|display_name
b) Response: 0|OK for success. 1| for an error.
c) The server should validate that the username does not exist
2) User Sign In: verify user credentials
a) Protocol: LOG|username|password
b) Response: i) 0|OK → the credentials are correct.
ii) 1|Invalid Credentials iii) 2|Already Logged In → in case that the user is logged in from another client.
c) This will help the server knowing which user is connected.
d) The server should keep a list of connected clients, which should…
arrow_forward
Implement function duplicate() that takes as input a string and the name of a file in the current directory and returns True if the file contains duplicate words and False otherwise. Hints: remember to save the function and the text file in the same directory.
def duplicate(filename):
'Put in docstring’
# get file content
infile = ________________# ______________
content = ______________# ______________
infile__________________# ______________
# replace punctuation with blank spaces and obtain list of words
table = ________________________ # _______________
words = _______________________ # _______________
# for every word, check if it occurs more than once; if so, return True
for word in words:
if ______________________ # _____________
_________________# _____________
# no word occurred more than once, so return False
______________
Result of running the function.
>>> duplicate('Duplicates.txt')
True
>>> duplicate('NoDuplicate.txt')
False
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Related Questions
- the File is being uploaded through /* TODO: while the file f is not emptyread a line get the name, gender, and rankingadd the data to the maps */ // My code so far, do I use length () or readline () for (File f : files) { while (files != files.length) ) { // while the file f is not empty /// read a line get the name, gender, and ranking }// add the data to the mapsarrow_forwardPlease help me write the following function (please see the attached photos for context of the problem): find_treasure(start_map_num): Takes an integer between 0 and 9 as input. Loads the corresponding map file, and starts following the trail (at position 0, 0 of that file) as described above. Continues following the trail through other map files as needed. Places an 'X' at the conclusion of the trail and saves the updated treasure map to a new file with 'new_' prepended to the current map filename. Returns a tuple of the row and column index where the 'X' was placed in that file.arrow_forwardHow to code this assignment JSON objects. Hint: Work on the methods in the order they are found in the documentation below. def swap_value(file_path: str, key: str, replacement): """ This function will be given a file path and a key. The file that the file path points to contains a json object. This function should, load the data in the file. Then replace the value associated with the key with replacement value. Then it should overwrite the current data in the file with the new changes. Finally it should return the old value. :param file_path: A path to file :param key: A key value in the JSON object saved in the file :param replacement: The new value that the key will be mapped to :return: The old value that the key used to be mapped to """ def update_transactions(file_path: str, transaction_list: list): """ You are part of a team tasked to create an application that helps bankers by saving their transactions for them. Your job…arrow_forward
- Milestone #1 - Ask Quiz Type In a file called main.py, implement a program that asks the user for a quiz type and prints the file name for that quiz type. The program should have one input prompt: the integer value of the personality quiz number. Your program should print the welcome message and the list of the personality quizzes, ask for the test number, and then print the file name. You are required to use the provided dictionary with the personality quizzes names. The list of the personality quizzes should be printed in alphabetical order. See example below. Welcome to the Personality Quiz! What type of Personality Quiz do you want to run? 1 BabyAnimals 2 Brooklyn99 3 Disney 4 Hogwarts 5 MyersBriggs 6 Sesame Street 7 - StarWars 8 - Vegetablesarrow_forwardUsing only BufferedReader and BufferedWriter to read/write files and only arrays for any data structure needs, create a static method reverseLineOrder which accepts the arguments: Filename to the input file as a String Filename of the output file as a String The method will create a new file with the lines from the given data set in reverse order. Data.txt: 1 2 3 4 5 6 7 8 9 0 9 8 7 6 5 4 3 2 1 0 8 7 6 5 4 3 2 1 0 9 Subject: Java Programmingarrow_forward2 CVS uses a simple text-based rule to identify overlaps during a merge: There is an overlap if the same line was changed in both versions that are being merged. If no such line exists, then CVS decides there is no conflict and the versions are merged automatically. For example, assume a file contains a class with three methods, a(). b(), and c(). Two developers work independently on the file. If they both modify the same lines of code, say the first line of method a(), then CVS decides there is a conflict. Explain why this approach will fail to detect certain types of conflict. Provide an example in your answer.arrow_forward
- Please help me with the assignment below The assignment: Make a telephone lookup program. Read a data set of 1,000 names and telephone numbers from a file that contains the numbers in random order. Handle lookups by name and also reverse lookups by phone number. Use a binary search for both lookups. This assignment needs a resource class and a driver class. The resource class and the driver class will be in two separate files. The driver class needs to have only 5 or 7 lines of code. The code needs to be written in Java. Please help me with exactly what I asked for help.arrow_forwardPlease help write the functions (context for the problem in the images): write_X_to_map(filename, row, col): Takes as inputs a string corresponding to a filename, and two non-negative integers representing a row and column index. Reads in the map at the given filename, inserts an X into the given row and column position, then saves the map to a new file with 'new_' prepended to the given filename. You can assume the filename given to the function as argument refers to a file that exists.arrow_forwardFocus on string operations and methodsYou work for a small company that keeps the following information about its clients: • first name• last name • a 5-digit user code assigned by your company.The information is stored in a file clients.txt with the information for each client on one line(last name first), with commas between the parts. For exampleJones, Sally,00345Lin ,Nenya,00548Fule,A,00000Smythe , Mary Ann , 00012Your job is to create a program assign usernames for a login system. First: write a function named get_parts(string) that will that will receive as its arguments a string with the client data for one client, for example “Lin ,Nenya,00548”, and return the separate first name, last name, and client code. You should remove any extra whitespace from the beginning and newlines from the end of the parts.You’ll need to use some of the string methods that we covered in this lessonYou can test your function by with a main() that is just the function call with the argument typed…arrow_forward
- Each line of a hockey file contains a four-digit year, a team name, and a two-digit number of wins.Here is one such file, hockey.txt:2003maple leafs452020maple leafs351995senators181996maple leafs302000senators482012canadiens48The first line of the file, for example, says that in 2003 (year), the maple leafs (team name) had 45 wins.Write a function that takes an open hockey file and returns a list of tuples,where each tuple refers to a team name and that team's maximum number of wins in any year.Here is a sample call of the function on hockey.txt:>>> teams_and_most_wins(open('hockey.txt'))[('maple leafs', 45), ('senators', 48), ('canadiens', 48)]"""from typing import TextIOdef teams_and_most_wins(f: TextIO) -> list[tuple[str, int]]:'''f is an open hockey file.Each year has 4 digits and each number of wins has 2 digits.Return a list of tuples where each tuple storesa team name and that team's maximum number of wins in any year.Every team should appear in exactly one of the…arrow_forwardFocus on string operations and methodsYou work for a small company that keeps the following information about its clients: • first name• last name • a 5-digit user code assigned by your company.The information is stored in a file clients.txt with the information for each client on one line(last name first), with commas between the parts. For exampleJones, Sally,00345Lin ,Nenya,00548Fule,A,00000Smythe , Mary Ann , 00012Your job is to create a program assign usernames for a login system. First: write a function named get_parts(string) that will that will receive as its arguments a string with the client data for one client, for example “Lin ,Nenya,00548”, and return the separate first name, last name, and client code. You should remove any extra whitespace from the beginning and newlines from the end of the parts.You’ll need to use some of the string methods that we covered in this lessonYou can test your function by with a main() that is just the function call with the argument typed…arrow_forwardThe Directory class has a list of names in it. You should use dynamic memory to create anarray upon instantiation. You should create a copy constructor for the directory class and anassignment operator (i.e. operator=()). You should create a function called fillDirectory whichaccepts a size for the directory and the names for it both of which should be given by the user.In main, create directory1 and fill it with information. Use the assignment operator=() to setdirectory2 equal to directory1. This is in c++arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education