(SOLVED) calculation

Discipline: Mathematics

Type of Paper: Question-Answer

Academic Level: Undergrad. (yrs 3-4)

Paper Format: APA

Pages: 1 Words: 275

Question

1-Write statements to calculate sine of 45 degree.

2-Write statements to calculate 3 to the 5th power by calling an appropriate function defined in math module.

3-The random() function of the random module returns a floating point number [0.0, 1.0). Write a statement to generate a floating point number in the range of [0.0, 5.0) by using the random() function.

Expert Answer

Answer1 -
Code to calculate sine of 45 degrees -
import math
sine45 = math.sin(math.radians(45))
print(sine45)
  • Explanation for step 1
The sin() method of math module takes radian input,
Therefore we must convert 45 degrees to radian first using the radian() method.

Answer 2 -
Code to calculate 3 to the power of 5 -
import math
res = math.pow(3, 5)
print(res)


Answer 3 -
Code to calculate a random number between 0 and 5 -
import random
res = random.random() * 100 % 5
print(res)
  • Explanation for step 3
random() will return random number between 0 and 1.
First we multiply that by 100 to make it between 0 and 100.
Then we modulus it by 5 to get a number between 0 to 5.