In: Computer Science
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
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.