Question

In: Computer Science

code in python I want to make a function that adds all the multipliers together. The...

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

Solutions

Expert Solution

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:


Related Solutions

Write a function in Python that adds two Binary Trees together. The inputs of your function...
Write a function in Python that adds two Binary Trees together. The inputs of your function should be two binary trees (or their roots, depending on how you plan on coding this), and the output will be one Binary Tree that is the sum of the two inputted. To add Binary Trees together: Add the values of nodes with the same position in both trees together, this will be the value assigned to the node of the same position in...
In python i want to create a function. The function will take in two linked lists...
In python i want to create a function. The function will take in two linked lists as the parameters. If one is shorter than the other then the shorter will be the length. I want to take the values from both linked lists and turn them into tuples. I then want these tuples to be put into a new linked list. I want to return that linked list. I want to do this using recursion and no helper functions or...
In python I have a linked list. I want to create one function that takes in...
In python I have a linked list. I want to create one function that takes in one parameter, head. In the function, cur = head and next_cur = head.next. I want to return head and next_cur, except at the end of the function they will return alternating values from head. For example, if the these are the values in the linked list: 2, 3, 5, 7, 11 after the function head should return: 2, 5, 11 and next_cur should return:...
Python I want to name my hero and my alien in my code how do I...
Python I want to name my hero and my alien in my code how do I do that: Keep in mind I don't want to change my code except to give the hero and alien a name import random class Hero:     def __init__(self,ammo,health):         self.ammo=ammo         self.health=health     def blast(self):         print("The Hero blasts an Alien!")         if self.ammo>0:             self.ammo-=1             return True         else:             print("Oh no! Hero is out of ammo.")             return False     def...
Code in python Hello I want a program to read only the price of each line...
Code in python Hello I want a program to read only the price of each line in a txt file in python. The price is present right after the 2nd comma within the txt file. The output that I want is also printed at the bottom. Inside the txt file: 2019-08-01 00:08:39,BTC/USD,10128.08 2019-08-01 00:08:21,BTC/USD,10117.54 2019-08-01 00:08:20,BTC/USD,10120.51 2019-08-01 00:08:19,BTC/USD,10118.13 2019-08-01 00:08:18,BTC/USD,10120.74 Python file output: Price 1: 10128.08 Price 2: 10117.54 Price 3: 10120.51 Price 4: 10118.13 Price 5: 10120.74
In python I want to create a function that takes in a linked list. Using recursion...
In python I want to create a function that takes in a linked list. Using recursion only, I want to check if the linked list is sorted. How do i do this?
Python 3 Fix the code so i can make the window larger or smaller and the...
Python 3 Fix the code so i can make the window larger or smaller and the fields adjusts everytime according to the window size import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook window = tk.Tk() window.title("daily logs") # window.resizable(0,0) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20) tk.Label(window, text="sold by").grid(row=3, sticky="W", pady=20, padx=20) tk.Label(window, text="Failed date").grid(row=4, sticky="W", pady=20, padx=20) # entries barcode = tk.Entry(window)...
can you please create the code program in PYTHON for me. i want to create array...
can you please create the code program in PYTHON for me. i want to create array matrix Nx1 (N is multiple of 4 and start from 16), and matrix has the value of elements like this: if N = 16, matrix is [ 4 4 4 4 -4 -4 -4 -4 4 4 4 4 -4 -4 -4 -4] if N = 64, matrix is [8 8 8 8 8 8 8 8 -8 -8 -8 -8 -8 -8 -8...
In python I want to create a singular function that takes two parameters 'head; and 'skip'....
In python I want to create a singular function that takes two parameters 'head; and 'skip'. Head is a linked list. Skip is a non negative value. If skip is zero it should return the linked list unchanged. The skip amount determines the amount to skip over. I want to change the linked list accordingly and then return the linked list with the modifications, not a list. If you have a linked list 11 -> 12 -> 18 -> 20...
In python I want to create a singular function that takes two parameters 'head; and 'skip'....
In python I want to create a singular function that takes two parameters 'head; and 'skip'. Head is a linked list. Skip is a non negative value. If skip is zero it should return head unchanged. The skip amount determines the amount to skip over. I want to change the linked list accordingly. If you have a linked list 11 -> 12 -> 18 -> 20 -> 24 -> 32 -> 38 -> 44 and skip =2, then you should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT