In: Computer Science
code in python
I want to make a function that adds all the multipliers together. The code is posted below and please look at wanted output section to see what I want the code to output. The last line of the code is the only addition I need. Thanks.
Code:
initial=int(input("Initial value :
")) #taking inputs
multiplier=float(input("Multiplier : "))
compound=int(input("No of compounds : "))
print("Your values are:")
mult=initial
#initalizing to find answer
for i in
range(0,compound):
#multiplying by multiplier
print(round(mult,1))
mult=mult*multiplier
Code Output:
Initial Value: 10
Multiplier: 1.4
Number of compounds: 10
Your Values are: 10 , 14, 19.6 , 27.4, 38.4, 53.8, 75.3, 105.4, 147.6, 206.6
Total value Amount: 24 , 33.6, 47.04, 65.856, 92.1984, 129.07776, 180.708864, 252.9924096
Source Code:
initial=int(input("Initial value : ")) #taking
inputs
multiplier=float(input("Multiplier : "))
def printAmount(lst):
for i in range(1,len(lst)):
val=lst[i-1]+lst[i] # the val is the sum of previous and current
element
if(val<lst[len(lst)-1]): # we have to print value only if value
< last value of list
print(round(val,i-1))
compound=int(input("No of compounds : "))
print("Your values are:")
lst=[] # create a list for storing mult values
mult=initial #initalizing to find answer
lst.append(mult)
for i in range(0,compound): #multiplying by multiplier
print(round(mult,1))
mult=mult*multiplier
lst.append(mult)
print("Total value Amount:")
printAmount(lst)
Sample input and output: