00:01
Suppose you have a certain amount of money in a savings account that earns compound monthly interest and you want to calculate the amount that you will have after a specific number of months.
00:14
The formula is f equal p times 1 plus i raised to the t, where f is a feature value of the account after the specified time period, p is the present value of the account, i is a monthly interest rate.
00:33
T is the number of month.
00:37
So we want to write the program that takes the account's present value, monthly interest rate, and the number of months that the money will be left in the account as three inputs from the user.
00:51
The program should pass these three values to a function that returns the official value of the account after the specified number of month.
00:59
The program should print the accounts future value.
01:03
So we have a solution here.
01:07
So the first part is definition of the function, future value, and we are also important a module called sis system module, which we use to call the exit function.
01:28
We'll explain down here.
01:30
So the function, future value, have three inputs present value which is a float then monthly interest trade which is a float also we can give the interest in decimal numbers because we can find that normally there is 6 .5 % and so on and the number of months is an interview is the only entry that is an interview and as we can see see is a simple function because we return the application as a formula that is present value that's b in the formula here then i plus 1 plus i inside parenthesis so times one plus most interest rate divided by 100 in python this division here is a floating point division but in this case it is evident that it will be so because mostly interest rate is already an floating point number so the division is a floating point number but even if the two quantities are integers the slat the slash forward slash is a floating point division in python so we have one plus that mostly interest divided by 100 we divide by 100 because the monthly interest rate is supposed to be given in percentage and that expression inside parenthesis is raised to the number of months.
03:18
This double asteris in python is the power operator.
03:23
And we have applied then the formula here with the three inputs to the function, the return, the function is going to calculate and return the final result to the program that is called in this function.
03:43
So after the definition of the function, we have main program to test the function and have included try exit blocks for each of the three inputs.
03:56
You can get rid of them if you don't want to complicate the code.
04:05
But in this case if the user enters something that is not expected is going to give an error message and stop the program execution.
04:15
So for example the first input from the user is the account's present value which we store in a variable called apv and remember that python receives always a stream when we use the input function.
04:41
So the input function is going to put the message on screen, enter the accounts present value and then when the user enters a string and hit enter that string is return here to the main program and then we try to convert it into a floating point number you can see here i have used double quotes to or represent the string that is going to be put on screen because i wanted to use this single quote here and so i cannot use a single quote to to enclose the string.
05:21
So that's why i use double quotes...