I'm a bit confused on how to get this program to run right. Here are the directions:
Part 1: Write a Python function called reduceWhitespace that is given a string line and returns the line with all extra whitespace characters between the words removed. For example, ‘This line has extra space characters ‘ ‘This line has extra space characters’
Function name: reduceWhitespace
Number of parameters: one string line
Return value: one string line
The main file should handle the file operations to read from a .txt file you create and call the function from the module you create. In main you should also print out your text from the file before the function call and print the result after the function call, showing that the function works. Additionally, write the lines with reduce whitespaces into a text file. Your function should also include the specification (docstring). Note: I will test your file by giving it a .txt file I create, so you should prompt the user for the text file (the framework for that is provide to you inside the main file).
Lab 9 Part 2: In the same module, write a Python function named countAllLetters that is given a string line and returns a list containing every letter and character in the line and the number of times that each letter/character appears (with upper/lower case letters counted together). For example, ‘This is a short line’ [(‘t’,2), (‘h’,2), (‘i’,3), (‘s’,3), (‘ ‘,4), (‘a’,1), (‘o’,1), (‘r’,1), (‘l’,1), (‘n’,1), (‘e’,1)]
Function name: countAllLetters
Number of parameters: one string line
Return value: a list
The main file should handle the file operations to read from a new .txt file you create and call the function from the module you create. In main, you should print out the text you read from the file, then call the function and then print out the resulting list, showing that the function works. You do not need to write the output into a text file. Your function should also include the specification (docstring). Note: I will test your file by giving it a .txt file I create, so you should prompt the user for the text file. Please zip both files and submit them as Lab9lastname.zip on Canvas. Please make sure you use the framework and follow the steps to complete the lab9main.py.
Here is what i have for both files:
def main():
filename1 = input('What is the textfile name without .txt: ') +
'.txt'
filename2 = 'result' + filename1
fileIn = open(filename1, 'r')
fileOut = open('out.text', 'w')
for line in fileIn:
print('reduceWhitespace()')
print(line)
print('Reduced line is: ')
print(reducedLine)
fileOut.write(reducedLine + '\n')
print('#'*60)
print()
filename1 = input('what is the textfile name without .txt: ') +
'.txt'
print('countAllLetters():')
print(line)
letters_count = countAllLetters(line)
print(letters_count)
main()
The second one:
def reduceWhitespace(line):
tokens = str(line).split()
splitline = str()
for item in tokens:
redicedLine = reducedLine + item + ' '
return reducedLine
def countAllLetters(line):
line= str(line).lower()
chars = []
letterCount = list()
for token in line.split():
for c in token:
if chars.count(c) == 0:
chars.append(c)
for c in chars:
letterCount.append((c,line.count(c)))
return letterCount
Here is the modified program: Save it in file main.py and run.
def reduceWhitespace(line):
return " ".join(line.split())
def countAllLetters(line):
tmpdict={}
retlist=[]
for s in line:
s = s.lower()
if s in tmpdict:
tmpdict[s] = tmpdict[s] + 1
else:
tmpdict[s] = 1
for key in tmpdict:
retlist.append((key,tmpdict[key]))
return retlist
def main():
filename1 = input('What is the textfile name without .txt: ') +
'.txt'
filename2 = 'result' + filename1
fileIn = open(filename1, 'r')
fileOut = open('out.text', 'w')
for line in fileIn:
reducedLine = reduceWhitespace(line)
print(line)
print('Reduced line is: ')
print(reducedLine)
fileOut.write(reducedLine + '\n')
print('#'*60)
print()
line = "This is a short line"
print(line)
letters_count = countAllLetters(line)
print(letters_count)
main()

Sample output:



