CPAN112 – Fundamentals of Numeric Computing – Assignment 03

CPAN 112 | Assignment 3

Program & Assignment

Write a program to calculate simple interest given Principal, Rate, Years, Months

Part – A

Define a function to get the total time in years

1. Ask the user to enter the value for year, months and days using the input()
2. Define a function using a key word “def” name it get_time (year, months, days)
Your output should look like :
 Enter year:2 Enter months:6 Enter the days:73 Total time in years is 2.7 years

Part B

Find the simple interest and must use the function created in the part I

1. Get the value of principal and rate from the user
2. Define a method with the key word ‘def’ and name it Simple_interest ()
Add codes to find simple interest
3. Call the methods to print the simple interest by calling the function from the part A
You final output should like
 Enter year:2 Enter months:6 Enter the days:73 principal:1000 rate(in %) :5 Total time in years is 2.7 years Total interest earned is \$ 135.0

Solutions:

Note: Format it yourself.

• PART A:
•  year=int(input(“Enter Year: “)) months=int(input(“Enter Months: “)) days=int(input(“Enter Days: “)) totaltime=”null” def get_time(year,months,days): totaltime=year + (months/12) + (days/360) print(“Total time in years is”, round(totaltime,1), “years”) return (round(totaltime,1)) get_time(year,months,days)
• PART B:
•  # creating variables year=int(input(“Enter Year: “)) months=int(input(“Enter Months: “)) days=int(input(“Enter Days: “)) totaltime=”null” # Function for calculating Time in Years def get_time(year,months,days): totaltime=year + (months/12) + (days/360) return (round(totaltime,1)) principle=float(input(“Enter Principle: “)) rate=float(input(“Enter Rate (in %): “)) # function for calculating Total Interest def Simple_interest(): Simple_interest = principle * (rate/100) * get_time(year,months,days) return (round(Simple_interest,1)) # function for displaying data def display(): print(“Total time in years is”, get_time(year,months,days), “years”) print(“Total interest earned is \$”, Simple_interest()) # calling display method display()