Questions
Using python, please complete these 4 exercises. Please limit your code to these skills: For loop...

Using python, please complete these 4 exercises. Please limit your code to these skills:

For loop

While loop

Input function

F strings

Tuples

Lists

Nested ifs

Elias

Exercise 1

Using the following list, do the following:

  1. Sort it in ascending order
  2. In a print statement, referencing the list and its index numbers, print the lowest value and the highest value.

[15, 70, 15, 38, 49, 98, 62, 89, 2, 21, 40, 74, 36, 36, 65, 1, 55, 16, 24, 56]

Exercise 2 (1 Point):

Using the following list, do the following:

1. Iterate through each element in the list

2. Print out whether the element is positive or negative or zero on a new line for each element.

[-2, 1, -2, 7, -8, -5, 5, 10, -6, 7]

Exercise 3 (2 Points):

Create a new list using the range function, appending the values from the range function's output into the list.

The range function must:

  1. Start at 1
  2. Stop at 50
  3. Skip every other number

Hint: Use either a for loop or a list comprehension

Exercise 4 (6 Points):

In this exercise, you will be required to do the following:

Take the following phrase: The only thing we have to fear is fear itself

  1. Convert it to a list
  2. Inspect each word in the list
    1. If the word in the list starts with a vowel (excluding y), then:
      1. add the letters "way" to the end of the word.
      2. EX: the word "and" would become "andway"
    2. If the word in the list does not start with a vowel (including y), then:
      1. take the first letter from the word and move it to the end of the word
      2. add to the end of the word, the letters "ay"
      3. EX: the word "money" would become "oneymay"
  3. Append each modified word to a new list
  4. convert the list to a string and print that string out
    1. HINT: use join()

So, the end result should be:

Hetay onlyway hingtay eway avehay otay earfay isway earfay itselfway

In: Computer Science

Java If the word begins with a single consonant followed by a vowel, move the consonant...

Java

  1. If the word begins with a single consonant followed by a vowel, move the consonant to the end of the word and add โ€œayโ€ after.
    • hello โ†’ [h]ello โ†’ ello[h] โ†’ elloh[ay] โ†’ ellohay
    • word โ†’ [w]ork โ†’ ork[w] โ†’ orkw[ay] โ†’ orkway
  2. If the word begins with a consonant cluster (more than one consonant followed by a vowel), move the entire consonant cluster to the end of the word and add โ€œayโ€ after.
    • start โ†’ [st]art โ†’ art[st] โ†’ artst[ay] โ†’ artstay
    • through โ†’ [thr]ough โ†’ ough[thr] โ†’ oughthr[ay] โ†’ oughthray
  3. If the word begins with a vowel, simply add โ€œyayโ€ to the end of the word.
    • on โ†’ [o]n โ†’ on[yay] โ†’ onyay
    • a โ†’ [a] โ†’ a[yay] โ†’ ayay
    • unique โ†’ [u]nique โ†’ unique[yay] โ†’ uniqueyay

If the word contains the letter "y", there are some special rules that must be applied:

  1. If the word begins with the letter โ€œyโ€ followed by a vowel, treat the โ€œyโ€ as a consonant.
    • yes โ†’ [y]es โ†’ es[y] โ†’ esy[ay] โ†’ esyay
    • yellow โ†’ [y]ellow โ†’ ellow[y] โ†’ ellowy[ay] โ†’ ellowyay
  2. If the word begins with a consonant or consonant cluster followed by the letter โ€œyโ€, treat the โ€œyโ€ as a vowel.
    • thy โ†’ [th]y โ†’ y[th] โ†’ yth[ay] โ†’ ythay
    • rhythm โ†’ [rh]ythm โ†’ ythm[rh] โ†’ ythmrh[ay] โ†’ ythmrhay

In the rules above, the letters "a", "e", "i", "o", and โ€œuโ€ are considered vowels, and all other letters are considered consonants, except for โ€œyโ€ as described above.

Other Characters

Beyond translating words, there are a few other rules to be aware of.

  1. If the original wordโ€™s first letter is capitalized, the translated word should also have its first letter capitalized.
    • Hello โ†’ [H]ello โ†’ ello[h] โ†’ elloh[ay] โ†’ [e]llohay โ†’ Ellohay
    • I โ†’ [I] โ†’ I[yay] โ†’ Iyay
  2. If the original word ends in a punctuation, move the punctuation to the end of the translated word.
    • hello. โ†’ hello[.] โ†’ [h]ello โ†’ ello[h] โ†’ elloh[ay] โ†’ ellohay[.] โ†’ ellohay.

Program Specification

Input

Our program should accept input in one of two ways:

  1. If a command-line argument is provided, it should read input from the file given as that argument.
  2. If no command-line arguments are provided, the program should read input directly from the terminal.

Each run of the program may consist of multiple lines of input. The total number of lines will vary. Input will end with either an EOF (end of file) marker, or a blank line of input. Your program should stop accepting input when either of these situations occurs.

