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

In Python For this programming assignment, we are going to investigate how much "work" different sorting...
In Python For this programming assignment, we are going to investigate how much "work" different sorting routines do, based on the input size and order of the data. We will record the work done by writing output CSV (comma separated value) files and creating various plots using matplotlib. Note: for this assignment, do not use Jupyter Notebook to code your solution. Use standard .py files and save your output to .csv and .png files (see the program details below for...
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.
Assembly Line Assignment: This week you are going to design and balance an assembly line. We...
Assembly Line Assignment: This week you are going to design and balance an assembly line. We are going to take the simple task of making cupcakes, break the work up into stations, calculate cycle times for each station, balance the work load between stations, and calculate the efficiency of the operation. The steps for the assignment are below. 1)Design an assembly line to manufacture cupcakes from scratch. 2)Balance the assembly line. 3)Measure the efficiency. Assignment Format: The best way to...
/******************************************************************************* * * 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 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...
JAVA: Compute the average of a list of user-entered integers representing rolls of two dice. The...
JAVA: Compute the average of a list of user-entered integers representing rolls of two dice. The list ends when 0 is entered. Integers must be in the range 2 to 12 (inclusive); integers outside the range don't contribute to the average. Output the average, and the number of valid and invalid integers (excluding the ending 0). If only 0 is entered, output 0. The output may be a floating-point value. Ex: If the user enters 8 12 13 0, the...
The purpose of this lab is to manipulate an array of integers. The assignment is to...
The purpose of this lab is to manipulate an array of integers. The assignment is to write a program that: 1. Declares an array of integers of size equal to constant int SIZE = 10. 2. Implements the following methods:  A method that displays a menu. The menu should be displayed after each completed menu selection.  A method that prompts the user to initialize the array. The entire array does not need to be initialized. The user may...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT