Question

[PYTHON]Objective Complete the function definitions generateRandomPoint,isIncircle, and ApproximatePI generateRandomPoint(): Returns

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question.
Here is the completed code for this problem.  Let me know if you have any doubts or if you need anything to change.
Thank You !!
================================================================================================
import  random

def generateRandomPoint():
    return [random.randint(0,4),random.randint(0,4)]


def isInCircle(x,y):
    d=(x**2+y**2)
    return d<1

def ApproximatePI(n):
    count_inside=0
    for i in range(n):
        random_point=generateRandomPoint()
        if isInCircle(random_point[0]/4.0,random_point[1]/4.0) is True:
            count_inside+=1
    return (4.0*count_inside)/n

print(ApproximatePI(100000))
Add a comment
Know the answer?
Add Answer to:
[PYTHON] Objective Complete the function definitions generateRandomPoint,isIncircle, and ApproximatePI generateRandomPoi...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a function in python that takes a set A and a relation R(x, y) on...

    Write a function in python that takes a set A and a relation R(x, y) on A (as a python function such that R(x, y) returns true if and only if the relation xRy holds), and returns True if and only if the relation R is reflexive. Here is the function signature you need to use. def is reflexive(A, R): You can test your code as follows. s = {1,2,3} def y(x, y): return x == y def n(x, y):...

  • Implement these in Python 3 preferably. Task: Implement the following algorithms to solve the Stock Span...

    Implement these in Python 3 preferably. Task: Implement the following algorithms to solve the Stock Span Problem using the ADT for a Stack in ython. The implementation of the ADT of a Stack (10 points) Implementation of computeSpans1 (20 points) Implementation of computeSpan2 (30 points) Provide the derived computational complexity of both computeSpans1 and computeSpans2 (40 points) Algorithm computeSpans1 (P) Input: an n-element list P of numbers such that P[i] is the prices of the stock on day I Output:...

  • Use Python [12] 10. Complete the code for the function documented below. Note that the function...

    Use Python [12] 10. Complete the code for the function documented below. Note that the function gets all its input from the parameters and not from the keyboard. It returns all information to the calling function and not to the computer display def frstiggest la, b, c) 'Assume a, b, and c are integers. Return True if a is greater than both b and c, Examples anh False otherwise would be True; firstigges (9, 6, 7) and firstBiagest (4, -2,...

  • PYTHON QUESTION... Building a Binary Tree with extended Binary Search Tree and AVL tree. Create a...

    PYTHON QUESTION... Building a Binary Tree with extended Binary Search Tree and AVL tree. Create a class called MyTree with the methods __init__(x), getLeft(), getRight(), getData(), insert(x) and getHeight(). Each child should itself be a MyTree object. The height of a leaf node should be zero. The insert(x) method should return the node that occupies the original node's position in the tree. Create a class called MyBST that extends MyTree. Override the method insert(x) to meet the definitions of a...

  • Hi, can someone offer input on how to address these 4 remain parts the zybook python...

    Hi, can someone offer input on how to address these 4 remain parts the zybook python questions?   4: Tests that get_num_items_in_cart() returns 6 (ShoppingCart) Your output ADD ITEM TO CART Enter the item name: Traceback (most recent call last): File "zyLabsUnitTestRunner.py", line 10, in <module> passed = test_passed(test_passed_output_file) File "/home/runner/local/submission/unit_test_student_code/zyLabsUnitTest.py", line 8, in test_passed cart.add_item(item1) File "/home/runner/local/submission/unit_test_student_code/main.py", line 30, in add_item item_name = str(input('Enter the item name:\n')) EOFError: EOF when reading a line 5: Test that get_cost_of_cart() returns 10 (ShoppingCart)...

  • Complete the definition of the backsub function below by implementing the backward substitution algorithm. This function...

    Complete the definition of the backsub function below by implementing the backward substitution algorithm. This function takes as input: U, an n x n upper triangular matrix b, an n x 1 vector for the right-hand-side of the matrix equation and returns as output: x, an n x 1 solution vector x function x = backsub(U,b) % Initialize the output vector. This will speed up computation by pre-allocating the memory. n = length(b); x = zeros(size(b)); % Do the backward...

  • a) Make a function which returns x/3 with a given integer x. double third(int x) {...

    a) Make a function which returns x/3 with a given integer x. double third(int x) { //Complete your code below. ______________________________________ return y; } b) Make a program which shows 2 ∗ n with a given user input n. #include<iostream> using namespace std; // Complete the blank. _______________________ int main(){ int n; cout<<"Enter:"; cin>>n; cout<<twice(n); return 0; } int twice(int x){ return 2*x; } c) Make a function which returns true if n is positive, otherwise returns false. ________ positive(int...

  • Python only please, thanks in advance. Type up the GeometricObject class (code given on the back...

    Python only please, thanks in advance. Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default...

  • 3. Write the function find sorted elt whose input is a vector sorted in increasing order...

    3. Write the function find sorted elt whose input is a vector sorted in increasing order and an element x. The output is 0 if the element x does not occur in v, 1 if the element x does occur in v. Below is the algorithm you should implement, known as the binary search algorithm. Note that the code below returns the index, but we want to return true or false, not the index, so adjust your code accordingly. Algorithm....

  • in python and can you tell me why i am wrong? Thank you ZyBooks Python M...

    in python and can you tell me why i am wrong? Thank you ZyBooks Python M X zy cS 171: Computer x zy 11.9. LAB: Output x C Write A Program 1 x Slack | Hiu Nguy TG Python Program t x p ython - Getting x +. - 5 x € → e l earn.zybooks.com/zybook/DREXELCS171 Winter2020/chapter/11/section/9 Help/FAQ Kuanyu Lai - = zyBooks Bake My library > CS 171: Computer Programming home> > 11.9: LAB: Output values in a list...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT