In: Computer Science
(Write in PythonUse a for statement to print 10 random numbers between 25 and 35, inclusive.
(Write in Python)in python The Pythagorean Theorem tells us that the length of the hypotenuse of a right triangle is related to the lengths of the other two sides. Look through the math module and see if you can find a function that will compute this relationship for you. Once you find it, write a short program to try it out.
(Write in PythonSearch on the internet for a way to calculate an approximation for pi. There are many that use simple arithmetic. Write a program to compute the approximation and then print that value as well as the value of math.pi from the math module.
import random
start_number = 25 // Starts from the number 25
end_number = 35 // ends at the number 35
number_of_digits = 10 //10 random numbers should be printed
result = [] // declaration of a list
for j in range(number_of_digits):
result.append(random.randint(start_number,
end_number)) // appending random numbers inclusively to the
list
print(*result)
In math module we have a function to calculate hypotenuse that is hypot()
import math
side_a = int(input('Input the length of side a: ')) // Prompts
to enter the length of the two shorter sides
side_b = int(input('Input the length of side b: '))
hypotenuse = math.hypot(side_a,side_b) // calculating the
hypotenuse by using hypot() function
print('The length of side c is: ',hypotenuse )
Printing the value of pi from math module
import math
print(math.pi)
Leibniz formula for pi is as follows
π=4*∑k≥0((−1)^k)*(1/(2k+1))
a = int(input("Please enter a value for N:")) //N value can be
anything
sum=0
for i in range(1,a):
sum += (-1)**(i+1)*((1.0/(i+i+1))) // Using leibniz formula for
approximation of pi value
result = 4*(1-sum) // value of pi
print(result)