Question 1
Write complete full Python programs for each part, to perform the following tasks
Write a Python program to perform the following
Prompt a user to enter the following pieces of information:
the initial value of an investment, i
the expected final value of an investment, f and
the number of years to accumulate the initial value to reach the final value, n.
Compute the annual compound interest rate in percent, r using the formula:
π π
π = 100( √
π
− 1)
Prompt the user to enter the number of years, y, he wishes to
Compute the final amount based on the computed compound interest rate, using the formula:
π
π = π(1 +
100
)π¦
Display the final amount based on the computed compound interest rate. Numbers should be displayed with 2 decimal
An example run with user input in green is shown here:
Enter the initial bank balance: 100 Enter the final bank balance: 120
Enter the number of years to reach final balance: 5
How many years to deposit given average interest rate is 3.71%: 10 After 10 years, you will have $144.00
Make a copy of your Python program in part a) for this part as you need to submit the program for part a).
Add a check that if the final amount is less than the initial amount, prompt whether the user wishes to swap the values of the initial amount with the final amount. If the user does not wish to swap, proceed as usual. Allow the user to respond in uppercase or lowercase. You may assume that the user enters either an n or a y as the first non-whitespace character.
Two sample runs with user input in green are shown here: Run 1:
Enter the initial bank balance: 200 Enter the final bank balance: 100
Initial value: $200 is more than final value: $100 Do you wish to swap the values? (y/n): n
Getting negative returns
Enter the number of years to reach final balance: 5
How many years to deposit given average interest rate is -12.94%: 10
After 10 years, you will have $50.00
Run 2:
Enter the initial bank balance: 200 Enter the final bank balance: 100
Initial value: $200 is more than final value: $100 Do you wish to swap the values? (y/n): yes
The values have been swapped
Enter the number of years to reach final balance: 5
How many years to deposit given average interest rate is 14.87%: 10 After 10 years, you will have $400.00
Make a copy of your Python program in part b) for this part as you need to submit the program for part b).
Add a check to ensure that the user enters either an n or a y as the first non- whitespace character when prompted whether he wishes to swap. You should repeatedly prompt the user until he enters a valid value.
An example run with user input in green is shown here:
Enter the initial bank balance: 200 Enter the final bank balance: 100
Initial value: $200 is more than final value: $100 Do you wish to swap the values? (y/n):
Do you wish to swap the values? (y/n): an Do you wish to swap the values? (y/n): a
Do you wish to swap the values? (y/n): na OK. Getting negative returns
Enter the number of years to reach final balance: 5
How many years to deposit given average interest rate is -12.94%: 10
After 10 years, you will have $50.00
Make a copy of your Python program in part c) for this part as you need to submit the program for part c).
Modify the code segment for part a) so that the program display the yearly value of the investment amount from the initial amount to the final amount, instead of displaying only the final amount.
An example run with user input in green is shown here:
Enter the initial bank balance: 200 Enter the final bank balance: 100
Initial value: $200 is more than final value: $100 Do you wish to swap the values? (y/n): nah
Getting negative returns
Enter the number of years to reach final balance: 5
How many years to deposit given average interest rate is -12.94%: 10
Year Amount($) 1 174.11
2 151.57
3 131.95
4 114.87
5 100.00
6 87.06
7 75.79
8 65.98
9 57.43
10 50.00
Make a copy of your Python program in part d) for this part as you need to submit the program for part d).
Allow the user to repeatedly enter new initial and final values until he enters 0 for the initial amount. Perform the steps as usual for each pair of initial and final values. You must modularise your program for this part by defining at least 2 functions.
An example run with user input in green is shown here:
Enter the initial bank balance: 100 Enter the final bank balance: 200
Enter the number of years to reach final balance: 2
How many years to deposit given average interest rate is 41.42%: 5
Year |
Amount($) |
1 |
141.42 |
2 |
200.00 |
3 |
282.84 |
4 |
400.00 |
5 |
565.69 |
Enter the initial bank balance: 500 Enter the final bank balance: 300
Initial value: $500 is more than final value: $300 Do you wish to swap the values? (y/n): n
Getting negative returns
Enter the number of years to reach final balance: 2
How many years to deposit given average interest rate is -22.54%: 5 Year Amount($)
1 387.30
2 300.00
3 232.38
4 180.00
5 139.43
Enter the initial bank balance: 0 Program end
Question 2
To enable collaborative learning through participation and engagement, you are encouraged to make postings in a discussion forum. You must NOT post Python code in the discussion forum.
The problem:
An expression is something that evaluates to a value, e.g., 3 + 4 evaluates to 7. As you learn to write Python programs, you will realise that writing syntactically correct expressions is a must for them to be evaluated by the Python interpreter. For example, 3 + / 4 is not a valid expression, and so, the Python interpreter cannot evaluate it.
In this question, you are to solve the problem of determining whether an expression is valid, and to evaluate it if it is so. Otherwise, you are to provide a helpful error message. In other words, you are to write a program to handle a small portion of what a Python interpreter needs to do when it gets an expression to evaluate.
Consider only simplified expressions as described here:
An expression may contain only these binary operators: +, -, /. // and *.
Parentheses, that is, ( and ), can be used to change the order of the evaluation of the
Operands are negative or positive numeric values (int or float).
Operands cannot be
The Python interpreter needs to tokenise the expression, however, you can simplify the tokenising process by assuming that the tokens (number, parentheses and operators) in the expression will be separated by whitespace. Thus, you will be able to get a next token by moving past whitespaces.
Examples of invalid expressions with explanation are given below:
Invalid expressions |
Explanation |
1 + 2 + a + 4 |
Operand must be a number, a is not a number |
( 1 + 3 ) ) |
Unbalanced parentheses |
( 1 + 3 ) * ( ( 2 ) |
Unbalanced parentheses |
33.3 + + 1 |
Operators require a left and right numeric operands |
( 33 ) ( 1 ) |
Operands must be separated by an operator |
) ( |
No preceding left parenthesis for the right parenthesis |
( ) |
No operand within the bracket |
Examples of valid expressions with explanation and the evaluated result are given below:
valid expressions |
Reasons |
Result of evaluation |
1.2 + -3 |
Operand operator operand |
-1.8 |
( ( 1 + 3 ) ) |
Balanced parentheses, operand operator operand |
4 |
( 1 + 3 ) * ( ( 2 ) ) |
Balanced parentheses, operand operator operand |
8 |
33.3 + -2 + 1 |
Operand operator operand |
32.3 |
( 33 ) / ( -1 ) |
Operand operator operand |
-33.0 |
( 33 ) // ( 1 ) |
Operand operator operand |
33 |
Before embarking on the program development, journal your learning journey by making postings for ALL items listed below (You must NOT POST ANY PYTHON CODE, and your posting should be clear, understandable and with SUFFICIENT elaboration):
at least TWO difficulties or questions you have about the problem
at least TWO difficulties or questions you have when attempting to solve the problem,
at least TWO suggestions, clarifications, observation or feedback to other students’ postings, accompanied with reasons
at least TWO conclusions of your research on the problem and how to solve it (Note that no Python code should be posted)
at least TWO important lessons you have through this
Demonstrate your understanding of modular program design, and develop the program that repeatedly read an expression and output only one of the following messages:
Unexpected right parenthesis between expr_left and )expr_right
There is 1 unclosed left parenthesis in expr
There are n unclosed left parentheses in expr
Invalid expression, expecting operator between expr_left and expr_right
Invalid expression, expecting operand between expr_left and expr_right
Invalid expression, expecting operand between expr_left and expr_right
but currentToken is a variable
result from evaluating the
You may use the function eval to evaluate an expression.
Note that expr_left refers to the portion of the expression without error and expr_right refers to start of where the error occurs in the expression. expr refers to the input expression, and currentToken refers to the current token being processed.
Your program should process the tokens in the input expressions without generating exceptions, and your program cannot use the try-except construct.
CS 340 Milestone One Guidelines and Rubric Overview: For this assignment, you will implement the fundamental operations of create, read, update,
Retail Transaction Programming Project Project Requirements: Develop a program to emulate a purchase transaction at a retail store. This
7COM1028 Secure Systems Programming Referral Coursework: Secure
Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip
CS 340 Final Project Guidelines and Rubric Overview The final project will encompass developing a web service using a software stack and impleme