Each line of input will contain words to be converted to Pig Latin. You may assume that the lines will only contain letters a-z A-Z, spaces , and common punctuation marks that are placed at the end of words !.,?.

You may assume that words are separated by spaces, but they may have attached punctuation marks at the end.

Input 1

hello world

Output 1

ellohay orldway

Input 2

A good day to Kansas!

Output 2

Ayay oodgay ayday otay Ansaskay!

In: Computer Science

(IN YOUR WORD) write a 400-word long, five paragraph essay about effect of Noise pollution (SUPPORTED...

(IN YOUR WORD) write a 400-word long, five paragraph essay about effect of Noise pollution

(SUPPORTED with a clear THESIS STATEMENT and five well-developed paragraphs)

In: Psychology

Here is a Problem I need to solve: 5) Write a function to determine is a...

Here is a Problem I need to solve:

5) Write a function to determine is a given word is legal. A word is illegal if it contains no vowels. For this problem,
the letter Y is considered to be a legal vowel. Pass in a word to this function and it will determine if the word is
legal or not. You can make the following assumptions about the word you a passing to this function.
1) The string being passed is a combination of letters only (no non-letter check needed)
2) The string being passed is null terminated
3) Letters may be capital or lower case and it has no effect on whether its a word

I think I am in the right direction below. But the problem is my proposed solution involves two separate functions. My question is how I can make this one function?

  1. int isVowel(char c){

  2. if(c>='A' && c<='Z')

  3. c=c+32;

  4. if(c=='a' || c=='e' || c=='i'|| c=='o'|| c=='u'|| c=='y')

  5. return 1;

  6. else

  7. return 0;

  8. }

  9. int validString(char *c){

  10. int i;

  11. for(i=0;c[i]!='\0';i++)

  12. if(isVowel(c[i]))

  13. return 1;

  14. return 0;

  15. }

In: Computer Science

Create a program that reports whether each word in a set of words appears in a...

Create a program that reports whether each word in a set of words appears in a paragraph. Here are the requirements: a. Ask the user to enter a set of words, one at a time. Use an appropriate prompt to keep asking for words until a blank line is entered. The set of words should be in a dictionary, where the word is the key, and โ€œyesโ€ or โ€œnoโ€ is the value. The value represents whether the word appears in the paragraph. As the words are entered, the value should initially be โ€œnoโ€. b. Ask the user to enter a paragraph. Use an appropriate prompt to keep asking for lines/sentences of the paragraph. The lines/sentences should be in a list (of strings). When the user enters a blank line, the paragraph is complete. c. Once the paragraph is entered, check to see if each word in the dictionary is in the paragraph. If it is, then set the value of that key (word) to โ€œyesโ€. It is sufficient to determine if the word is in the paragraph. You do not need to find all instances, nor count the number of instances. d. Present the results by writing the results of the dictionary using a loop. (Do not simply print the dictionary as a whole.) This should appear as two columns of data, with the key in the first column, and the corresponding value of โ€œyesโ€ or โ€œnoโ€ in the second column.

In: Computer Science

Map word scanning in C++ For some context, I've been working on a program in which...

Map word scanning in C++

For some context, I've been working on a program in which I must enter in words and clear them of any potential punctuations. If a word has punctuation in the middle of the word, I must ignore the letters AFTER the punctuation and delete the punctuation as well. For example if I enter in "fish_net" I will only get "fish" back. I must also keep track of the occurrence of each word as well as number of words.

Here's my problem, I'm using a do while loop to continuously enter in words and break from it when needed. When I do, my output is supposed to be separate words, but they are getting merged with each other and counting it as one word. For example, lets say I enter in the words: "hello" "there" "done". The INTENDED output should be the following: hello 1 (newline) there 1 (newline) done 1. However, the output CURRENTLY goes like this: hello 1 (newline) hellothere 1 (newline) hellotheredone 1. Mind you that the numbers after the words are the number of occurrences that word is entered.

#include <iostream>
#include<map>
#include<string>
#include <algorithm>
using namespace std;

void get_words(map<string, int>&);
void print_words(const map<string, int>&);
void clean_entry(const string&, string&);

int main()
{
   map<string,int>m;
   get_words(m);
   print_words(m);
}

void get_words(map<string, int>&m)
{
   string word, cleaned_words = "";
   cout << "Enter in a string of text: ";
   do
   {  
       cin >> word;
       clean_entry(word, cleaned_words);

       if (cleaned_words.length() != 0)
       {
           m[cleaned_words]++;//inserting clean words into map
       }
  
   } while (word != "done");
}

void print_words(const map<string, int>&m)
{  
   int non_empty_words = 0;
   for (auto it = m.begin(); it != m.end(); it++)
   {
       cout << it->first << " " << it->second << endl;
       non_empty_words += it->second;
   }
   cout << "Non-empty words: " << non_empty_words << endl;
   cout << "Words: " << m.size();
}

