Questions
python question <proverbs.txt> All's well that ends well. Bad news travels fast. Well begun is half...

python question

<proverbs.txt>

All's well that ends well.

Bad news travels fast.

Well begun is half done.

Birds of a feather flock together.

Please write a program that reads the file you specify and calculates how many times each word stored in the file appears. However, ignore non-alphabetic words and convert uppercase letters to lowercase letters. For example, all's, Alls, alls are considered to be the same words.

What is the output of the Python program when the input file is specified as "proverbs.txt"? That is, in your answer, include the source codes of your word counter program and its output.

Please refer to this

ex)

fname = input("file name: ")

file = open(fname, "r")

table =dict()

for line in file :

words = line. split()

for word= line. split()

if word not in table :

table[word]= 1

else:

table[word] +=1

print(table)

In: Computer Science

public boolean areArrays(int[] arr1, int[] arr2){ // 1. initial check: both arrays need to have the...

public boolean areArrays(int[] arr1, int[] arr2){
// 1. initial check: both arrays need to have the same length, return false if not the same
// 2. return true if both given arrays are equals(same values in the same indices), false otherwise
if(arr1.length != arr2.length){
return false;
}
for(int i = 0; i < arr1.length; i++){
if(arr1[i] != arr2[i]){

}
}
return true;
}

public int getIndexOfWord(String[] arr, String word){
// if found, return the index of word, otherwise return -1
for(int i = 0; i < arr.length; i++){
if(arr[i].equals(word)){
return i;
}
}
return -1;
}

public boolean arrayContainsWord(String[] arr, String word){
// return true if array contains specific word, false otherwise
for(int i = 0; i < arr.length; i++){
if(arr[i].equals(word));
return true;
}
return false;
}

--- Scanner ------

In: Computer Science

1) Only a single main class is required 2) The main class must contain a static...

1) Only a single main class is required

2) The main class must contain a static method called "getInputWord" that prompts a user to input a word from the keyboard and returns that word as a String. This method must use "JOptionPane.showInputDialog" to get the input from the user (you can find info about JOptionPane in JavaDocs)

3) The main class must contain a static method called "palindromeCheck" that takes a String as an input argument and returns a boolean indicating whether or not that String is a palindrome. This method must utilize a Stack data structure to determine whether the word is a palindrome. Hint: Use the charAt() method of the String class to access each character of the word

Flow of the Program:

1) Read in a word from the user by calling the "getInputWord" method

2) Check if the word is a palindrome using the "palindromeCheck" method

3) Output the result to the screen using "JOptionPane.showMessageDialog" (you can find info about JOptionPane in JavaDocs)

In: Computer Science

C++ Pig Latin Lab This assignment uses pointers to perform something done often in computer applications:...

C++ Pig Latin Lab

This assignment uses pointers to perform something done often in computer applications: the parsing of text to find “words” (i.e., strings delineated by some delimiter).

Write a program that encodes English language phrases into Pig Latin. Pig Latin is a form of coded language often used for amusement. Many variations exist in the methods used to form Pig Latin phrases. Use the following algorithm: to form a Pig Latin phrase from an English language phrase, tokenize the phrase into words with the C++ function strtok_s(). To translate each English word into a Pig Latin word, place the first letter of the English word at the end of the English word and add the letters “ay” after it. Thus, the word “jump” becomes “umpjay,” the word “the” becomes “hetay,” and the word “computer” becomes “omputercay.” Blanks between words remain as blanks. Assume that the English phrase input from the keyboard consists of words separated by blanks, there are no punctuations marks, all words have 2 or more letters, and the input phrase is less than 200 characters. Function printLatinWord() should display each word. Hint: Each time a token is found in a call to strtok_s(), pass the token pointer to function printLatinWord() and print the Pig Latin word.

Your program should allow the user to enter phrases until he or she selects an exit option to quit.

In summary: Create a Pig Latin program to implement this functionality: Prompt the user to enter a sentence. Print out the sentence, and then print out the same sentence in Pig Latin. Repeat this sequence until the user elects to quit.

Sol'n so far: (errors in lines 83 and 92)

#include <iostream>
#include <string>

using namespace std;

