Numbers Exercises#

Question-1#

In a single line of code, compute \(\sqrt{\sqrt{\sqrt{625}}}\) and round it to the nearest hundredth.

Question-2#

In at most two lines of code, compute \(\displaystyle |ln( 2^{sin(|-100|)})|\) and round it to the nearest hundredth.

Question-3#

Write a program that prompts the user for three numbers using three input functions. Assign the entered values to variables with the names x, y, and z.

  • Find \(\displaystyle f(x, y,z) = \frac{5xy}{2+x^2}+\frac{x+y+z}{y^4+x^2y^2}\)

  • Round this value to the nearest hundredth and print the result in the following format.

  • Sample Output:
    x: 1
    y: 2
    z: 3
    f(1,2,3)=3.63

Question-4#

Write a program that prompts the user to enter their height using two input() functions for the feet and inch parts separately.

  • Assign the entered values to variables named feet and inch.

  • Convert the given height into centimeters using the following conversion formulas: 1 foot = 12 inches and 1 inch = 2.54 cm

  • Sample Output:
    Enter the feet part of your height: 6
    Enter the inch part of your height: 4
    6 feet and 4 inches = 193.04 cm

Question-5#

Write a program that prompts the user for a 4-digit positive number. Swap the first two digits of the given number with the last two digits and print it.

  • Do not use string indexing that will be covered in the next chapter.

  • Example 1: If the given number is 1234, then print 3412.

    • Print format: 1234 —- swap—> 3412

  • Example 2: If the given number is 6789, then print 8967.

    • Print format: 6789 —- swap—> 8967

Question-6: Distance#

In a coordinate plane, each point is represented by its x and y components in the form of \((x,y)\).
The distance between two points \(P=(x_1,y_1)\) and \(Q=(x_2,y_2)\) is given by the following distance formula:

  • \(\displaystyle dist(P,Q) = \sqrt{(x_2-x_1)^2+(y_2-y_1)^2}\)

Write a program that prompts the user for the x and y components of a point using two input() functions and computes the distance between the given point and the point \((-5,6)\).

  • Round the distance to the nearest hundredth.

Sample Output:
Enter the x-component of the point: -2
Enter the y-component of the point: 10
The distance between (-5,6) and (-2.0,10.0) is 5.0

Question-7: Midpoint#

In a coordinate plane, each point is represented by its x and y components in the form of \((x,y)\).
The midpoint \((x_m, y_m)\) between two points \(P=(x_1,y_1)\) and \(Q=(x_2,y_2)\) is given by the following midpoint formula:

  • \(\displaystyle x_m = \frac{x_2+x_1}{2}, y_m = \frac{y_2+y_1}{2}\)

Write a program that prompts the user for the x and y components of a point using two input() functions, and computes the x and y components of the midpoint between the given point and the point \((-5,6)\)

Sample Output:
Enter the x-component of the point: 3
Enter the y-component of the point: 5
The midpoint between (-5,6) and (3.0,5.0) is (-1.0,5.5).

Question-8: Pythagorean#

The Pythagorean Theorem states that for a right triangle with sides \(a\), \(b\), and \(c\) where \(c\) is the hypotenuse: \(\displaystyle c = \sqrt{a^2+b^2}.\)

  • Write a program that prompts the user for the sides of a right triangle using two input() functions, and computes the length of the hypotenuse.

  • Round the hypotenuse to the nearest hundredth.

Sample Output:
Enter the length of the first side: 4
Enter the length of the second side: 8
The length of the hypotenuse: 8.94

Question-9: Degrees to Radians#

An angle in degrees is converted to radians using the following formula: \(\displaystyle R = \frac{\pi}{180} \cdot D\).

  • Write a program that prompts the user for an angle in degrees using an input() function, converts it to radians, and rounds it to the nearest hundredth.

  • Use the conversion formula provided above, and also the math.radians() function to compare the results.

Sample Output:
Enter the angle in degrees: 120
120.0 degrees is 2.09 using the formula.
120.0 degrees is 2.09 using the math.radians() functions.

Question-10: Law of Cosines#

The Law of Cosines states that for a triangle with sides \(a\), \(b\), and the angle \(\gamma\) between these two sides:

\(\displaystyle c = \sqrt{a^2+b^2-2ab \cdot \cos(\gamma)}\),

where \(c\) is the length of the third side of the triangle corresponding to the angle \(\gamma\).

  • Write a program that prompts the user for two sides of a triangle and the angle between them in degrees using three input() functions, and computes the length of the third side \(c\).

  • Round \(c\) to the nearest hundredth.

  • The math.cos() function takes the angle in radians. You need to convert the given angle in degrees to radians before using it.

Sample Output:
Enter the length of the first side : 6
Enter the length of the second side : 3
Enter the angle between these two sides in degrees: 70
The length of the third side: 5.72

Question-11#

Write a program that prompts the user for a number. Assign the entered value to variable with the name x.

  • Find \(\displaystyle f(x) = \frac{x^3-2x}{x+6}\)

  • Round this value to the nearest hundredth and print the result in the following format.

  • Sample Output:
    x: 10
    f(10)=61.25

Business Applications#

Question: Ordinary Annuity#

An ordinary annuity is an interest earning account where you make equal payments at the end of each compounding period.

The future value of an ordinary annuity is given by the following formula.

\(\displaystyle A = R \left( \frac{(1+\frac{r}{m})^{mt}-1}{\frac{r}{m}} \right)\)

where,

  • \(A\): Future value

  • \(R\): regular payment

  • \(r\): annual interest rate

  • \(m\): number of payments in a year

  • \(t\): number of years

If you deposit 200 dollars every month into an account earning 5.25% interest per year, compounded monthly, how much money will you have saved after 30 years? Round this value to the nearest hundredth.

Hint:

  • Use the variables \(R, r, m, t\) for the given values.

  • Calculate the value of the variable \(A\).

  • To avoid mistakes, you can calculate the numerator and denominator of \(A\) separately.

Question: Amortized Loan-1#

Amortization is paying off a loan by making equal payments.

The present value of an amortized loan is given by the following formula.

\(\displaystyle P = R \left( \frac{1-(1+\frac{r}{m})^{-mt}}{\frac{r}{m}} \right)\)

where,

  • \(P\): Present value

  • \(R\): regular payment

  • \(r\): annual interest rate

  • \(m\): number of payments in a year

  • \(t\): number of years

If you can make monthly payments of 350 dollars for 3 years at an annual interest rate of 9%, what is the present value of the loan you can take out? Round this value to the nearest hundredth.

Hint:

  • Use the variables \(R, r, m, t\) for the given values.

  • Calculate the value of the variable \(P\).

  • To avoid mistakes, you can calculate the numerator and denominator of right hand side separately.

Question: Amortized Loan-2#

If you take out an 80,000 dollars loan to buy a truck with an annual interest rate of 6%, to be paid off over 5 years, what is the monthly payment? Round this value to the nearest hundredth.

Hint:

  • Use the variables \(P, r, m, t\) for the given values.

  • Calculate the value of the variable \(R\).