Question

Create one Python module: arithmetic which has two functions: add(x, y) and get_length(x). The description of...

Create one Python module: arithmetic which has two functions: add(x, y) and get_length(x).

The description of two functions are below (hint: name this file arithmetic.py):

def add(x, y):

# add two numbers

def get_length(x):

# return the length of a given string

Then in the main .ipynb file of this assignment, import this arithmetic model, and call these two functions using real arguments.

Note: • You need to also submit the arithmetic.py file this question.

Homework Answers

Answer #1
Below is a screen shot of the python program to check indentation. Comments are given on every line explaining the code.
arithmetic.py:


main file:

Below is the output of the program:


Below is the code to copy:
arithmetic.py:
#CODE STARTS HERE----------------
def add(x,y): #Add function
   return x+y #Returns the sum of x and y

def get_length(x): #Get length function
   # Returns the length of x using built in function len()
   return len(x)

#CODE ENDS HERE------------------

main.py:

#CODE STARTS HERE----------------
import arithmetic #importing arithematic module(arithmetic.py)

#Call add function from arithmetic and print result
print(arithmetic.add(5,10))

#Call get_length function from arithmetic and print result
print(arithmetic.get_length("abcdefg"))
#CODE ENDS HERE------------------
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Module 4 Assignment 1: Pseudocode & Python with Variable Scope Overview Module 4 Assignment 1 features...
Module 4 Assignment 1: Pseudocode & Python with Variable Scope Overview Module 4 Assignment 1 features the design of a calculator program using pseudocode and a Python program that uses a list and functions with variable scope to add, subtract, multiply, and divide. Open the M4Lab1ii.py program in IDLE and save it as M4Lab1ii.py with your initials instead of ii. Each lab asks you to write pseudocode that plans the program’s logic before you write the program in Python and...
Please create a python module named homework.py and implement the functions outlined below. Below you will...
Please create a python module named homework.py and implement the functions outlined below. Below you will find an explanation for each function you need to implement. When you are done please upload the file homework.py to Grader Than. Please get started as soon as possible on this assignment. This assignment has many problems, it may take you longer than normal to complete this assignment. This assignment is supposed to test you on your understanding of reading and writing to a...
Function Example: Write a Python function that receives two integer arguments and writes out their sum...
Function Example: Write a Python function that receives two integer arguments and writes out their sum and their product. Assume no global variables. def writer(n1, n2): sum = n1 + n2 product = n1*n2 print("For the numbers", n1, "and", n2) print("the sum is", sum) print("and the product is", product) ... 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both...
Design a function called print_area that takes two floating-point numbers, representing the length and width of...
Design a function called print_area that takes two floating-point numbers, representing the length and width of a rectangle. The print_area function calculates and prints the area of the rectangle, rounded to two decimal places. Design a function called small_enough_word that takes a string for which the number of characters will be tested, and an integer representing the maximum allowable number of characters that the word can contain. Remember: the arguments MUST be in this order (the string of text before...
Assignment 2 Programming Language: Python 2 Preface: Create a new python file with a name of...
Assignment 2 Programming Language: Python 2 Preface: Create a new python file with a name of your choosing (ex: “assignment2.py”). At the top of the file paste the following: import numpy as np import random class Base_Obstacle_Map(object):     def __init__(self, length, width):         self.map = np.zeros((length, width), dtype=np.uint8)     def add_obstacle(self, x, y):         self.map[x, y] = 1     def remove_obstacle(self, x, y):         self.map[x, y] = 0     def display_map(self):         try:             import matplotlib.pyplot as plt             plt.imshow(self.map)...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes and methods. Purpose: The purpose of this challenge is to provide experience creating a class and working with OO concepts in Python 3. Requirements: Write a class in Python 3 named Animal that has the following attributes and methods and is saved in the file Animal.py. Attributes __animal_type is a hidden attribute used to indicate the animal’s type. For example: gecko, walrus, tiger, etc....
PHP calculator problem Create a calculator class that will add, subtract, multiply, and divide two numbers....
PHP calculator problem Create a calculator class that will add, subtract, multiply, and divide two numbers. It will have a method that will accept three arguments consisting of a string and two numbers example ("+", 4, 5) where the string is the operator and the numbers are what will be used in the calculation. It doesn't need an HTML form, all the arguments are put in through the method. The class must check for a correct operator (+,*,-,/), and a...
Create a Python main program which calls two functions enterNum and calcResult and accomplishes the following:...
Create a Python main program which calls two functions enterNum and calcResult and accomplishes the following: 1. The main program calls the function enterNum 3 times. The first time enterNum is called, the main program stores the returned output in the variable xx. The second time, the returned output is stored in the variable yy and the third time in zz. 2. enterNum asks the user to enter a floating point number. This function has no input arguments and returns...
##4. What will the following program display? ##def main(): ## x = 1 ## y =...
##4. What will the following program display? ##def main(): ## x = 1 ## y = 3.4 ## print(x, y) ## first printing ## change_us(x, y) ## print(x, y) ##second printing ## ##def change_us(a, b): ## a = 0 ## b = 0 ## print(a, b) ## ##main() ## ##Yes, yes, main() displays ##1 3.4 ##0 0 ##1 3.4 ## The question is: why x and y are still the same while the second printing of (x,y)? ## It seems...
1. Write a function called compute_discount which takes a float as the cost and a Boolean...
1. Write a function called compute_discount which takes a float as the cost and a Boolean value to indicate membership. If the customer is a member, give him/her a 10% discount. If the customer is not a member, she/he will not receive a discount. Give all customers a 5% discount, since it is Cyber Tuesday. Return the discounted cost. Do not prompt the user for input or print within the compute_discount function. Call the function from within main() and pass...