Question

In: Computer Science

In this assignment, we are going to work with a combination of variables representing integers, floating...

  • In this assignment, we are going to work with a combination of variables representing integers, floating point numbers (decimals), and strings. Strings are also known as literals. We will create, save, and run a Python batch file (i.e., a Python script file) that will ask the user to enter the name of an investment, the amount invested, the annual return rate, and number of years, after which Python will compute the investment's final value at the end of that time period and spew out a full sentence incorporating the input and computed variables. This sentence will be put together by concatenating all the variables.

    A batch file is a sequence of commands that execute consecutively one after another when Python is asked to run/execute the file. Python batch files have the extension of .py and are best created in a text editor such as Notepad. Do NOT use Word or other word processors to create Python batch files -- they will result in syntax errors.

    Type the following commands into Notepad and save the whole thing as a Python batch file called investment.py --

    name=input("Investment name:")
    amount=int(input("Invested amount:"))
    rate=float(input("Annual return rate:"))
    years=float(input("No. of years:"))
    final_amount=amount*((1+rate)**years)
    print("An investment of","$",round(amount,2),"in",name,"today will grow to $",round(final_amount,2),"after",int(years),"years.")
    print("An investment of "+"$"+str(amount)+" in "+name+" today will grow to $"+str(round(final_amount,2))+" after "+str(int(years))+" years.")

    Now open a Command Prompt window and navigate to the directory in which you had saved investment.py, and then execute this Python script file as follows --

    C:\>py investment.py

    Experiment with various values of the input variables when prompted, and try to correlate the outputs with the last two concatenation/print commands in the script file.

    Also experiment with the commands in the script by removing the functions int, float, round, and str, and see what happens. show step by step answer using Jupyter.

Solutions

Expert Solution

name=input("Investment name:")
amount=int(input("Invested amount:"))
rate=float(input("Annual return rate:"))
years=float(input("No. of years:"))
final_amount=amount*((1+rate)**years)
print("An investment of","$",round(amount,2),"in",name,"today will grow to $",round(final_amount,2),"after",int(years),"years.")
print("An investment of "+"$"+str(amount)+" in "+name+" today will grow to $"+str(round(final_amount,2))+" after "+str(int(years))+" years.")


Related Solutions

Assignment Description In this assignment, we are going to analyze the changes in market demand and...
Assignment Description In this assignment, we are going to analyze the changes in market demand and market supply for a commodity (a good or a service). In addition, we will also analyze how the changes in demand and supply affected the market price and production of this commodity. To do so, we will are going to address the key factors (determinants) that have caused the shift in demand and/or the shift in supply. The goal here is to provide an...
Using the simple model for representing binary floating point numbers A floating-point number is 14 bits...
Using the simple model for representing binary floating point numbers A floating-point number is 14 bits in length. The exponent field is 5 bits. The significand field is 8 bits. The bias is 15 Represent -32.5010 in the simple model.
C programming Assignment 1. Read two integers into two variables, A and B. Print them on...
C programming Assignment 1. Read two integers into two variables, A and B. Print them on terminals. Write functions to Swap them (1) using a temporary variable and (2) without using a temporary variable. 2. Read 10 integers into an array. Sort the array. Then print the sorted array. 3. Read 16 integers into an array. Use merge sort algorithm to sort it. 4. Read 16 integers into an array. Sort it using merge sort algorithm. Then read a number...
Java Programming In this assignment we are going to create our own programming language, and process...
Java Programming In this assignment we are going to create our own programming language, and process it Java. programming language has 6 commands enter add subtract multiply divide return enter, add, subtract, multiply, divide all take 1 parameter (a double value). return takes no parameters.
Write a function named “compileStats” that has 4 parameters: a vector of integers, an integer representing...
Write a function named “compileStats” that has 4 parameters: a vector of integers, an integer representing the smallest value contained in the vector, an integer representing the largest value contained in the vector, and a double that represents the average of the values in the vector. The compileStats function will not “return” a value, it will set the Pass By Reference parameters to the correct values (smallest, largest, and average). Use the following main function in driver1b.cpp as a starting...
/******************************************************************************* * * Welcome to Assignment 1! In this assignment, you're going to be practicing lots...
/******************************************************************************* * * Welcome to Assignment 1! In this assignment, you're going to be practicing lots * of new JavaScript programming techniques. You'll see comments like this one: * * @param {String} name - the name to greet in the message * * These are specially formatted comments that define parameters to functions, * and tell use the type {String} or {Number}, and also the parameter's name. * Finally, we also explain a bit about how the parameter is used,...
write a function mean_value that accepts up to four integers and returns their possibly floating point...
write a function mean_value that accepts up to four integers and returns their possibly floating point mean_value. the function should be able to work with any number of inputs from one to four. ( it just returns the input if there is only one)
In this assignment you are going to use the menu you created in Assignment 1 to...
In this assignment you are going to use the menu you created in Assignment 1 to test both your Double and Integer classes. You should add functionality to the menu to allow you test the add, sub, mul, div functions for instances of both classes You are going to have make a modification to your menu class. Currently it uses an array to hold a fixed amount of menu items. While this may be OK for most applications we want...
Ex 3. Consider the following definitions: Definition: Let a and b be integers. A linear combination...
Ex 3. Consider the following definitions: Definition: Let a and b be integers. A linear combination of a and b is an expression of the form ax + by, where x and y are also integers. Note that a linear combination of a and b is also an integer. Definition: Given two integers a and b we say that a divides b, and we write a|b, if there exists an integer k such that b = ka. Moreover, we write...
Given the following 32-bit binary sequences representing single precision IEEE 754 floating point numbers: a =...
Given the following 32-bit binary sequences representing single precision IEEE 754 floating point numbers: a = 0100 0000 1101 1000 0000 0000 0000 0000 b = 1011 1110 1110 0000 0000 0000 0000 0000 Perform the following arithmetic and show the results in both normalized binary format and IEEE 754 single-precision format. Show your steps. a)     a + b b)     a × b
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT