Starting from:

$29.99

CSC1001 Assignment 1 Solution



You should write your code for each question in a .py file (please name it using the question name, e.g. q1.py). Please pack all your .py files into a single .zip file, name it using your student ID (e.g. if your student ID is 123456, then the file should be named as 123456.zip), and then submit the .zip file via Blackboard.

Please also write a text file, which provide the details about your code. (Note that the report should be submitted as PDF) The report should be included in the .zip file as well. (An example of report has been released on Blackboard)





Question 1 (10% of this assignment): Suppose you want to deposit a certain amount of money into a savings account with a fixed annual interest rate. What amount do you need to deposit in order to have $5,000 in the account after three years? The initial deposit amount can be obtained using the following formula:
𝑓𝑖𝑛𝑎𝑙𝐴𝑐𝑐𝑜𝑢𝑛𝑡𝑉𝑎𝑙𝑢𝑒
𝑖𝑛𝑖𝑡𝑖𝑎𝑙𝐷𝑒𝑝𝑜𝑠𝑖𝑡𝐴𝑚𝑜𝑢𝑛𝑡 =
(1 + 𝑎𝑛𝑛𝑢𝑎𝑙𝐼𝑛𝑡𝑒𝑟𝑒𝑠𝑡𝑅𝑎𝑡𝑒)𝑛𝑢𝑚𝑏𝑒𝑟𝑂𝑓𝑌𝑒𝑎𝑟𝑠
Write a program that prompts the user to enter final account value, annual interest rate in percent, and the number of years, and displays the initial deposit amount. A sample run of your program:

Question 2 (15% of this assignment): Write a program that prompts the user to enter a positive integer and displays each of its digits one by one (one digit per line). Here is a sample run:


Question 3 (15% of this assignment): Write a program to allow a user to input a number m, and then use a while loop to find the smallest integer n such that n2 is greater than m. For example, if the user inputs m = 10, your program should output n = 4.


Question 4 (15% of this assignment): Write a program to allow a user to input a
number N, and print a table with N rows and 3 columns. In the mth row, your program should output three numbers: m, m+1, and mm+1. For example, when the user inputs N = 5, your program should output the following:

Your program should be robust enough to handle the possible improper inputs (e.g. the user inputs a negative N).


Question 5 (20% of this assignment): Write a program to allow a user to input an integer N, and print all the prime numbers which are smaller than N. For example, when the user inputs N = 10, your program should output


Your program should output at most 8 prime numbers in each line.
Your program should also be robust enough to handle the possible improper inputs (e.g. the user inputs a string; the user inputs a number less than 1). If you have any question about the definition of the prime number, PLEASE check it on Google.


Question 6 (25% of this assignment): Given a function f(x), and a real interval [a, b], the numerical integration of f(x) over interval [a, b] can be calculated as:

(1)

In equation (1), n represents the number of sub-intervals into which the interval [a, b] will be divided; and it controls the accuracy of numerical integration.
Write a program to allow the user to specify a trigonometric function f (f can only be sin, cos or tan), and input the interval end points a, b and number of sub-intervals n. Your program should then calculate the numerical integration of f over [a, b] using equation (1), and output the result.
Your program should be robust enough to handle possible improper inputs (e.g. the user inputs a floating point number as n; the user inputs a wrong function name).

Python has built-in trigonometric functions. To call them, use the following statement in your program to import them from the math package:


You can then invoke the trigonometric functions like the following examples:



For more details about the math package, please visit the following link:
https://docs.python.org/3/library/math.html#math.sin

More products