In Python: how can I fix the IsADirectoryError: [Errno 21] Is a directory: ???
this is my code:
#importing sqlite and pandas
import sqlite3
import pandas as pd
#goal
print("Welcome! The goal of this assigment is to create a database to find meanings and synonyms for given phrases.")
#Connecting database
conn = sqlite3.connect("keilavaldez.db")
#Creating cursor to remove existing specified tables
cur = conn.cursor()
#creating tables
cur.execute("CREATE TABLE Synsets([SynsetID] INTEGER,[Definition] text)")
cur.execute("CREATE TABLE Phrases([SynsetID] INTEGER,[phrase] text)")
conn.commit()
#opening and reading table named "synsets"
with open("//Users//keilavaldez//Desktop//assigment 10", 'r') as f:
for line in f:
data = line.split('\t')
cur.execute('INSERT INTO synsets (SynsetID, Definition) VALUES (?, ?)', (data[0], data[1].strip()))
#opening and reading table named "phrases"
with open("//Users//keilavaldez//Desktop//assigment 10", 'r') as f:
for line in f:
data = line.split('\t')
cur.execute('INSERT INTO phrases (SynsetID, phrase) VALUES (?, ?)', (data[0], data[1].strip()))
#Asking the user to enter a phrase
#checking if the phrase its in the database
#checking phrases even if they are lower
phrase = str(input("Please enter a phrase: "))
query = 'SELECT * FROM phrases WHERE phrase=' + "'"+ phrase.lower() + "'"
df = pd.read_sql_query(query, conn)
#if phrase is not in database, asking the user to try again
if df.empty:
print("Phrase/word not found. Please try again!")
#returning output if output is in database
#printing how many meanings the phrase has
#printing synonyms, printing unique synonyms
#prinit
else:
result_query = 'SELECT DISTINCT s.SynsetID,Definition FROM phrases p INNER JOIN synsets s ON s.SynsetID=p.SynsetID WHERE phrase=' + "'"+ word.lower() + "'"
result_df = pd.read_sql_query(result_query, conn)
lst = result_df['SynsetID'].values.tolist()
query = 'SELECT DISTINCT phrase,SynsetID FROM phrases WHERE SynsetID IN (SELECT DISTINCT s.SynsetID FROM phrases p INNER JOIN synsets s ON s.SynsetID=p.SynsetID WHERE phrase=' + "'"+ word.lower() + "') AND phrase<>"+ "'"+ word.lower() + "'"
df = pd.read_sql_query(query, conn)
syn = df['phrase'].values.tolist()
print("There are "+ str(len(lst)) +" meanings and "+ str(len(syn)) +" unique synonyms")
j=1
#priniting along with the synset ID
#printing all synonyms
for i in lst:
print("The meaning of this word: ",j)
print(result_df[result_df['SynsetID']==i]["The definition of this word: "].values[0])
print("Synset ID: ")
print(i)
print("Synonyms:")
words = df[df['SynsetID']==i]['phrase'].values.tolist()
for w in words:
if w!=phrase.lower():
print(w)
j=j+1
In: Computer Science
Python please
A string is one of most powerful data types in programming. A string object is a sequence of characters and because it is a sequence, it is indexable, using index numbers starting with 0. Similar to a list object, a string object allows for the use of negative index with -1 representing the index of the last character in the sequence. Accessing a string object with an invalid index will result in IndexError exception.
In Python a string literal is defined to be a sequence of characters enclosed in single, double or triple quotes.
To define a string object or variable, we use one of the following:
A string object in immutable, meaning, it cannot be changed once it is defined.
The concatenation operator (+) is used to add two or more string objects (strObj1 + strObj2)
The repetition operator (*) is used to repeat the string object (n*strObj or strObj*n, where n is an integer)
The in and not in operators are used to test if one string object is contained in another string object.
Slice a string object using strObj[start:end], start is the index of the starting character and end-1 is the index last character.
The split method creates a list of the split string object.
lstObj = strObj.split(split-character)
space is the default split-character.
The strip method removes the leading and trailing character, the default is space.
strObj.strip(strip-character)
Variations: rstrip, lstrip (left and right strip methods to remove leading and trailing character, respectively)
Other commonly used string methods are
strObj.lower() changes all characters to lowercase
strObj.upper() changes all characters to uppercase
strObj.islower() tests if all characters are lowercase
strObj.isupper() tests if all characters are uppercase
strObj.replace(old, new) replaces old substring with new substring
strObj.find(substring) returns the lowest index of the substring if it is found in strObj
Activity
In: Computer Science
Python please Questions #6 and # 7 please
A string is one of most powerful data types in programming. A string object is a sequence of characters and because it is a sequence, it is indexable, using index numbers starting with 0. Similar to a list object, a string object allows for the use of negative index with -1 representing the index of the last character in the sequence. Accessing a string object with an invalid index will result in IndexError exception.
In Python a string literal is defined to be a sequence of characters enclosed in single, double or triple quotes.
To define a string object or variable, we use one of the following:
A string object in immutable, meaning, it cannot be changed once it is defined.
The concatenation operator (+) is used to add two or more string objects (strObj1 + strObj2)
The repetition operator (*) is used to repeat the string object (n*strObj or strObj*n, where n is an integer)
The in and not in operators are used to test if one string object is contained in another string object.
Slice a string object using strObj[start:end], start is the index of the starting character and end-1 is the index last character.
The split method creates a list of the split string object.
lstObj = strObj.split(split-character)
space is the default split-character.
The strip method removes the leading and trailing character, the default is space.
strObj.strip(strip-character)
Variations: rstrip, lstrip (left and right strip methods to remove leading and trailing character, respectively)
Other commonly used string methods are
strObj.lower() changes all characters to lowercase
strObj.upper() changes all characters to uppercase
strObj.islower() tests if all characters are lowercase
strObj.isupper() tests if all characters are uppercase
strObj.replace(old, new) replaces old substring with new substring
strObj.find(substring) returns the lowest index of the substring if it is found in strObj
Activity
In: Computer Science
Python please Questions #3, #4 and # 5 please
A string is one of most powerful data types in programming. A string object is a sequence of characters and because it is a sequence, it is indexable, using index numbers starting with 0. Similar to a list object, a string object allows for the use of negative index with -1 representing the index of the last character in the sequence. Accessing a string object with an invalid index will result in IndexError exception.
In Python a string literal is defined to be a sequence of characters enclosed in single, double or triple quotes.
To define a string object or variable, we use one of the following:
A string object in immutable, meaning, it cannot be changed once it is defined.
The concatenation operator (+) is used to add two or more string objects (strObj1 + strObj2)
The repetition operator (*) is used to repeat the string object (n*strObj or strObj*n, where n is an integer)
The in and not in operators are used to test if one string object is contained in another string object.
Slice a string object using strObj[start:end], start is the index of the starting character and end-1 is the index last character.
The split method creates a list of the split string object.
lstObj = strObj.split(split-character)
space is the default split-character.
The strip method removes the leading and trailing character, the default is space.
strObj.strip(strip-character)
Variations: rstrip, lstrip (left and right strip methods to remove leading and trailing character, respectively)
Other commonly used string methods are
strObj.lower() changes all characters to lowercase
strObj.upper() changes all characters to uppercase
strObj.islower() tests if all characters are lowercase
strObj.isupper() tests if all characters are uppercase
strObj.replace(old, new) replaces old substring with new substring
strObj.find(substring) returns the lowest index of the substring if it is found in strObj
Activity
In: Computer Science
Question
Objective:
The purpose of this lab is for you to become familiar with Python’s built-in text container -- class str -- and lists containing multiple strings. One of the advantages of the str class is that, to the programmer, strings in your code may be treated in a manner that is similar to how numbers are treated. Just like ints, floats, a string object (i.e., variable) may be initialized with a literal value or the contents of another string object. String objects may also be added together (concatenation) and multiplied by an integer (replication). Strings may also be compared for “equality” and arranged into some order (e.g., alphabetical order, ordering by number of characters, etc.). Finally, strings may be placed in containers which can then be passed as arguments to functions for more complex manipulations.
Specifications:
Write an interactive Python program composed of several functions that manipulate strings in different ways. Your main() function prompts the user for a series of strings which are placed into a list container. The user should be able to input as many strings as they choose (i.e., a sentinel-controlled loop). Your main function will then pass this list of strings to a variety of functions for manipulation (see below).
The main logic of your program must be included within a loop that repeats until the user decides he/she does not want to continue processing lists of strings. The pseudo code for the body of your main() function might be something like this:
# Create the main function
def main():
# declare any necessary variable(s)
# // Loop: while the user wants to continue processing more lists of words
#
# // Loop: while the user want to enter more words (minimum of 8)
# // Prompt for, input and store a word (string) into a list # // Pass the list of words to following functions, and perform the manipulations
# // to produce and return a new, modified, copy of the list.
# // NOTE: None of the following functions can change the list parameter it
# // receives – the manipulated items must be returned as a new list.
#
# // SortByIncreasingLength(…)
# // SortByDecreasingLength(…)
# // SortByTheMostVowels(…)
# // SortByTheLeastVowels(…)
# // CapitalizeEveryOtherCharacter(…)
# // ReverseWordOrdering(…)
# // FoldWordsOnMiddleOfList(…)
# // Display the contents of the modified lists of words
#
# // Ask if the user wants to process another list of words
Deliverable(s):
Your deliverable should be a Word document with screenshots showing the sample code you have created, and discuss the issues that you had for this project related to AWS and/or Python IDE and how you solved them.
Submit the program you develop including captured output. Also turn in screen captures from running your program inputting, as a minimum, three (3) sets word lists (no fewer than 8 words per list).
In: Computer Science
Literature Review
Words: 500
Article Chosen: Parent–Child Aggression: Association With Child Abuse Potential and Parenting Styles
https://libres.uncg.edu/ir/uncg/f/C_Rodriguez_Parent_2010.pdf
Guidelines
Guide only, feel free to organise however else you like to as long as you address the learning outcomes and elements in the rubric.
* Introduction
Introduce the general issue and its importance
Identify key trends or perspectives
Identify the specific focus of this literature review (your identified issue)
Give a brief outline of the structure of the body
* Body
Cluster your literature around common themes or threads of ideas. Structure your writing thematically and not author by author. This allows you to compare, contrast, and make sense of the different authors’ perspectives on one point./ And if you find there are a lot of authors with some contribution to one point, then maybe that point needs to be teased out into sub-themes
Try not to hide behind what the literature is saying. Remember, it is up to you to interpret it and make sense of it for your reader. Listing what they have found or believe is part of a literature review, but in itself is not enough, you need to clarify what the reader is to take away from this body of research
Never be afraid to narrow your topic. You have a word limit, which is enough to make one meaningful point, but not to include detail for its own sake. It is better to dig deep into a topic rather than be broad and superficial
You may have to limit your question many times before you finalise your draft. Spend time considering your question/topic, because this provides the guidelines for your writing and your research. You need to have clear guidelines so that you can research with purpose and efficiency, even if these guidelines are modified later. Otherwise a lot of time and energy will be wasted, either, looking at irrelevant material, or material that cannot fit into your review
* Conclusion
Summarize the major contributions, evaluating the current position, and pointing out flaws in methodology, gaps in the research, contradictions and areas for further study
Conclude by summing up and identifying the significance of the topic in relation to the literature
* Please ensure that you write succinctly to avoid wasting your word count. Note that unnecessary words weakens your argument. You should keep within +/- 10% of your word count
* Check for spelling and grammatical errors. Loosing marks from errors that could be addressed through editing is not worth it.
* Make sure that all references are correctly referenced using APA style
* Refer to Unit Guide for more information about the unit requirements
In: Psychology
I have one error and it encounters my split array and it should
output true or false
public class Main
{
private static int[] freq;
static boolean doubleOrNothing(int[] array, int size, int
i)
{
if (size <= 1)
return false;
if (2 * array[i] == array[i+1])
return true;
return doubleOrNothing(array, size - 1, i++);
}
/**
*
* @param word
* @param sep
*
*
* @param count
* @return
*/
public static String wordSeparator(String word, String sep, int
count)
{
if (count <= 0)
return "";
String new_word="";
if (count == 1)
return word;
return word + sep + wordSeparator(word, sep, count - 1);
}
static boolean mcNuggetNumber(int n) //checks for 3 or 7 piece
chicken nugget
{
boolean l = false, r = false;
if (n == 3 || n == 7)
return true;
if (n >= 3)
l = mcNuggetNumber(n - 3);
if (n >= 7)
r = mcNuggetNumber(n - 7);
return l || r;
}
static boolean splitArray(int arr[], int n, int k)
{
// An odd length array cannot be divided into pairs
if (n == 1)
return false;
// Create a frequency array to count occurrences
// of all remainders when divided by k.
// map freq = null;
// Count occurrences of all remainders
for (int i = 0; i < n; i++)
freq[arr[i] % k]++;
// Traverse input array and use freq[] to decide
// if given array can be divided in pairs
for (int i = 0; i < n; i++)
{
// Remainder of current element
int rem = arr[i] % k;
// If remainder with current element divides
// k into two halves.
if (2 * rem == k)
{
// Then there must be even occurrences of
// such remainder
if (freq[rem] % 2 != 0)
return false;
}
// If remainder is 0, then there must be two
// elements with 0 remainder
else if (rem == 0)
{
if (1 & freq[rem])
{
return false;
}
else
{
}
}
// Else number of occurrences of remainder
// must be equal to number of occurrences of
// k - remainder
else if (freq[rem] != freq[k - rem])
return false;
}
return true;
}
public static void main(String[] args) {
int a1[] ={1};
int a2[] = { 1,2 };
int a3[] = { 0,0,1 };
int a4[] = { 2,3,4 };
int a5[] = { 1,3,5,10 };
int a6[] = { 1,3,5,11 };
int a7[] = { 9,8,7,6,5,4,3,2,1 };
int a8[] = { 9,8,7,6,12,4,3,2,1 };
int i1[] = { 7 };
int i2[] = { 3,4 };
int i3[] = { 3,4,5 };
int i4[] = { 9,10,11 };
int o1[] = { 3,4 };
int o2[] = { 2,3,4 };
int o3[] = { 3,4,5,6 };
int o4[] = { 1,2,3,4,5,6 };
int s1[] = { 2, 2 };
int s2[] = { 2, 3 };
int s3[] = { 5, 2, 3 };
int s4[] = { 5, 2, 2 };
int s5[] = { 1, 1, 1, 1, 1, 1 };
int s6[] = { 1, 1, 1, 1, 1 };
int s8[] = { 1 };
int s9[] = { 3, 5 };
int s10[] = { 5, 3, 2 };
int s11[] = { 2, 2, 10, 10, 1, 1 };
int s12[] = { 1, 2, 2, 10, 10, 1, 1 };
int s13[] = { 1, 2, 3, 10, 10, 1, 1 };
System.out.println("Jones Robert ");
System.out.println("Assignment 3");
System.out.println("Recursion.");
System.out.println("All calls must result in true or
false.");
System.out.println();
System.out.println("Double Or Nothing." );
System.out.println("1. " + doubleOrNothing(a1, 1,0) );
System.out.println( "2. " + doubleOrNothing(a2, 2,0) );
System.out.println("3. " + doubleOrNothing(a3, 3,0) );
System.out.println("4. " + doubleOrNothing(a4, 3,0));
System.out.println("5. " + doubleOrNothing(a5, 4,0) );
System.out.println("6. " + doubleOrNothing(a6, 4,0) );
System.out.println("7. " + doubleOrNothing(a7, 9,0) );
System.out.println("8. " + doubleOrNothing(a8, 9,0) );
System.out.println();
System.out.println();
System.out.println("Word Separator.");
System.out.println("1. " + wordSeparator("Y", "X", 4));
System.out.println("2. " + wordSeparator("Y", "X", 2));
System.out.println("3. " + wordSeparator("Y", "X", 1));
System.out.println("4. " + wordSeparator("Y", "X", 0));
System.out.println();
System.out.println("McNugget Numbers" );
System.out.println(" 1. " + mcNuggetNumber(0));
System.out.println(" 2. " + mcNuggetNumber(1) );
System.out.println(" 3. " + mcNuggetNumber(2) );
System.out.println(" 4. " + mcNuggetNumber(3) );
System.out.println(" 5. " + mcNuggetNumber(4) );
System.out.println(" 6. " + mcNuggetNumber(5) );
System.out.println(" 7. " + mcNuggetNumber(6) );
System.out.println(" 8. " + mcNuggetNumber(7) );
System.out.println(" 9. " + mcNuggetNumber(8) );
System.out.println("10. " + mcNuggetNumber(9) );
System.out.println("11. " + mcNuggetNumber(10) );
System.out.println("12. " + mcNuggetNumber(11) );
System.out.println("13. " + mcNuggetNumber(12) );
System.out.println("14. " + mcNuggetNumber(13));
System.out.println("15. " + mcNuggetNumber(14));
System.out.println("16. " + mcNuggetNumber(15));
System.out.println("17. " + mcNuggetNumber(16));
System.out.println();
System.out.println ("Split the Array");
System.out.println ("1. " + splitArray (1));
System.out.println ("2. " + splitArray (2));
System.out.println ("3. " + splitArray (3));
System.out.println ("4. " + splitArray (4));
System.out.println ("5. " + splitArray (5));
System.out.println ("6. " + splitArray (6));
System.out.println ("7. " + splitArray (7));
System.out.println ("8. " + splitArray (8));
System.out.println ("9. " + splitArray (9));
System.out.println ("10. " + splitArray (10));
System.out.println ("11. " + splitArray (11));
System.out.println ("12. " + splitArray (12));
System.out.println ("13. " + splitArray (13));
System.out.println ("14. " + splitArray (14));
System.out.println ("15. " + splitArray (15));
System.out.println ("16. " + splitArray (16));
System.out.println();
}
private static String splitArray(int i) {
throw new UnsupportedOperationException("Not supported yet."); //To
change body of generated methods, choose Tools | Templates.
}
}
I have an error
In: Computer Science
Programming in C (not C++)
The high level goal of this project is to write a program called "wordfreak" that takes "some files" as input, counts how many times each word occurs across them all (considering all letters to be lower case), and writes those words and associated counts to an output file in alphabetical order.
We provide you some example book text files to test your program on. For example, if you ran
$ ./wordfreak aladdin.txt
Then the contents of the output file would be:
$ cat output.txt
a : 49
aback : 1
able : 1
...
required : 1
respectfully : 1
retraced : 1
...
that : 11
the : 126
their : 2
...
you : 20
young : 1
your : 7
The words from all the input files will be counted together. If a word appears 3 times in one input file and 4 times in another, it will be counted 7 times between the two.
Input
wordfreak needs to be able to read input from 3 sources: standard input, files given in argv, and a file given as the environment variable. It should read words from all these that are applicable (always standard in, sometimes the other 2).
A working implementation must be able to accept input entered directly into the terminal, with the end of such input signified by the EOF character (^D (control+d)):
$ ./wordfreak
I can write words here,
and end the file with control plus d
$ cat output.txt
and : 1
can : 1
control : 1
d : 1
end : 1
file : 1
here : 1
i : 1
plus : 1
the : 1
with : 1
words : 1
write : 1
However, it should alternately be able to accept a file piped in to standard input via bash’s operator pipe:
$ cat aladdin.txt | ./wordfreak
It should be noted that your program has no real way to tell which of these two situations is occuring, it just sees information written to standard input. However, by just treating standard input like a file, you will get both of these behaviours.
A working implementation must also accept files as command line arguments:
$ ./wordfreak aladdin.txt iliad.txt odyssey.txt
Finally, a working implementation must also accept an environment variable called WORD_FREAK set to a single file from the command line to be analyzed:
$ WORD_FREAK=aladdin.txt ./wordfreak
And of course, it should be able to do all of these at once
$ cat newton.txt | WORD_FREAK=aladdin.txt ./wordfreak iliad.txt odyssey.txt
Words
Words should be comprised of only alpha characters, and all alpha characters should be taken to be lower case.
For example "POT4TO???" would give the words "pot" and "to". And the word "isn’t" would be read as "isn" and "t". While this isn't necessarily intuitively correct, this is what your code is expected to do:
$ echo "Isn’t that a POT4TO???" | ./wordfreak
$ cat output.txt
a : 1
isn : 1
pot : 1
t : 1
that : 1
to : 1
You are required to store the words in a specific data structure. You should have a binary search tree for each letter 'a' to 'z' that stores the words starting with that letter (and their counts). This can be thought of as a hash function from strings to binary search trees, where the hashing function is just first_letter - 'a'. Note that these BSTs will not likely be balanced; that is fine.
Output
The words should be written to the file alphabetically (the BSTs make this fairly trivial). Each word will give a line of the form "[word][additional space] : [additional space][number]\n". The caveat is that all the colons need to line up. The words are left-aligned and the longest will have a single space between its end and the colon (note "respectfully" in the example below); the numbers are right-aligned and the longest will have a single space between the colon and its beginning (note 126 in the example below).
$ ./wordfreak aladdin.txt
$ cat output.txt
a : 49
...
respectfully : 1
...
the : 126
...
your : 7
The output file should be named output.txt. Note that when opening the file to write to, you will either need to create the file or remove all existing contents, so make use of open()'s O_CREAT and O_TRUNC. Moreover, you will want the file’s permissions to be set so that it can be read. open()’s third argument determines permissions of created files, something like 0644 will make it readable.
restricted to only using the following system calls: open(), close(), read(), write(), and lseek() for performing I/O. You are allowed to use other C library calls (e.g., malloc(), free()). However, all I/O is restricted to the Linux kernel’s direct API support for I/O. You are also allowed to use sprintf() to make formatting easier.
In: Computer Science
for parts 1-2 for
use these answers/rules
Find the relative extrema of the function Specifically:
The relative maxima of f occur at x =
The relative minima of f occur at x =
The value of f at its relative minimum is
the value of f at its relative maximum is
Notes: Your answer should be a comma-separated list of values or the word "none".
part 1)
f(x)=9x−(4/x)+6
part 2)
f(x)=(8x^2−7x+32)/(x)
part 3)
Use the derivative to find the vertex of the parabola
y=−3x^2+12x−9
Answer: the vertex has coordinates
x=
and
y=.
In: Math
Australia has been a world leader in using 'healthy public
policy approaches' such as legislation and taxation to address
tobacco consumption. Since the 1990s, our policy measures have led
to significant smoking decline across Australia. Using one of the
several tobacco control policies in Australia, describe each of the
following phases of Walt’s (1994) policy making framework as stated
in Baum (2016; Chapter 24: Healthy Public Policy, p 620-621):
a. Problem identification and issue recognition
b. Policy formulation
c. Policy implementation
d. Policy evaluation
Word limit = 500 words
Note: You can use innovative ways to present this response
In: Nursing