void clean_entry(const string&words, string&cleaned_words)
{
   int len = words.length();
   int i = 0;
   while (i < len && ispunct(words[i])) i++;//parse through initial punctuation (make sure that punctuation is deleted while leaving word intact if in front or back)
   while (i < len && !ispunct(words[i]))//while we come across any words with no punctuation, we add it to cleaned words
   {
       cleaned_words += words[i];
       i++;
   }
}

In: Computer Science

Need to design a program in C++ that plays hangman using classes (polymorphism and inheritance) Below...

Need to design a program in C++ that plays hangman using classes (polymorphism and inheritance)

Below is the code only need to add the classes and make the program run with at least one class of Polymorphism and Inheritance.

CODE:

#include <iostream>
#include <cstdlib>
#include<ctime>
#include <string>
using namespace std;

int NUM_TRY=8; //A classic Hangman game has 8 tries. You can change if you want.
int checkGuess (char, string, string&); //function to check the guessed letter
void main_menu();
string message = "Play!"; //it will always display


int main(int argc, char *argv[])
{
string name;
char letter;
string word;
  

string words[] = //These are the list of 10 three lettered words.
{ //You can change them as per your requirement.
"man",
"van",
"tan",
"hop",
"pop",
"two",
"six",
"may",
"low",
"out",
};
  
srand(time(NULL));
int n=rand()% 10; //Random function to genterate random words from the given list
word=words[n];
  
  
string hide_m(word.length(),'X'); // This function is used to hide the actuall word to be guessed.
//The mask selected is 'X' so the word will show as 'XXX' till you guess the correct letters.
  
  
  
while (NUM_TRY!=0)
{
main_menu();
cout << "\n" << hide_m;
cout << "\nGuess a letter: ";
cin >> letter;
  
if (checkGuess(letter, word, hide_m)==0)
{
message = "Wrong letter.";
NUM_TRY = NUM_TRY - 1;
}
else
{
message = "NICE! You guessed a letter";
}
if (word==hide_m)
{
message = "Congratulations! You got it!";
main_menu();
cout << "\nThe word is : " << word << endl;
break;
}
}
if(NUM_TRY == 0)
{
message = "NOOOOOOO!...you've been hanged.";
main_menu();
cout << "\nThe word was : " << word << endl;
}
cin.ignore();// used to discard everything in the input stream
cin.get();
return 0;
}


int checkGuess (char guess, string secretword, string &guessword)
{
int i;
int matches=0;
int len=secretword.length();
for (i = 0; i< len; i++)
{
  
if (guess == guessword[i])
return 0;
  
if (guess == secretword[i])
{
guessword[i] = guess;
matches++;
}
}
return matches;
}

void main_menu()
{
system("cls");
cout<<"\nHangman Game!";
cout << "\nYou have " << NUM_TRY << " tries to try and guess the word.";
cout<<"\n"+message;
}

//*end of code*

Hangman Game

*** Need at least to add one Class to the game code that uses Polymorphism and Inheritance.

In: Computer Science

Discuss for and against compensating victims of medical injuries via tort liability. What does the question...

Discuss for and against compensating victims of medical injuries via tort liability. What does the question above mean and paragraphs to include in an 2000 word essay. The 2000 word is mandatory

In: Economics

What is the difference between MARR(100 word), Discount Rate(100 words), and Interest Rate(100 word )? Do...

What is the difference between MARR(100 word), Discount Rate(100 words), and Interest Rate(100 word )? Do not write more than 100 words for each concept.

In: Economics

The five most common words appearing in spam emails are shipping!, today!, here!, available, and fingertips!....

The five most common words appearing in spam emails are shipping!, today!, here!, available, and fingertips!. Many spam filters separate spam from ham (email not considered to be spam) through application of Bayes' theorem. Suppose that for one email account, in every messages is spam and the proportions of spam messages that have the five most common words in spam email are given below.

shipping!        0.050      

today!             0.047

here!              0.034

Available       0.016

fingertips!      0.016


Also suppose that the proportions of ham messages that have these words are

shipping!

0.0016

today!

0.0021

here!

0.0021

available

0.0041

fingertips!

0.0010

Round your answers to three decimal places.

If a message includes the word shipping!, what is the probability the message is spam?

If a message includes the word shipping!, what is the probability the message is ham?

Should messages that include the word shipping! be flagged as spam?

b. If a message includes the word today!, what is the probability the message is spam?

If a message includes the word here!, what is the probability the message is spam?

Which of these two words is a stronger indicator that a message is spam?

Why?

Because the probability is

c. If a message includes the word available, what is the probability the message is spam?

If a message includes the word fingertips!, what is the probability the message is spam?

Which of these two words is a stronger indicator that a message is spam?

Why?

Because the probability is

d. What insights do the results of parts (b) and (c) yield about what enables a spam filter that uses Bayes' theorem to work effectively?

Explain.

It is easier to distinguish spam from ham when a word occurs in spam and less often in ham.

In: Statistics and Probability