//class that hold strings of PigLatin
class PigLatin
{
   //variable to Piglatin form word
private:
   char *latin;

public:
   //constructor that converts word into PigLatin form
   PigLatin(char *word)
   {
       //get the string length
       int i, j = 0, len = strlen(word);

       //allocating space
       latin = new char[len + 3];

       //forming word
       for (i = 1; i < len; i++)
       {
           latin[j] = word[i];
           j++;
       }

       //Adding last characters
       latin[j] = word[0];
       j++;
       latin[j] = 'a';

       j++;
       latin[j] = 'y';

       j++;
       latin[j] = '\0';
   }

   //Function that returns the word in PigLatin form
   string getLatin()
   {
       string str(latin);
       return str;
   }

   //Destructor to deallocate memory
   ~PigLatin()
   {
       delete[]latin;
   }
};

//Function that receives the char * variable as parameter and prints its PigLatin form

void PrintLatinWord(char *str)
{
   //creating an object of PigLatin class
   PigLatin obj(str);

   //Printing word in PigLatin form
   cout << obj.getLatin() << " ";
}

//Main function
int main()
{
   int i;
   char str[200];
   char *pch;
   char option;

   //Loop till user wants to quit
   do
   {
       //Reading a phrase
       cout << "\n\n Enter a sentence to translated:";
       cin.getline(str, 200);

       //splitting words to tokens
       pch = strtok_s(str, " ");

       cout << "\n\t";

       //split enter phrase completes
       while (pch != NULL)
       {
           //Passing token
           PrintLatinWord(pch);
           pch = strtok_s(NULL, " ");
       }

       //Reading user option
       cout << "\n\n Do you want to enter another sentence? (Y - continue, N - Exit):";

       cin.ignore();
   } while (option != 'N' && option != 'n');

   cout << endl;
   system ("pause");
   return 0;
}

In: Computer Science

Python: Word Frequencies (Concordance) 1. Use a text editor to create a text file (ex: myPaper.txt)...

Python:

Word Frequencies (Concordance)

1. Use a text editor to create a text file (ex: myPaper.txt) It should contain at least 2 paragraphs with around 200 or more words.

2. Write a Python program (HW19.py) that

  • asks the user to provide the name of the text file. Be SURE to check that it exists!
    Do NOT hard-code the name of the file! Use the entry provided by the user!
  • read from the text file
  • NOTE: (write your program so that it ONLY works if it reads from the file specified by the user).

3. Your program will produce a dictionary of words with the number of times each occurs. It maps a word to the number of times the word occurs

  • Key: a word
  • Value: the number of times the word occurs in the text. The report should be an ALPHABETIZED output table, listing the word and the number of occurrences.

NOTES:

  • The input sequence can be words, numbers or any other immutable Python object, suitable for a dict key.
  • Ignore case – apple is the same as Apple is the same as APPLE, etc.
  • Discard all punctuation and extra white space (newlines, tabs, blanks, etc.).
  • Put the words into a dictionary. The first time a word is seen, the frequency is 1. Each time the word is seen again, increment the frequency. NOTE: you are REQUIRED to use the dictionary class for this assignment.
  • Produce a frequency table. To alphabetize the frequency table, extract just the keys and sort them. This sorted sequence of keys can be used to extract the counts from the dict.
  • Make sure that your output (the table) is formatted so that the columns are aligned, and so that there are titles for each column.
  • Be sure to modularize your code, using functions appropriately.
  • The main function should be clean and easy to read, calling the functions with meaningful names. Pass parameters – do not use global variables.

BONUS +5 pts:

  • Create a menu-driven front-end to this application.
    • First, populate the dictionary from the file
    • Next, provide a menu that allows the user to
      • Add words to the dictionary
                after asking the user for the word to add
                Note: the count should increase if the word is already there)
      • Check if a word is already in the dictionary
      • Delete a word from the dictionary after asking the user for the word to delete
      • Print the dictionary entries in table form as described above.
  • Allow the user to continue using the menu until they choose the option to quit.

In: Computer Science

Word Frequencies (Concordance)    1. Use a text editor to create a text file (ex: myPaper.txt)...

Word Frequencies (Concordance)   

1. Use a text editor to create a text file (ex: myPaper.txt) It should contain at least 2 paragraphs with around 200 or more words.

2. Write a Python program (HW19.py) that

  • asks the user to provide the name of the text file. Be SURE to check that it exists!
    Do NOT hard-code the name of the file! Use the entry provided by the user!
  • read from the text file
  • NOTE: (write your program so that it ONLY works if it reads from the file specified by the user).

