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:
[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:
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
So, the end result should be:
Hetay onlyway hingtay eway avehay otay earfay isway earfay itselfway
In: Computer Science
Java
If the word contains the letter "y", there are some special rules that must be applied:
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.
Program Specification
Input
Our program should accept input in one of two ways:
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 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 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?
int isVowel(char c){
if(c>='A' && c<='Z')
c=c+32;
if(c=='a' || c=='e' || c=='i'|| c=='o'|| c=='u'|| c=='y')
return 1;
else
return 0;
}
int validString(char *c){
int i;
for(i=0;c[i]!='\0';i++)
if(isVowel(c[i]))
return 1;
return 0;
}
In: Computer Science
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 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
In: Computer Science
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
In: Economics
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