race
.py
keyboard_arrow_up
School
Yale University *
*We aren’t endorsed by this school
Course
351B
Subject
Computer Science
Date
Apr 3, 2024
Type
py
Pages
2
Uploaded by CountIron11913 on coursehero.com
'''
NICK HUGHES
DS2000
HW8
NOV 6TH, 2023
'''
import matplotlib.pyplot as plt
# Import the custom Runner class from the 'runner' module
from runner import Runner
def read_data(filename):
# Initialize an empty list to store Runner objects
runners = []
with open(filename, 'r') as file:
# Read all lines from the file into a list
lines = file.readlines()
# Extract the first line as the header
header = lines[0]
# Extract the remaining lines as data lines
data_lines = lines[1:]
# Iterate through the data lines
for line in data_lines:
# Format each line
data = line.strip().split()
# Extract the first value as the runner's name
name = data[0]
# Extract and convert numeric values as floats and remove the names
runs = [float(run) for run in data[1:] if run.replace('.', '', 1).isdigit()]
runner = Runner(name)
# Iterate through the runs
for run in runs:
# Add each run to the Runner object
runner.add_run(run)
runners.append(runner)
return runners
def main():
runners = read_data('runner_data.txt')
# Create a new figure for the plot
plt.figure() # Iterate through the list of runners with an index
for i, runner in enumerate(runners):
# Different y-values for each runner
runner.y = 10 * (i + 1) # Different color for each runner
# Consulted https://www.geeksforgeeks.org/matplotlib-pyplot-viridis-in-
python/
runner.color = plt.cm.viridis(i / len(runners)) # Iterate through days from 1 to 28
for day in range(1, 29):
# Iterate through the list of runners
for runner in runners:
# Move each runner to the next position
runner.move_next()
# Draw the runner's position
runner.draw()
# Add a legend to the plot
plt.legend(loc="upper left")
# Set the plot title and labels and x-limit
plt.title("February Miles")
plt.xlabel("Distance(Miles)")
plt.xlim(0, 150)
# Save the plot as an image with a day-specific filename
# https://www.geeksforgeeks.org/matplotlib-pyplot-savefig-in-python/ plt.savefig(f"day_{day}.png")
# Clear the current figure for the next day's plot
# https://www.geeksforgeeks.org/matplotlib-pyplot-clf-in-python/ plt.clf()
# Find the runner with the maximum distance traveled
winner = max(runners, key=lambda runner: runner.x) # Print the name and distance of the winner
print(f'The winner is {winner.name} with {winner.x} miles.')
if __name__ == '__main__':
main()
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
5 partition_list (head)
This is a little like split_list() from the Short problem, except that, instead
of splitting the list into two by cutting it into the middle, you will now build
two lists to return, using alternate values.
The first value in the input list should be returned at the head of the first new
list; the second value should be the head of the second list. Keep on alternating
from there, putting one new value on the first list, and one on the second. (But
remember that the length of the input list might be odd.)
Example
Suppose you have the following input list:
10 - 13 -> -1 -> 1000 - 0
It should return the following two lists:
10
1
0
13 -> 1000
arrow_forward
Description
The aim of this project is to develop a cyclic doubly linked list. You will implement two classes:
1. Cyclic doubly linked lists: CyclicDoubleList, and
2. Doubly linked nodes: DoubleNode.
A cyclic doubly linked list with three nodes is shown in Figure 1. The empty cyclic doubly linked
list is shown in Figure 2.
head.
Figure 1. A cyclic doubly linked list and three nodes.
head-
Figure 2. An empty cyclic doubly linked list.
The class CyclicDoubleList stores a finite list of n (zero or more) elements stored in doubly
linked nodes. If there are zero elements in the list, the list is said to be empty. Each element is
stored in an instance of the DoubleNode class. If the list is empty, the head pointer
points to null. Otherwise, the head pointer points to the first node, the next pointer of the ith
node (1 referred to as the head pointer, and
An integer referred to as the list size which equals the number of elements in the list.
Member Functions
Constructors
CyclicDoubleList ()…
arrow_forward
Phyton:
Program 6:
Write a program that allows the user to add data from files or by hand. The user may add more data whenever they want. The print also allows the user to display the data and to print the statistics. The data is store in a list. It’s easier if you make the list global so that other functions can access it.
You should have the following functions:
· add_from_file() – prompts the user for a file and add the data from it.
· add_by_hand() – prompts the user to enter data until user type a negative number.
· print_stats() – print the stats (min, max, mean, sum). You may use the built-in functions.
Handling errors such as whether the input file exist is extra credit.
To print a 10-column table, you can use the code below:
for i in range(len(data)):
print(f"{data[i]:3}", end="")
if (i+1)%10==0:
print()
print()
Sample run:
Choose an action
1) add data from a file
2) add data by hand
3) print stats
4)…
arrow_forward
def delete_item(...): """ param: info_list - a list from which to remove an item param: idx (str) - a string that is expected to contain an integer index of an item in the in_list param: start_idx (int) - an expected starting value for idx (default is 0); gets subtracted from idx for 0-based indexing
The function first checks if info_list is empty. The function then calls is_valid_index() to verify that the provided index idx is a valid positive index that can access an element from info_list. On success, the function saves the item from info_list and returns it after it is deleted from info_list.
returns: If info_list is empty, return 0. If is_valid_index() returns False, return -1. Otherwise, on success, the function returns the element that was just removed from info_list.
Helper functions: - is_valid_index() """
arrow_forward
find_last(my_list, x): Takes two inputs: the first being a list and the second being any type. Returns the index of the last element of the list which is equal to the second input; if it cannot be found, returns None instead.
>>> find_last(['a', 'b', 'b', 'a'], 'b')
2
>>> ind = find_last(['a', 'b', 'b', 'a'], 'c')
>>> print(ind)
None
arrow_forward
Task 5: Unscramble
You will write a program that takes in 2 files: a dictionary file and a file listing jumbled words. Your
binary will be called unscramble and will be run using
unscramble
The file contains a bunch of scrambled words, one word per line. Your job is to print out
these jumbles words, 1 word to a line. After each jumbled word, print a list of real dictionary words that
could be formed by unscrambling the jumbled word. The dictionary words that you have to choose
from are in the file. As an example, the starter package contains two sample input files
and the result should look as follows. The order that you display the dictionary words on each line can
be different; however, the order that you print out the jumbled words should be identical to the order in
your input. The sample out below is skipping a few lines to save handout space (your output must not
omit these lines).
nwae: wean anew wane
eslyep: sleepy
rpeoims: semipro imposer promise
ettniner: renitent.…
arrow_forward
find_last(my_list, x): Takes two inputs: the first being a list and the second being any type.
Returns the index of the last element of the list which is equal to the second input; if it cannot be
found, returns None instead.
>>> find_last(['a', 'b', 'b', 'a'], 'b')
2
>>> ind = find_last(['a', 'b', 'b', 'a'], 'c')
>>> print(ind)
None
• find_first(my_list, x): Takes two inputs: the first being a list and the second being any type.
Returns the index of the first element of the list which is equal to the second input; if it cannot be
found, returns None instead.
>>> find_first(['a', 'b', 'b', 'a'], 'b')
1
>>> ind = find_first(['a', 'b', 'b', 'a'], 'c')
>>> print(ind)
None
In python
arrow_forward
Help make a C++ program that:1. Queries the user for the name of a file of text.2. Opens the file, and maintains two lists: one list for words beginning with the letter"D" or "d", and a second list for words beginning with any other letter. Each listmust maintain words in alphabetical order.3. Each node in the list must contain the word and the number of times that the word appears.4. Display (a screen at a time) each of the lists showing the alphabetized list of words and thenumber of times that each appears.
Please have the main function as the first function in the program. Please make the least amount of functions as possible. Like for the file input have the file error thing in the same function. And please add comments throughout the code.
arrow_forward
Word IndexWrite a python program that reads the contents of a text file. The program should create a dictionary inwhich the key-value pairs are described as follows:Key. The keys are the individual words found in the file.576Values. Each value is a list that contains the line numbers in the file where the word (thekey) is found.For example, suppose the word “robot” is found in lines 7, 18, 94, and 138. The dictionarywould contain an element in which the key was the string “robot”, and the value was a listcontaining the numbers 7, 18, 94, and 138.Once the dictionary is built, the program should create another text file, known as a word index,listing the contents of the dictionary. The word index file should contain an alphabetical listingof the words that are stored as keys in the dictionary, along with the line numbers where thewords appear in the original file. Figure 9-1 shows an example of an original text file(Kennedy.txt) and its index file (index.txt
arrow_forward
Help make a C++ program that:1. Queries the user for the name of a file of text.2. Opens the file, and maintains two lists: one list for words beginning with the letter"D" or "d", and a second list for words beginning with any other letter. Each listmust maintain words in alphabetical order.3. Each node in the list must contain the word and the number of times that the word appears.4. Display (a screen at a time) each of the lists showing the alphabetized list of words and thenumber of times that each appears.
Please have the main function as the first function in the program
arrow_forward
The function last_words in python takes one parameter, fname, the name of a text file, and returns a list containing the last word from each line of the file. For example, if the file contents are:
apples are red bananas are yellow limes are green
then the list ["red", "yellow", "green"] should be returned.
NOTE: You may assume the file will contain no blank lines.
BIG HINT: If line is a string representing a line of text (inside a for loop!), then L = line.split() creates a list of the words in the line.
For example:
Test
Result
L = last_words("wordlist1.txt") print(L)
['happy', 'sad', 'angsty', 'euphoric', 'maudlin']
arrow_forward
Python
write a program in python that plays the game of Hangman. When the user plays Hangman,
the computer first selects a secret word at random from a list built into
the program. The program then prints out a row of dashes
asks the user to guess a letter. If the user guesses a letter that is in the word, the word is redisplayed
with all instances of that letter shown in the correct positions, along with any letters correctly guessed
on previous turns. If the letter does not appear in the word, the user is charged with an incorrect guess.
The user keeps guessing letters until either:
* the user has correctly guessed all the letters in the word or
* the user has made eight incorrect guesses.
one for each letter in the secret word
and
Hangman comes from the fact that incorrect guesses are recorded by drawing an evolving picture of
the user being hanged at a scaffold. For each incorrect guess, a new part of a stick-figure body
the head, then the body, then each arm, each leg, and finally…
arrow_forward
def small_index(items: list[int]) -> int:"""Return the index of the first integer in items that is less than its index,or -1 if no such integer exists in items.>>> small_index([2, 5, 7, 99, 6])-1>>> small_index([-5, 8, 9, 16])0>>> small_index([5, 8, 9, 0, 1, 3])3"""
arrow_forward
Contact list: Binary Search
A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings). That list is followed by a name, and your program should output the phone number associated with that name.
Define and call the following function. The return value of FindContact is the index of the contact with the provided contact name. If the name is not found, the function should return -1 This function should use binary search. Modify the algorithm to output the count of how many comparisons using == with the contactName were performed during the search, before it returns the index (or -1).
int FindContact(ContactInfo contacts[], int size, string contactName)
Ex: If the input is:
3 Frank 867-5309 Joe 123-5432 Linda…
arrow_forward
in c++
In a linked list made of integer data type, write only an application file that prints thoseintegers that are divisible by 5. Note that you assume that linked list exists, you onlyprints the value of data items that meet the condition (divisible by 5)
arrow_forward
linked list is an object that creates, references and manipulates node objects. In this assignment, you are asked to write a Python program to create a linked list and do a set of operations as follows:1. Create an empty linked list2. Create and insert a new node at the front of the linked list3. Insert a new node at the back of the linked list4. Insert a new node at a specified position in the linked list5. Get a copy of the data in the node at the front of the linked list6. Get a copy of the data in the node at a specified position in the linked list7. Remove the node at the front of the linked list8. Remove the node at the back of the linked list9. Remove the node at a specified position in the linked list10.Traverse the list to display all the data in the nodes of the linked list11.Check whether the linked list is empty12.Check whether the linked list is full13.Find a node of the linked list that contains a specified data itemThese operations can be implemented as methods in a…
arrow_forward
CLASSES, DYNAMIC ARRAYS AND POINTERS
Define a class called textLines that will be used to store a list of lines of text (each line can be specified as a string).
Use a dynamic array to store the list. In addition, you should have a private data member that specifies the length of the list.
Create a constructor that takes a file name as parameter, and fills up the list with lines from the file. Make sure that you set the dynamic array to expand large enough to hold all the lines from the file. Also, create a constructor that takes an integer parameter that sets the size of an empty list.
in C++
Write member functions to:
remove and return the last line from the list
add a new line onto the end of the list, if there is room for it, otherwise print a message and expand the array
empty the entire list
return the number of lines still on the list
take two lists and return one combined list (with no duplicates)
copy constructor to support deep copying
remember the destructor!
arrow_forward
python programming
Write a function that will insert a new value into the middle of a Linked List.
INPUT: The head of the Linked List, the value to insert
OUTPUT: Nothing is output
RETURNED: Nothing is returned
arrow_forward
Scrambled Codewords C++
1. The codewords will be scrambled words. You will read the words used for the codes from a file and store it into an array. There are 60 words in the file that range in size from 3 characters to 7 characters. The file is called wordlist.txt and can be found attached to the assignment in IvyLearn.2. Start with input for an integer seed for the random number generator. There is no need to put a prompt before the cin operation.3. Ask the Player if they are ready to play and only proceed if they type a Y or y. If the user types an N or n then the program should finish. a. INPUT VALIDATION: Make sure the user has typed either y, Y, n, or N4. Create a variable to keep track of the number of guesses the user has made.5. Use the random number generator to pick a word from the list of words.6. Once you have chosen a word as the codeword you will need to scramble the letters to make it into a code. You should use the random number generator to help you mix up the…
arrow_forward
is a data structure that makes it easy to rearrange data without having to move data in memory:a. arrayb. stack arrayc. linked listd. queue array
arrow_forward
List<String> name = new List<string> { "Jane", "Sue", "Annie" };name.Add("Lisa");MessageBox.Show(name.Count.ToString());
3
4
5
arrow_forward
@6
The Reference-based Linked Lists: Select all of the following statements that are true.
options:
As a singly linked list's node references both its predecessor and its successor, it is easily possible to traverse such a list in both directions.
According to the terminology introduced in class, the head reference variable in a singly linked list object references the list's first node.
According to the terminology introduced in class, in a doubly linked list, each node references both the head and tail node.
In a double-ended singly linked list, the tail reference variable provides access to the entire list.
In a circular linked list, the last node references the first node.
arrow_forward
C++ ProgrammingActivity: Deque Linked List
Explain the flow of the code not necessarily every line, as long as you explain what the important parts of the code do. The code is already correct, just explain the flow.
#include "deque.h"
#include "linkedlist.h"
#include <iostream>
using namespace std;
class DLLDeque : public Deque {
DoublyLinkedList* list;
public:
DLLDeque() {
list = new DoublyLinkedList();
}
void addFirst(int e) {
list->addAt(e,1);
}
void addLast(int e) {
list->addAt(e,size()+1);
}
int removeFirst() {
return list->removeAt(1);
}
int removeLast() {
return list->removeAt(size());
}
int size(){
return list->size();
}
bool isEmpty() {
return list->isEmpty();
}
// OPTIONAL: a helper method to help you debug
void print() {…
arrow_forward
struct nodeType {
int infoData;
nodeType * next;
};
nodeType *first;
… and containing the values(see image)
Using a loop to reach the end of the list, write a code segment that deletes all the nodes in the list. Ensure the code performs all memory ‘cleanup’ functions.
arrow_forward
Unique WordsWrite a python program that opens a specified text file then displays a list of all the unique words foundin the file.Hint: Store each word as an element of a set.
arrow_forward
Java Linked List Print Program
I have a program with multiple linked list that has data stored from a text file. I'm using two methods 1) getData 2) printData. I have to print the contents of my linked lists in a certain format, but I don't know how . My code and desired output is below:
File Data:
employ1,role3,1
employ2,role2,3
employ3,role1,2
employ2,role3,1
employ1,role1,2
employ2,role2,2
Code:
public void getData(){LinkedList<String> list1 = new LinkedList<String>();LinkedList<String> list2 = new LinkedList<String>();LinkedList<String> list3 = new LinkedList<String>();
String str;while(scanner.hasNextLine()){str = scanner.next();String[] sp = str.split("-");switch(sp[1]){case "employ1":list1.add(sp[0]);list1.add(sp[2]);break;case "employ2":list2.add(sp[0]);list2.add(sp[2]);break;case "employ3":list3.add(sp[0]);list3.add(sp[2]);break;}
public void printACM() {
???????
}
Output:
role1
role2
role3
employ1
2
1
employ2
23
1
employ3…
arrow_forward
Write the program that uses a linked list to store the information in memory.
1) Add to the front of the list.2) Add to the back of the list.3) Print the list6) Quit
(Option 1)
This option should allow the user to input a name which should be stored at the front of the list.
(Option 2)
This option should allow the user to input a name which should be stored at the back of the list.
(Option 3)
This option should print out the list to the screen.
(Option 6)
This option should quit the program. Give back all dynamic memory on close.
arrow_forward
True/False 9. The add method can be used to add an item to the end of a list.
arrow_forward
Starter Code:
def find_zero(L): pass
def bubble(L, left, right): pass
def selection(L, left, right): pass
def insertion(L, left, right): pass
def sort_halfsorted(L, sort):
'''Efficiently sorts a list comprising a series of negative items, a single 0, and a series of positive items
Input
-----
* L:list
a half sorted list, e.g. [-2, -1, -3, 0, 4, 3, 7, 9, 14]
<---neg---> <----pos----->
* sort: func(L:list, left:int, right:int)
a function that sorts the sublist L[left:right] in-place
note that we use python convention here: L[left:right] includes left but not right
Output
------
* None
this algorithm sorts `L` in-place, so it does not need a return statement
Examples
--------
>>> L = [-1, -2, -3, 0, 3, 2, 1]
>>> sort_halfsorted(L, bubble)
>>> print(L)
[-3, -2, -1, 0, 1, 2, 3]
'''
idx_zero = find_zero(L) # find the 0 index
sort(L, 0, idx_zero) # sort left half
sort(L, idx_zero+1, len(L)) # sort right half
arrow_forward
Complete the following function according to its docstring description.
Notes:
• report is a file open for reading, not a string representing the name of a file.
• the method str.strip() may come in handy!
1 from typing import TextIO
def every_second_line(report: TextIO) -> list[str]:
"""Return a list containing every second line (with leading and trailing
whitespace removed) in report, starting with the first line.
arrow_forward
You have a sorted linked list. Fill in the missing code in the following function.
SortedType::DeleteItem(Item Type item)
// pointer delete
//trailing pointer
// traveling pointer
void
{
NodePtr tempPtr;
NodePtr predLoc;
NodePtr location:
bool found false;
// Find item to delete: Put your code below
//delete item: Put your code below
arrow_forward
In C++, you are going to write a program that implements a doubly linked list. The data must be read from the files and you can put the file names in your program. Letters.txt contains 26 English Letters:
Copy the following exactly as it is into own .txt file to test:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Sequence.txt contains a list of numbers.
Copy the following exactly as is into another .txt file3,-3,19,-19,18,1,-2,3,-18,17,1,-3,-13,14 You need to 1. Create a doubly linked list by reading the 26 letters from Letters.txt.
2. Sequence.txt file contains a sequence of relative letter positions. The initial position is at the beginning of the list which is ‘A’. The first number in the sequence is ‘3’. So the current position will move forward for three steps. Then the first letter to output is ‘D’ and now the current position is at ‘D’ as well. The second number in the sequence is ‘-3’. Then the second letter to output is the third element backward from the current position which is ‘A’. You…
arrow_forward
Scrambled Codewords C++
The codewords will be scrambled words. You will read the words used for the codes from a file and store it into an array. There are 60 words in the file that range in size from 3 characters to 7 characters. The file is called wordlist.txt and can be found attached to the assignment in IvyLearn.
Start with input for an integer seed for the random number generator. There is no need to put a prompt before the cin operation.
Ask the Player if they are ready to play and only proceed if they type a Y or y. If the user types an N or n then the program should finish.
INPUT VALIDATION: Make sure the user has typed either y, Y, n, or N
Create a variable to keep track of the number of guesses the user has made.
Use the random number generator to pick a word from the list of words.
Once you have chosen a word as the codeword you will need to scramble the letters to make it into a code. You should use the random number generator to help you mix up the…
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
- 5 partition_list (head) This is a little like split_list() from the Short problem, except that, instead of splitting the list into two by cutting it into the middle, you will now build two lists to return, using alternate values. The first value in the input list should be returned at the head of the first new list; the second value should be the head of the second list. Keep on alternating from there, putting one new value on the first list, and one on the second. (But remember that the length of the input list might be odd.) Example Suppose you have the following input list: 10 - 13 -> -1 -> 1000 - 0 It should return the following two lists: 10 1 0 13 -> 1000arrow_forwardDescription The aim of this project is to develop a cyclic doubly linked list. You will implement two classes: 1. Cyclic doubly linked lists: CyclicDoubleList, and 2. Doubly linked nodes: DoubleNode. A cyclic doubly linked list with three nodes is shown in Figure 1. The empty cyclic doubly linked list is shown in Figure 2. head. Figure 1. A cyclic doubly linked list and three nodes. head- Figure 2. An empty cyclic doubly linked list. The class CyclicDoubleList stores a finite list of n (zero or more) elements stored in doubly linked nodes. If there are zero elements in the list, the list is said to be empty. Each element is stored in an instance of the DoubleNode class. If the list is empty, the head pointer points to null. Otherwise, the head pointer points to the first node, the next pointer of the ith node (1 referred to as the head pointer, and An integer referred to as the list size which equals the number of elements in the list. Member Functions Constructors CyclicDoubleList ()…arrow_forwardPhyton: Program 6: Write a program that allows the user to add data from files or by hand. The user may add more data whenever they want. The print also allows the user to display the data and to print the statistics. The data is store in a list. It’s easier if you make the list global so that other functions can access it. You should have the following functions: · add_from_file() – prompts the user for a file and add the data from it. · add_by_hand() – prompts the user to enter data until user type a negative number. · print_stats() – print the stats (min, max, mean, sum). You may use the built-in functions. Handling errors such as whether the input file exist is extra credit. To print a 10-column table, you can use the code below: for i in range(len(data)): print(f"{data[i]:3}", end="") if (i+1)%10==0: print() print() Sample run: Choose an action 1) add data from a file 2) add data by hand 3) print stats 4)…arrow_forward
- def delete_item(...): """ param: info_list - a list from which to remove an item param: idx (str) - a string that is expected to contain an integer index of an item in the in_list param: start_idx (int) - an expected starting value for idx (default is 0); gets subtracted from idx for 0-based indexing The function first checks if info_list is empty. The function then calls is_valid_index() to verify that the provided index idx is a valid positive index that can access an element from info_list. On success, the function saves the item from info_list and returns it after it is deleted from info_list. returns: If info_list is empty, return 0. If is_valid_index() returns False, return -1. Otherwise, on success, the function returns the element that was just removed from info_list. Helper functions: - is_valid_index() """arrow_forwardfind_last(my_list, x): Takes two inputs: the first being a list and the second being any type. Returns the index of the last element of the list which is equal to the second input; if it cannot be found, returns None instead. >>> find_last(['a', 'b', 'b', 'a'], 'b') 2 >>> ind = find_last(['a', 'b', 'b', 'a'], 'c') >>> print(ind) Nonearrow_forwardTask 5: Unscramble You will write a program that takes in 2 files: a dictionary file and a file listing jumbled words. Your binary will be called unscramble and will be run using unscramble The file contains a bunch of scrambled words, one word per line. Your job is to print out these jumbles words, 1 word to a line. After each jumbled word, print a list of real dictionary words that could be formed by unscrambling the jumbled word. The dictionary words that you have to choose from are in the file. As an example, the starter package contains two sample input files and the result should look as follows. The order that you display the dictionary words on each line can be different; however, the order that you print out the jumbled words should be identical to the order in your input. The sample out below is skipping a few lines to save handout space (your output must not omit these lines). nwae: wean anew wane eslyep: sleepy rpeoims: semipro imposer promise ettniner: renitent.…arrow_forward
- find_last(my_list, x): Takes two inputs: the first being a list and the second being any type. Returns the index of the last element of the list which is equal to the second input; if it cannot be found, returns None instead. >>> find_last(['a', 'b', 'b', 'a'], 'b') 2 >>> ind = find_last(['a', 'b', 'b', 'a'], 'c') >>> print(ind) None • find_first(my_list, x): Takes two inputs: the first being a list and the second being any type. Returns the index of the first element of the list which is equal to the second input; if it cannot be found, returns None instead. >>> find_first(['a', 'b', 'b', 'a'], 'b') 1 >>> ind = find_first(['a', 'b', 'b', 'a'], 'c') >>> print(ind) None In pythonarrow_forwardHelp make a C++ program that:1. Queries the user for the name of a file of text.2. Opens the file, and maintains two lists: one list for words beginning with the letter"D" or "d", and a second list for words beginning with any other letter. Each listmust maintain words in alphabetical order.3. Each node in the list must contain the word and the number of times that the word appears.4. Display (a screen at a time) each of the lists showing the alphabetized list of words and thenumber of times that each appears. Please have the main function as the first function in the program. Please make the least amount of functions as possible. Like for the file input have the file error thing in the same function. And please add comments throughout the code.arrow_forwardWord IndexWrite a python program that reads the contents of a text file. The program should create a dictionary inwhich the key-value pairs are described as follows:Key. The keys are the individual words found in the file.576Values. Each value is a list that contains the line numbers in the file where the word (thekey) is found.For example, suppose the word “robot” is found in lines 7, 18, 94, and 138. The dictionarywould contain an element in which the key was the string “robot”, and the value was a listcontaining the numbers 7, 18, 94, and 138.Once the dictionary is built, the program should create another text file, known as a word index,listing the contents of the dictionary. The word index file should contain an alphabetical listingof the words that are stored as keys in the dictionary, along with the line numbers where thewords appear in the original file. Figure 9-1 shows an example of an original text file(Kennedy.txt) and its index file (index.txtarrow_forward
- Help make a C++ program that:1. Queries the user for the name of a file of text.2. Opens the file, and maintains two lists: one list for words beginning with the letter"D" or "d", and a second list for words beginning with any other letter. Each listmust maintain words in alphabetical order.3. Each node in the list must contain the word and the number of times that the word appears.4. Display (a screen at a time) each of the lists showing the alphabetized list of words and thenumber of times that each appears. Please have the main function as the first function in the programarrow_forwardThe function last_words in python takes one parameter, fname, the name of a text file, and returns a list containing the last word from each line of the file. For example, if the file contents are: apples are red bananas are yellow limes are green then the list ["red", "yellow", "green"] should be returned. NOTE: You may assume the file will contain no blank lines. BIG HINT: If line is a string representing a line of text (inside a for loop!), then L = line.split() creates a list of the words in the line. For example: Test Result L = last_words("wordlist1.txt") print(L) ['happy', 'sad', 'angsty', 'euphoric', 'maudlin']arrow_forwardPython write a program in python that plays the game of Hangman. When the user plays Hangman, the computer first selects a secret word at random from a list built into the program. The program then prints out a row of dashes asks the user to guess a letter. If the user guesses a letter that is in the word, the word is redisplayed with all instances of that letter shown in the correct positions, along with any letters correctly guessed on previous turns. If the letter does not appear in the word, the user is charged with an incorrect guess. The user keeps guessing letters until either: * the user has correctly guessed all the letters in the word or * the user has made eight incorrect guesses. one for each letter in the secret word and Hangman comes from the fact that incorrect guesses are recorded by drawing an evolving picture of the user being hanged at a scaffold. For each incorrect guess, a new part of a stick-figure body the head, then the body, then each arm, each leg, and finally…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