3. Your program will produce a dictionary of words with the number of times each occurs. It maps a word to the number of times the word occurs

  • Key: a word
  • Value: the number of times the word occurs in the text. The report should be an ALPHABETIZED output table, listing the word and the number of occurrences.

NOTES:

  • The input sequence can be words, numbers or any other immutable Python object, suitable for a dict key.
  • Ignore case – apple is the same as Apple is the same as APPLE, etc.
  • Discard all punctuation and extra white space (newlines, tabs, blanks, etc.).
  • Put the words into a dictionary. The first time a word is seen, the frequency is 1. Each time the word is seen again, increment the frequency. NOTE: you are REQUIRED to use the dictionary class for this assignment.
  • Produce a frequency table. To alphabetize the frequency table, extract just the keys and sort them. This sorted sequence of keys can be used to extract the counts from the dict.
  • Make sure that your output (the table) is formatted so that the columns are aligned, and so that there are titles for each column.
  • Be sure to modularize your code, using functions appropriately.
  • The main function should be clean and easy to read, calling the functions with meaningful names. Pass parameters – do not use global variables.

BONUS +5 pts:

  • Create a menu-driven front-end to this application.
    • First, populate the dictionary from the file
    • Next, provide a menu that allows the user to
      • Add words to the dictionary
                after asking the user for the word to add
                Note: the count should increase if the word is already there)
      • Check if a word is already in the dictionary
      • Delete a word from the dictionary after asking the user for the word to delete
      • Print the dictionary entries in table form as described above.
  • Allow the user to continue using the menu until they choose the option to quit.

In: Computer Science

Python File program 5: Word Frequencies (Concordance)    20 pts 1. Use a text editor to create...

Python File

program 5: Word Frequencies (Concordance)    20 pts

1. Use a text editor to create a text file (ex: myPaper.txt) It should contain at least 2 paragraphs with around 200 or more words.

2. Write a Python program (HW19.py) that

  • asks the user to provide the name of the text file. Be SURE to check that it exists!
    Do NOT hard-code the name of the file! Use the entry provided by the user!
  • read from the text file
  • NOTE: (write your program so that it ONLY works if it reads from the file specified by the user).

3. Your program will produce a dictionary of words with the number of times each occurs. It maps a word to the number of times the word occurs

  • Key: a word
  • Value: the number of times the word occurs in the text. The report should be an ALPHABETIZED output table, listing the word and the number of occurrences.

NOTES:

  • The input sequence can be words, numbers or any other immutable Python object, suitable for a dict key.
  • Ignore case – apple is the same as Apple is the same as APPLE, etc.
  • Discard all punctuation and extra white space (newlines, tabs, blanks, etc.).
  • Put the words into a dictionary. The first time a word is seen, the frequency is 1. Each time the word is seen again, increment the frequency. NOTE: you are REQUIRED to use the dictionary class for this assignment.
  • Produce a frequency table. To alphabetize the frequency table, extract just the keys and sort them. This sorted sequence of keys can be used to extract the counts from the dict.
  • Make sure that your output (the table) is formatted so that the columns are aligned, and so that there are titles for each column.
  • Be sure to modularize your code, using functions appropriately.
  • The main function should be clean and easy to read, calling the functions with meaningful names. Pass parameters – do not use global variables.

BONUS +5 pts:

  • Create a menu-driven front-end to this application.
    • First, populate the dictionary from the file
    • Next, provide a menu that allows the user to
      • Add words to the dictionary
                after asking the user for the word to add
                Note: the count should increase if the word is already there)
      • Check if a word is already in the dictionary
      • Delete a word from the dictionary after asking the user for the word to delete
      • Print the dictionary entries in table form as described above.
  • Allow the user to continue using the menu until they choose the option to quit.

In: Computer Science

write an report essay on the topic "the growing urban youth unemployment" (MAX WORD 1260) requesting...

write an report essay on the topic "the growing urban youth unemployment"

(MAX WORD 1260)

requesting to be in word document

In: Economics

describe the role of osteoblast and osteoclast in your own word Describe layers pf epidermis in...

describe the role of osteoblast and osteoclast in your own word Describe layers pf epidermis in your own word

In: Anatomy and Physiology

Consider the phrase "confidence interval" - what does the word "confidence" imply and what is the...

Consider the phrase "confidence interval" - what does the word "confidence" imply and what is the information provided by the word "interval"?

In: Statistics and Probability