Question

In: Computer Science

(Write in PythonUse a for statement to print 10 random numbers between 25 and 35, inclusive....

(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.

Solutions

Expert Solution

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)


Related Solutions

Write a program that prints the count of all prime numbers between A and B (inclusive),...
Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = The 5 digit unique number you had picked at the beginning of the semester B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7,...
3. Write a script that generates two random numbers between -5 and 25, calculates their average,...
3. Write a script that generates two random numbers between -5 and 25, calculates their average, and if the average is greater than 10 then prints “High Average” else prints “Low Average”. You can use $RANDOM to generate the random numbers. 4. Write a script using the for-loop construct that counts the number of directories looping through the files in the directory name provided by the user on a prompt by the script.
Write a program to print random numbers and whether they were even or odd. Ask the...
Write a program to print random numbers and whether they were even or odd. Ask the user to enter a positive number to indicate how many random numbers to pull (verify number is positive). Zero is positive. Declare two variables and initialized to zero. int evens = 0, odds = 0; Use them to count how many evens and how many odds were pulled. Enter how many random numbers to pull : 3 41           odd 18467    odd 6334    even 1...
I am to write a code that uses two queues, and print the generated random numbers...
I am to write a code that uses two queues, and print the generated random numbers and content of both queues. I need to use the enqueue and dequeue functions in the code.  The instructions are below. Program should be in C Instructions: Generate n random numbers with values between 10 - 100. Note: n>9 if u write a function (for example, called generateRand) to do this - what is the data or input we have to give it? Create a...
Write a Python program which generates a random number between 0 and 24 inclusive and that...
Write a Python program which generates a random number between 0 and 24 inclusive and that print out: • the double of the random number if the random number is greater than 12, • the triple of the random number if it is equal to 12 • and the quadruple of the random number if it is less than 12
Write an algorithm that print all numbers that are divisible by 3 between 1000 and 2000
Write an algorithm that print all numbers that are divisible by 3 between 1000 and 2000
Instructions:  Code a for statement that increments from 1 through 10, but print only the even numbers...
Instructions:  Code a for statement that increments from 1 through 10, but print only the even numbers using a fall-thru switch. You can catch the odd numbers using the option in the switch that handles everything else. Name your program ForFallThruSwitch.java. Use Java Style Guide in line advancing and spacing. --------------------OUTPUT RESULTS-------------------- Not printing odd numbers! 2 is an even number. Not printing odd numbers! 4 is an even number. Not printing odd numbers! 6 is an even number. Not printing...
1: Answer these questions: (a) Write a Java program to print whole numbers between 1 to...
1: Answer these questions: (a) Write a Java program to print whole numbers between 1 to 1000 which are divisible by 3, 5 and by both numbers. (b) Differentiate between instance and local variable in Java (c) In a tabular form, differentiate between instance and class variable
Create a JAVA lottery game application.  Generate four random numbers, each between 0 and 9 (inclusive).  Allow the...
Create a JAVA lottery game application.  Generate four random numbers, each between 0 and 9 (inclusive).  Allow the user to guess four numbers.  Compare each of the user’s guesses to the four random numbers and display a message that includes the user’s guess, the randomly determined four-digit number, and the amount of points the user has won as follows: No matches 0 points Any one digit matching 5 points Any two digits matching 100 points Any three digits matching 2,000 points All four...
In Assembly Language Write a program that generates 10 random numbers (0~99). Save the numbers into...
In Assembly Language Write a program that generates 10 random numbers (0~99). Save the numbers into arrayInt and calculate the sum. .data arrayInt Byte 10 DUP(?) Displays the array and the sum as follows: The random numbers are: xx xx xx xx xx xx …. The sum is   xxxx
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT