 # Python Assignment

## Transcribed Text

ASSIGNMENT 1: Instructions: Add your code as indicated in each function body Besides adding yor code, Do not alter this file at all Do not delete or change the test cases You can check the total score to see your assignment score If you get error in test cases that means your function does not work properly so recode it Rename the file as firstname_lastname_assignmentid.ipynb such as marina_johnson_assignment1.ipynb QUESTIONS ¶ Question 1 In : # This function will search the given text in order to find a given word def is_word_there(text, word): """ What it takes? a text to be searched a word to be searched within a text what it does? searches if a word occurs in a text What it returns? returns 1 if word is in the text. returns -1 if word is not in the text """ # your code goes in here return Question 2 In : # This function will go over the text # and count the number of occurances of a given word def count_word(text, word): """ What it takes? a text to be searched a word to be searched within a text what it does? finds how many times a word occurs in a text for example, the text is 'I like to play football. I also like to watch football. My favorite football team is Eagles.' let's say the word to be searched is football. then, the function should return 3. What it returns? return the number of word counts in a text. It will return an integer if the word does not in the text, return -1. """ # your code goes in here return Question 3 # given a radius, find the area of a circle def get_area_circle(r): """ what it takes radius of a circle (any positive real number) what it does: computes the area of a circle given a radius, find the area of a circle area = pi*r2 (pi times r squared) what it returns area of a circle. Any positive real number (float) """ # your code goes in here return In : Question 4 In : # Given a number, this function will compute the factorial def get_factorial(number): """ what it takes? number to calculate its factorial what it does? given a number, find its factorial such as 5! = 20 Do not use a python built-in function - code it what it returns? factorial of a number 5! shoukld return 120 It will return integer """ # your code goes in here return Question 5 In : Question 6 - 2 points In : # This function checks whether a given number is even or not def isEven(number): """ what it takes? a number what it does? determines if a number is even what it returns? if even, return +1 if odd, return -1 """ # your code goes in here return Question 7 - 2 points In : # This function checks whether a given number is odd or not def isOdd(number): """ what it takes? a number what it does? determines if a number is odd what it returns? if even, return +1 if odd, return -1 """ # your code goes in here return Question 8 # This function will sum the lists elementwise def sum_lists(list1, list2): """ What it takes? two lists of numbers What it does? given that list1 and list 2 are equal sizes get the sum of these two lists elementwise What it returns? for example: """ list1 = [1, 6, 12] list2 = [4, 2, 14] your sum should return [5, 8, 26] it will return a LIST # your code goes in here return In [ ]: Question 9 In [ ]: # find the range def compute_range(a_list): """ what it takes? a list of numbers what it does? for a given list of numbers, find the range remember range is maximum number - minimum number what it returns? a number (float or integer depending on the numbers) """ # your code goes in here return Question 10 In [ ]: # compare documents and find common words def get_common_words(text1, text2): """ What it takes as an argument? two text variables what it does? find common words occuring in both texts What it returns? must return a LIST of common words """ # your code goes in here return def compute_stdev(a_list): """ What it takes? a list of numbers what it does? given a list of numbers compute the standard deviation (find the formula for standard deviation online if you dont remember it) Here are the steps that you will follow: 1. find the mean of the numbers 2. subtract the mean from each numbers 3. square the differences 4. sum the differences 5. divide by (the size (len) of the list - 1) if there are 5 items in the list, divide it by 4 6. take the square root of the result 7. return it what it returns? a number (float), which is the standard deviation """ # your code goes in here return TEST CASES - DO NOT TOUCH ANYTHING BELOW HERE In [ ]: Test case 1 In [ ]: Test case 2 In [ ]: Test case 3 In [ ]: Test case 4 In [ ]: Test case 5 In [ ]: Test case 6 In [ ]: Test case 7 text = """ Python is an amazing programming language. Python is also one of the primary languages in the data analysis field""" word = "amazing" if is_word_there(text, word) ==1: score.append('pass') else: score.append('fail') word = "Python" if count_word(text, word) ==2: score.append('pass') else: score.append('fail') if ((get_area_circle(5) > 78) and (get_area_circle(5)<79)): score.append('pass') else: score.append('fail') if get_factorial(5) == 120: score.append('pass') else: score.append('fail') if sum_lists([1,2, 3], [10, 11, 12]) == [11, 13, 15]: score.append('pass') else: score.append('fail') if isEven(5) == -1: score.append('pass') else: score.append('fail') if isOdd(5) == 1: score.append('pass') else: score.append('fail') In [ ]: score = [] Test case 8 if (compute_stdev([5, 4, 8, 3]) > 2.160) and (compute_stdev([5, 4, 8, 3]) < 2.162): score.append('pass') else: score.append('fail') In [ ]: Test case 9 In [ ]: Test case 10 In [ ]: Total Score In [ ]: if compute_range([2, 5, 8, 1]) == 7: score.append('pass') else: score.append('fail') text1 = """ Python is an amazing programming language. It is also one of the primary languages in the data analysis field""" text2 = "Python is a genus of constricting snakes in the Pythonidae family. You can find amazing pictures of p ython snakes in this link" if get_common_words(text1, text2).sort() == ['amazing', 'of', 'the', 'is', 'python', 'in'].sort(): score.append('pass') else: score.append('fail') j=1 for i in score: print('you ', i, 'the test case ', j) j = j+1 print('\n', 'your total score is ',score.count('pass')*1.6)

## Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* __ASSIGNMENT 1:__\n",
"    * Instructions: \n",
"       * Add your code as indicated in each function body\n",
"       * Besides adding yor code, Do not alter this file at all\n",
"       * Do not delete or change the test cases\n",
"       * You can check the total score to see your assignment score\n",
"       * If you get error in test cases that means your function does not work properly so recode it\n",
"       * Rename the file as firstname_lastname_assignmentid.ipynb such as marina_johnson_assignment1.ipynb"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# QUESTIONS"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 1"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# This function will search the given text in order to find a given word\n",
"import re\n",...
\$10.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

• 1
• 2
• 3
Live Chats