Question

In: Computer Science

Module and Import For these 3 problems, -You are writing a function to calculate a formula...

Module and Import

For these 3 problems,

-You are writing a function to calculate a formula in the module.

-You are going to import the modules to the main.

-Write 3 more functions in the main

-Don't do any formula calculation in the main just use module functions and return your result.

-Call each main function twice to test the provided values.

1. Meter to Feet and Inches

One meter equals 39.37 inches and 1 foot equals 12 inches.

Write a function m_2_ft_inch (m) under the module meter_feet.py.

Import it to the main and another function named meter_to_feet_n_inch (meter) in the main. Call your function twice to test these 2 values.

i) 78 meter

ii) 245 meter

Hint: Use the remainder to solve this problem

Note: The result must be in feet and inches, suppose if it is 1.73 meters, your program should be able to print, 5 feet 8 inches

2. Kinetic Energy

Kinetic Energy equals 0.5 times mass (m) times square of velocity (v)

Write a function k_energy(m, v) under module KE.py. Import it to the main then write a function named kine_energy that accepts two arguments of mass and velocity.

Call your function twice to test the following parameters.

i) Object_A: mass = 230 kg, velocity = 12 m/sec

ii) Object_B: mass = 330 Kg, velocity = 11 m/sec

3. Future Value Calculation

Suppose you have a certain type of saving account that earns compound interest in your deposit. You can calculate your amount with formula,

F = P . (1 + i) ^ t

where,

F = Future value of the account after a certain time period

P = current balance of your account

i = annual interest rate, percent must be divided by 100 in calculations

t = number of years

Write a function my_future_value (p, i, t) under module future_value.py. Import the module to the main. In main write a function calculate_future_value (PV, interest, time). Call this function twice to calculate the future value with arguments for present value, interest rate, and the number of months as below.

a) P = $25000, i = 14.37% and t = 10 years

b) P = $133000, i = 16.70% and t = 13 years

Solutions

Expert Solution

I have given you the codes for main function and other three functions with comments and I have given you the output screens with above testcases

Hope this helps

Codes-

Main function code-

#importing modules from other python files
import meter_feet 
import KE
import future_value
from meter_feet import *
from KE import *
from future_value import *


#function to convert meters to feet and inches
def meter_to_feet_n_inch(m):
    result=m_2_ft_inch(m)
    return result

#function to calculate kinetic energy     
def kine_energy(m,v):
    result=k_energy(m,v)
    return result

#function to calculate future value    
def calculate_future_value(PV,interest,time):
    result=my_future_value(PV,interest,time)
    return result
    


#this is our main function  
if __name__ == "__main__":
    print("Convert meters to feet and inches")
    print("Meter to feet and inches for two testcases are")
    #calling and printing the result for the function anmes meter to feet and iches convertion 
    print(meter_to_feet_n_inch(78))
    print(meter_to_feet_n_inch(245))
    print("\n")
    
    print("Calculation of kinetic energy")
    print("Kinetic energy for two testcase Objects are ")
    #calling and printing the result for the function named kinetic energy 
    print(str(kine_energy(230,12))+"Joules")
    print(str(kine_energy(330,11))+"Joules")
    print("\n")
    
    print("Future Value calculation")
    #calling and printing the result for the function named calculation of future value
    print("Future value calculation of two testcases are")
    print("$"+str(calculate_future_value(25000,14.37,10)))
    print("$"+str(calculate_future_value(133000,16.70,13)))
    
#Note for printing we converted to string to concact numerical values and i hope you know the formulas for 
#the above stated problems
#and i have given you the other python module files functions
    
    

Meters to feet and inches function code-

import math

#function for convertion of meters to feet and inches 
def m_2_ft_inch(m):
    mynewlength = 100*m/2.54 + 0/2.54 
    mynewfeet = math.floor(mynewlength/12)
    mynewinch =mynewlength-12*mynewfeet
    z=str(mynewfeet)+"feet "+str(math.floor(mynewinch))+"inches "
    return z

Kinetic energy conversion function code-

#function to caluate kinetic energy 
def k_energy(m,v):
    kineticenergy=0.5*m*(v)**2
    return kineticenergy

Future value calculation function code-

#function to calculate future value 
def my_future_value(p,i,t):
    futurevalue=p*(1+i/100)**t
    return futurevalue
    

Outputscreens and codes Images-

