Programming language: PYTHON
Prompt: You will be creating a program to show final investment
amounts from a principal using simple or compound interest. First,
get a principal amount from the user. Next, ask the user if simple
or compound interest should be used. If the user types in anything
other than these options, ask again until a correct option is
chosen. Ask the user to type in the interest rate as a percentage
from 0 to 100%. Finally, ask the user for the number of years of
this investment. If simple interest is chosen: For each year, show
the user the year number and total amount of interest earned to
date. At the end, show the user the principal, the length of the
investment, the type of interest and at what percentage, and the
total final amount (i.e., principal plus total interest). If
compound interest is chosen: For each year, show the user the year
number and new principal. At the end, show the user the original
principal, the length of the investment, the type of interest and
at what percentage, and the final principal. The program only needs
to run once per execution.
Key concepts and resources from class :
• While
• External resources and prior knowledge
Assumptions, checks, or procedures:
1. The user should be able to type “s” (lowercase, no quotes) for simple interest and “c” (lower case, no quotes) for compound interest. Anything other than “s” or “c” should be considered an invalid choice. Please see samples below.
2. The interest rate as a percentage (when the user types it in) must be a number between 0.0 and 100.0. For example, an interest rate of 4.5% would be entered as 4.5.
3. You will not be using any econ or finance formulas to calculate simple or compound interest. Instead, you will be doing the calculations “manually”.
4. You can assume that time is finite (the number of years entered by the user), the interest rate does not change over time, and interest is calculated once per year. You can consider any total amounts you show to be “end of year” amounts.
5. Decimal values are allowed. Round decimals in outputs to the nearest hundredth (i.e., same as you would see at a bank).
6. You will need to add dollar and percent signs to your output.
7. You can assume that inputs for principal, interest rate, and year will be valid. Inputs for year will not contain decimals. How to break down this prompt I’m going to heavily paraphrase your econ and finance classes (and we can make use of some assumptions) in describing the types of interest. Simple interest is calculated only on the principal and then summed yearly per the prompt. Compound interest is calculated on the new principal each year. Once you understand those differences, it’s just a matter of using while and other concepts to do that in code.
This is the code i have so far...this is the error i am getting : "Traceback (most recent call last): File "main.py", line 18, in while (i <= years): Type error: '<' not supported between instances of 'str'
principal = input("enter the principal amount:\t")
s = input("1. s for simple interest\n 2. c for compound interest\n enter your choice:\t")
while(s!='s' and s!='c'):
s = raw_input("1. s for simple interest\n2. c for compound interest\nenter your choice:\t")
if(s=='s'):
years = input("enter number of years:\t")
rateofinterest = input("enter rate of interest:\t")
i = 1
while(i<=years):
interest = (principal*i*rateofinterest)/100
amount = interest + principal
print("at the end of {} year interest:\t{} interest type: simple interest amount:\t{}".format(i,interest,amount))
i = i + 1
if(s=='c'):
years = input("enter number of years:\t")
rateofinterest = input("enter rate of interest:\t")
i = 1 while(i <= years):
interest = (principal*i*rateofinterest)/100
amount = interest + principal
print("at the end of {} year interest:\t{} interest type: compound interest amount:\t{}".format(i,interest,amount))
i = i + 1
principal = principal + interest
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
The main error in your code was the way you were trying to read values. The input() method returns a string value, not a numeric type. So principal=input(….) will read the principal value as a string and not floating point. If you need to read as float value, you should use float(input()) instead of input(), the same applies for int(). There were many other errors too. Fixed everything
#code
# the input() returns a string, not a numeric type
#if you need to input a floating point value, you should use
float(input())
#if you need to input a integer value, you should use
int(input())
#getting principal as a float value
principal = float(input("enter the principal
amount:\t"))
#getting choice as string
s = input("1. s for simple
interest\n2. c for compound
interest\nenter your
choice:\t")
#loops until a valid choice is made
while(s!='s' and
s!='c'):
s = input("1. s for simple
interest\n2. c for compound
interest\nenter your
choice:\t")
if(s=='s'):
#getting years as int and rate of interest
as float
years = int(input("enter number of
years:\t"))
rateofinterest = float(input("enter rate
of interest:\t"))
i = 1
while(i<=years):
interest =
(principal*i*rateofinterest)/100
amount = interest +
principal
#displaying year and
interest earned. here {:.2f} will round the
#decimal values into 2
decimal places and then display
print("at
the end of {} year interest
earned:\t${:.2f}".format(i,interest))
i = i + 1
#displaying principal, length, type ,
interest rate and final amount
print('principal: ${:.2f}, length
of investment: {} years, type: simple
interest'.format(principal,years),end='
')
print('interest rate: {:.2f}%, total
final amount:
${:.2f}'.format(rateofinterest,amount))
if(s=='c'):
years = float(input("enter number of
years:\t"))
rateofinterest = float(input("enter rate
of interest:\t"))
#finding starting principal
current_principal=principal
#finding the rate in which each time the
interest is compounded in a year
compound_interest_rate=(rateofinterest/12)/100
i = 1
while(i <= years):
n=1
#loops for 12 times
(months in a year)
while n<=12:
#finding interest
interest = current_principal * compound_interest_rate
#updating principal
current_principal
= current_principal + interest
n+=1
#displaying
principal at the end of year
print("at
the end of {} year principal
amount:\t${:.2f}".format(i,current_principal))
i = i + 1
#displaying original principal, duration,
interest rate and final principal
print('original principal: ${:.2f},
length of investment: {} years, type: compound
interest'.format(principal, years), end='
')
print('interest rate: {:.2f}%, total
principal amount: ${:.2f}'.format(rateofinterest,
current_principal))
#output
enter the principal amount: 125000
1. s for simple interest
2. c for compound interest
enter your choice: c
enter number of years: 5
enter rate of interest: 7.25
at the end of 1 year principal amount: $134369.79
at the end of 2 year principal amount: $144441.92
at the end of 3 year principal amount: $155269.04
at the end of 4 year principal amount: $166907.74
at the end of 5 year principal amount: $179418.86
original principal: $125000.00, length of investment: 5.0 years, type: compound interest interest rate: 7.25%, total principal amount: $179418.86
Programming language: PYTHON Prompt: You will be creating a program to show final investment amounts from...
USE PYTHON PROGRAMMING LANGUAGE. Compound Interest A high school economics teacher wants to demonstrate the power of compound interest to her students. She would like you to write a program so that students can input their principal amount and the interest rate they will receive and show them how their investment will grow over time. The formula to calculate the total income of an investment (compounded annually) over time is: amount = P (1 + I)<sup>Y</sup> Where: P is the...
Write a program in Python that computes the interest accrued on an account. You can modify the “futval.py” program given in Chapter 2 to accomplish it. Your program should use a counted loop rather than a formula. It should prompt the user to enter the principal amount, the yearly interest rate as a decimal number, the number of compounding periods in a year, and the duration. It should display the principal value at the end of the duration. To compute...
Write an application that calculates the amount of money earned on an investment. Prompt the user to enter an investment amount, the number of years for the investment, and the interest rate. Display an error message if the user enters 0 for any of these values; otherwise, display the total amount (balance) for each year of the investment. Save the file as Investment.java. Java Program Specific instructions: Program must use 4 methods to accomplish the following: Prompt for and return...
This C++ Program should be written in visual studio 2017 You are to write a program that can do two things: it will help users see how long it will take to achieve a certain investment goal given an annual investment amount and an annual rate of return; also, it will help them see how long it will take to pay off a loan given a principal amount, an annual payment amount and an annual interest rate. When the user...
solution:
new file, invest.cpp 2. Prompt and read in the initial investment (type integer). 3. Prompt and read in the interest rate (type integer). 4. Prompt and read in the number of years (type double). 5. Compute the final value of the investment as: x*(1 + (R/100))' where x is the initial investment, R is the interest rate, and Y is the number of years. Use the C++ function pow to compute (1 + (R/100))'. Note that you will compute...
14.Compound Interest hank account pays compound interest, it pays interest not only on the principal amount that was deposited into the account, but also on the interest that has accumulated over time. Suppose you want to deposit some money into a savings account, and let the account earn compound interest for a certain number of years. The formula for calculating the balance of the account afer a specified namber of years is The terms in the formula are A is...
Write a program that prints the accumulated value of an initial investment invested at a specified annual interest and compounded annually for a specified number of years. Annual compounding means that the entire annual interest is added at the end of a year to the invested amount. The new accumulated amount then earns interest, and so forth. If the accumulated amount at the start of a year is acc_amount, then at the end of one year the accumulated amount is:...
using this code to complete. it python 3.#Display Program
Purpose
print("The program will show how much money you will make
working a job that gives a inputted percentage increase each
year")
#Declaration and Initialization of Variables
userName = "" #Variable to hold user's name
currentYear = 0 #Variable to hold current year input
birthYear = 0 #Variable to hold birth year input
startingSalary = 0 #Variable to hold starting salary
input
retirementAge = 0 #Variable to hold retirement age input...
in python language.
3. Calculates the final amount (A). The program uses four inputs: P, n,r, and t. Hint: nt 1 = P(1+3) Where • P = principal amount (initial investment) . r= annual nominal interest rate (as a decimal) • n = number of times the interest is compounded per year . t = number of years
C Programming For this task, you will have to write a program that will prompt the user for a number N. Then, you will have to prompt the user for N numbers, and print then print the sum of the numbers. For this task, you have to create and use a function with the following signature: int sum(int* arr, int n); Your code should look something like this (you can start with this as a template: int sum(int* arr, int...