I'm a bit confused on how to get this program to run right. Here are the...
If i could get any guidance on how to get this started it will be great. My prof. literally just gave us the information below (which are literally just instructions) and I am unsure on how to get started. For this assignment we are going to create a function that reads an input stream and classifies it into “tokens” from a language that we define here. In this language we make the following rules: ● An identifier is a letter...
Sample program run - Needs to be coded in python -Enter the text that you want to search for, Or DONE when finished: valiant paris The valiant Paris seeks for his love. -Enter the text that you want to search for, or DONE when finished: Romeo and Juliet Enter Romeo and Juliet aloft, at the WIndow -- Enter the text that you want to search for, DONE when finished: DONE # copy the following two lines into any # program...
Let’s build a dynamic string tokenizer! Start with the existing template and work on the areas marked with TODO in the comments: Homework 8 Template.c Note: If you turn the template back into me without adding any original work you will receive a 0. By itself the template does nothing. You need to fill in the code to dynamically allocate an array of strings that are returned to the user. Remember: A string is an array. A tokenizer goes through...
Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( ); // constructor ~Salesperson( ); // destructor Salesperson(double q1, double q2, double q3, double q4); // constructor void getsales( ); // Function to get 4 sales figures from user void setsales( int quarter, double sales); // Function to set 1 of 4 quarterly sales // figure. This function will be called // from function getsales ( ) every time a // user enters a sales...
Write a class called TemperatureFile. • The class has one data attribute: __filename • Write getter and setter for the data attribute. • Write a “calculateAverage” function (signature below) to calculate and return average temperature of all temperatures in the file. def calculateAverage(self): • Handle possible exceptions Write a main function: • Create a file ('Temperatures.txt’) and then use “write” method to write temperature values on each line. • Create an object of the TemperaureFile with the filename (‘Temperatures.txt’) just...
HELP NEEDED in C++ (preferred) or any other language Write a simple program where you create an array of single byte characters. Make the array 100 bytes long. In C this would be an array of char. Use pointers and casting to put INTEGER (4 byte) and CHARACTER (1 byte) data into the array and pull it out. Make sure you can access both character and integer data at any location in the array. Read data from a text file....
My C++ program is not compiling. Please explain how you fixed with detailed inline comments. I am using Visual Studio 2017. It's a character count program that keeps and displays a count of all the upper, lower case and digits in a .txt file. The requirement is to use classes to implement it. -----------------------------------------------------------------HEADER FILE - Text.h--------------------------------------------------------------------------------------------- /* Header file contains only the class declarations and method prototypes. Comple class definitions will be in the class file.*/ #ifndef TEXT_H #define...
I need help in Python. This is a two step problem So I have the code down, but I am missing some requirements that I am stuck on. Also, I need help verifying the problem is correct.:) 7. Random Number File Writer Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 500. The application should let the user specify how many random numbers the file...
Hi, can someone offer input on how to address these 4 remain parts the zybook python questions? 4: Tests that get_num_items_in_cart() returns 6 (ShoppingCart) Your output ADD ITEM TO CART Enter the item name: Traceback (most recent call last): File "zyLabsUnitTestRunner.py", line 10, in <module> passed = test_passed(test_passed_output_file) File "/home/runner/local/submission/unit_test_student_code/zyLabsUnitTest.py", line 8, in test_passed cart.add_item(item1) File "/home/runner/local/submission/unit_test_student_code/main.py", line 30, in add_item item_name = str(input('Enter the item name:\n')) EOFError: EOF when reading a line 5: Test that get_cost_of_cart() returns 10 (ShoppingCart)...
It is a C++ program by using
inheritance and vectors
My professor said that all the files should be separate. like
File.cpp, File.h, Text.cpp,Text.h,Main.cpp
I already have these files
File.cpp
#include "File.h"
// Constructor of File that takes File name and type as
arguments
File::File(string type, string name) {
this->type = type;
this->name = name;
}
//returns the type.
string File::getType() {
return type;
}
//returns the name of file.
string File::getName() {
return name;
}
File.h
#ifndef __FILE_H__
#define...