I hope these will help you.


Related Solutions

Programming language is in python 3 For this project, you will import the json module. Write...
Programming language is in python 3 For this project, you will import the json module. Write a class named NobelData that reads a JSON file containing data on Nobel Prizes and allows the user to search that data. It just needs to read a local JSON file - it doesn't need to access the internet. Specifically, your class should have an init method that reads the file, and it should have a method named search_nobel that takes as parameters a...
Programming language is python 3 For this project, you will import the json module. Write a...
Programming language is python 3 For this project, you will import the json module. Write a class named NeighborhoodPets that has methods for adding a pet, deleting a pet, searching for the owner of a pet, saving data to a JSON file, loading data from a JSON file, and getting a set of all pet species. It will only be loading JSON files that it has previously created, so the internal organization of the data is up to you. The...
you will be assessed on the use of BINOM.DIST function, and creating formula to calculate the...
you will be assessed on the use of BINOM.DIST function, and creating formula to calculate the expected value of a binomial distribution. You will also be asked to interpret a probability value. Multiple Choice Test Chris is sitting a multiple choice test in statistics. The test consists of 9 items and each item has 5 options. After the test, Chris told you he didn’t study for the test at all and guessed all answers. a) If Chris guessed each and...
How do you calculate Payback Period on Excel by using FAME function? What is the formula?
How do you calculate Payback Period on Excel by using FAME function? What is the formula?
Suppose ?(?, ?) = ?3? a) (3 pts) Write down the formula and calculate the marginal...
Suppose ?(?, ?) = ?3? a) (3 pts) Write down the formula and calculate the marginal rate of substitution (MRS) of X for Y. b) (1 pts) Denote the price for good X is ? , the price for good Y is ? , and income is I.?? Write down the budget constraint. c) (5 pts) Derive the individual demand for good X and good Y as a function of prices and income. (hint: solve the utility maximization problem) d)...
a. Show the formula you use to solve the problems, and the corresponding numbers in the...
a. Show the formula you use to solve the problems, and the corresponding numbers in the formula. Show all the steps. b. Show all the inputs and outputs. JetHair’searnings are $6 per share. The firm’s ROE is 50%and its plowback ratio is 40%. a. What is JetHair’sdividend for next year ? b. What is the current stock price if its required rate of return is 35%?
import java.util.LinkedList; import java.util.Queue; import java.time.*; public class CheckOutLine { /** This is the main function...
import java.util.LinkedList; import java.util.Queue; import java.time.*; public class CheckOutLine { /** This is the main function for the program */ public static void main() { System.out.println("\n\tBegin CheckOutLine Demo\n"); System.out.println("\nCreating a Queue called \"register\" based on a LinkedList"); Queue<Customer> register = new LinkedList<Customer>();    System.out.println("\nAdding Customers to the Register queue"); // 1. TO DO: add five or more customers to the register line (5 Pts) // format: register.add(new Customer(name, checkout time));                System.out.printf("Register line has %d customers\n",...
PYTHON Suppose you need to import a single class named GeneTools from a module named bioinformatics,...
PYTHON Suppose you need to import a single class named GeneTools from a module named bioinformatics, in Python. Which of the following represents the correct use of an import statement? import GeneTools from bioinformatics from bioinformatics import GeneTools from bioinformatics import * import GeneTools
Each question will be labeled as a calculator or formula question. For calculator problems , you...
Each question will be labeled as a calculator or formula question. For calculator problems , you are to label and input all the variables of interest: N, I/Y, PV, PMT, FV (and Begin mode if you switch). the unknown variable should be indicated by a ? symbol. Once solved, rewrite the variable identifier with the correct answer. For the formula problems, set up the problem and solve. Be sure to show each step for credit. Answer each question in BB...
import java.util.LinkedList; import java.util.ListIterator; public class ProjectList { /** This is the main function for the...
import java.util.LinkedList; import java.util.ListIterator; public class ProjectList { /** This is the main function for the program */ public static void main() { System.out.println("\n\tBegin ProjectList demo program");    // 1. TO DO: Describe your project (1 Pt) System.out.println("Project: . . . . . . \n"); System.out.println("Create a LinkedList to store the tasks"); // 2. TO DO: Declare a LinkedList of String objects called "tasks" (1 Pt)       System.out.println("Add initial tasks into the list"); // 3. TO DO: Add initial...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT