Concept explainers
The following is an old word puzzle: “Name a common word, besides tremendous, stupendous and horrendous, that ends in dous.” If you think about this for a while, it will probably come to you. However, we can also solve this puzzle by reading a text file of English words and outputting the word if it contains “dous” at the end. The text file “words.txt” contains 87, 314 English words, including the word that completes the puzzle. This file is available online with the source code for the book. Write a
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
Problem Solving with C++ (9th Edition)
Additional Engineering Textbook Solutions
Web Development and Design Foundations with HTML5 (8th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Software Engineering (10th Edition)
- Write a program that first reads in the name of an input file and then reads the input file using the file.readlines() method. The input file contains an unsorted list of number of seasons followed by the corresponding TV show. Your program should put the contents of the input file into a dictionary where the number of seasons are the keys, and a list of TV shows are the values (since multiple shows could have the same number of seasons). Sort the dictionary by key (least to greatest) and output the results to a file named output_keys.txt. Separate multiple TV shows associated with the same key with a semicolon (), ordering by appearance in the input file. Next, sort the dictionary by values (alphabetical order), and output the results to a file named output_titles.txt. Ex If the input is: filel.txt and the contents of file1.txt are: 20 Gunsmoker 30 The Simpsons 10 Will & Grace 14 Dallas 20 Law & Order 12 Murder, She Wrote the file output keys.txt should contain: 10: Will & Grace 12:…arrow_forwardWrite a program that first reads in the name of an input file and then reads the input file using the file.readlines() method. The input file contains an unsorted list of number of seasons followed by the corresponding TV show. Your program should put the contents of the input file into a dictionary where the number of seasons are the keys, and a list of TV shows are the values (since multiple shows could have the same number of seasons). Sort the dictionary by key (least to greatest) and output the results to a file named output_keys.txt. Separate multiple TV shows associated with the same key with a semicolon (;), ordering by appearance in the input file. Next, sort the dictionary by values (alphabetical order), and output the results to a file named output_titles.txt. Ex: If the input is: file1.txt and the contents of file1.txt are: 20 Gunsmoke 30 The Simpsons 10 Will & Grace 14 Dallas 20 Law & Order 12 Murder, She Wrote the file output_keys.txt should contain: 10: Will…arrow_forwardWrite a program that first reads in the name of an input file and then reads the input file using the file.readlines() method. The input file contains an unsorted list of number of seasons followed by the corresponding TV show. Your program should put the contents of the input file into a dictionary where the number of seasons are the keys, and a list of TV shows are the values (since multiple shows could have the same number of seasons). Sort the dictionary by key (least to greatest) and output the results to a file named output_keys.txt, separating multiple TV shows associated with the same key with a semicolon (;). Next, sort the dictionary by values (alphabetical order), and output the results to a file named output_titles.txt. Ex: If the input is: file1.txt and the contents of file1.txt are: 20 Gunsmoke 30 The Simpsons 10 Will & Grace 14 Dallas 20 Law & Order 12 Murder, She Wrote the file output_keys.txt should contain: 10: Will & Grace 12: Murder, She Wrote 14: Dallas…arrow_forward
- Write a program that reads the strings from file SortedStrings. txt and report whether the strings in the files are stored in ascending order. If the strings are not sorted in the file, display the first two strings that are out of order.arrow_forwardEach 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_forwardWrite a program that receives a filename as user input. The file is structured as multiple lines containing numbers separated by a single space.For example, this would be an acceptable file: 1 2 3 4 5 6 7 2 Your program should open this file and: print all its contents; write the median of all numbers to a new file called result.txt. IMPORTANT NOTES: the median is the element in the middle when you sort the values; the median of values (2, 1, 3) is 2, because when you sort them, you get 1, 2, 3, and 2 is the value in the middle. you can assume there will be no empty lines; there might be any arbitrary number lines in the file; there might be any arbitrary number of elements in a single line; you can assume there will always be an odd number of elements. Example 1: If input is: file1.txt and the contents of file1.txt are: 1 2 2 you should first print the content, and then write 2 to result.txt. Example 2: If input is: file2.txt and the contents of file2.txt are: 1 2 3 4 5 1 7 you…arrow_forward
- In Java Write a program that reads the student information from a tab separated values (tsv) file and creates a text file that contains student information together with the course grades of the students. Each row of the tsv file contains the Last Name, First Name, Midterm1 score, Midterm2 score, and the Final score of a student. A sample of the student information is provided in StudentInfo.tsv. Assume the number of students is at least 1 and at most 20. The program performs the following tasks: A: 90 =< x B: 80 =< x < 90 C: 70 =< x < 80 D: 60 =< x < 70 F: x < 60 Output the last names, first names, exam scores, and letter grades of the students into a text file named report.txt. Output one student per row and separate the values with a tab character. Ex: If the input of the program is: StudentInfo.tsv and the contents of StudentInfo.tsv are: Barrett Edan 70 45 59 Bradshaw Reagan 96 97 88 Charlton Caius 73 94 80 Mayo Tyrese 88 61 36 Stern Brenda 90 86 45…arrow_forwardIn pythonarrow_forwardWrite a program that opens a specified text file then displays a list of all the unique words found in the file. Hint: Store each word as an element of a set. 5. Word Frequency Write a program that reads the contents of a text file. The program should create a dictio- nary in which the keys are the individual words found in the file and the values are the number of times each word appears. For example, if the word "the" appears 128 times, the dictionary would contain an element with 'the' as the key and 128 as the value. Thearrow_forward
- Write a program (call it intersection.py) that finds all gene symbols that appear both in the chr21_genes.txt file and in the HUGO_genes.txt file. These gene symbols should be printed to a file in alphabetical order (you can hard code the output file OUTPUT/intersection_output.txt) . The program should also print on the terminal how many common gene symbols were found. Use Lists or Sets to solve the problem. It is fine to use a temporary Dictionary to find the intersection of two Lists, but this can be simplified with Sets. Note: HUGO_genes.txt could have some duplicate entries.Remember to have these command line options:$ python3 intersection.py -h usage: intersection.py [-h] -i1 FILE1 -i2 FILE2 Provide two gene list (ignore header line), find intersection optional arguments: -h, --help show this help message and exit -i1 INFILE1, --infile1 INFILE1 Gene list 1 to open -i2 INFILE2, --infile2 INFILE2 Gene list 2 to open $ python3 intersection.py -i1 chr21_genes.txt -i2 HUGO_genes.txt #…arrow_forwardUpload only 1.c file. Any filename. Create a program that accepts a number num and returns each place value in the number. Limit Input: 0 to 60000 Examples: Input: 39 → Output: [30, 9] Input: 434 → Output: [400, 30, 4] Input: 100 → Output: [100, 0, 0]arrow_forwardCan someone help me with this question?? It will be highly appreciatedtedarrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT