Question: 1) Move all the functions into W5_firstname_lastname_Mylib.py 2) Use import to include W5_firstname_lastname_Mylib into the code 3) Test the code and make sure that the

1) Move all the functions into W5_firstname_lastname_Mylib.py

2) Use import to include W5_firstname_lastname_Mylib into the code

3) Test the code and make sure that the prior code is still working

4) Add the following function into Mylib

scalc(p1)

p1 will be a string like this "N1, N2, operator"

examples

scalc("20,30,*")

the result will be 600

scalc("50,20,+")

the result will be 70

scalc("50,20,-")

the result will be 30


scalc("60,20,/")

the result will be 30

use string functions to parse the first number, the second number, and the operator from the input string.

use the prior functions (add, subtract, divide and multiply ) to do the calculations.

Do not use any UI functions in the library such as print(), input(), and format.    Each function should have parameter(s) return at least one values to the caller.

Submission Instructions:

Make sure that you save your code in a text file in this format; 

W5_firstname_lastname.py

W5_firstname_lastname_Mylib.py

 

 

How should the functions look in W5_firstname_lastname.py?

How should the functions look in W5_firstname_lastname_Mylib.py?

 

BREAK-------------------------------

 

Is this correct for Wk5_firstname_lastname.py file?

"""

import W5_firstname_lastname_Mylib
W5_firstname_lastname_Mylib_calculate()
W5_firstname_lastname__Mylib.py
# Choose your lower range, higher range, first, and second numbers
def calculate():
   try:
       lowRange = float(input("Enter your Lower range --->"))
       highRange = float(input("Enter your Higher range --->"))
       number1 = float(input('Enter your First number between 10 and 20 --->'))
       number2 = float(input('Enter your Second number --->'))
       lr= lowRange
       hr= highRange
# This is an exception so that the user cannot enter anything other than a number. This allows numeric values only.
   except ValueError:
       print("You must enter a numeric value only")
# This is an exception so the user cannot divide by zero. This avoids hard coding.
# Print each math operation
   if number2 == 0:
       try:
           print("The Result of",number1,"+",number2,"=",add(number1, number2))
           print("The Result of",number1,"-",number2,"=",sub(number1, number2))
           print("The Result of",number1,"*",number2,"=",mult(number1, number2))
           print("The Result of",number1,"/",number2,"=",div(number1, number2))
           print(Mylib.scalc(operation))
       except ZeroDivisionError:
           print("You cannot Divide by zero, try again!!!")
       
   elif number1 >= lowRange and number2 <= highRange:
     
       print("The Result of",number1,"+",number2,"=",add(number1, number2))
       print("The Result of",number1,"-",number2,"=",sub(number1, number2))
       print("The Result of",number1,"*",number2,"=",mult(number1, number2))
       print("The Result of",number1,"/",number2,"=",div(number1, number2))
       print(Mylib.scalc(operation))
     
   else:
    print(isinrange(lr,hr,number1,number2))
   again()
# Checks the input ranges
def isinrange(lr, hr, number1, number2):
  if number1 <= lr:
      return 'The input values are outside the input ranges
              Please check the numbers and try again
              Thanks for using our calculator'
  elif number2 >= hr:
      return 'The input values are outside the input ranges
              Please check the numbers and try again
              Thanks for using our calculator'
#Addition
def add(x, y):
  answer = x+y
  return answer
#Subtraction
def sub (x, y):
  answer = x - y
  return answer
#Multiply
def mult (x, y):
  answer = x * y
  return answer
#Divide
def div (x, y):
  answer = x / y
  return answer
#Looping
def again():
  calc_again = input("Continue Looping? Y/N")
  if calc_again == 'y':
      calculate()
  elif calc_again == 'n':
      print ("Good Bye!")
  else:
      quit()

calculate()  

 

BREAK-----

 

Is this correct for the W5_firstname_lastname_Mylib.py file?

 

import W5_firstname_lastname_Mylib
W5_firstname_lastname_Mylib_calculate()
W5_firstname_lastname__Mylib.py


#Addition
def add(x, y):
   answer = x+y
   return answer
#Subtraction
def sub (x, y):
   answer = x - y
   return answer
#Multiply
def mult (x, y):
   answer = x * y
   return answer
#Divide
def div (x, y):
   answer = x / y
   return answer

def IsInRange(lr, hr, num1, num2):
   if num1 <= lr:
       return "The input values are outside the input ranges."
               "Please check the numbers and try again. Thank you for using my calculator."

   elif num2 >= hr:
       return "The input values are outisde the input ranges."
               "Please check the numbers and try again. Thank you for using my calculator."
#Scalc function
def scalc(p1):
   istring = p1.split(",")
   if istring[2] == "+":
       res = add(int(istring[0]), int(istring[1]))
   elif istring[2] == "-":
       res = sub(int(istring[0]), int(istring[1]))
   elif istring[2] == "*":
       res = mult(int(istring[0]), int(istring[1]))
   elif istring[2] == "/":
       res = div(int(istring[0]), int(istring[1]))
   return res

# This is the flower box and it should at the beginning of each assignment
# You must add comments to your code
# Program name : Wk5_firstname_lastname.py
# Student Name : Ymmas Azaba
# Course : ENTD220
# Instructor : My instructor
# Date : Any Day

# Description : This code shall...

# Copy Wrong : This is my work


Step by Step Solution

3.47 Rating (163 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Your code structure seems to be a bit mixed up Heres how the functions should look in the W5firstnam... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!