mercredi 29 avril 2020

How do I use input in def (Python)

I'm a newbie when it comes to coding. I would highly appreciate it if you can help me solving my problem regards to coding. I tried to use input in my def but doesn't work.

import random

def estimate_pi(n):
    num_point_circle = 0
    num_point_total = 0
    for _ in range(n):
        x = random.uniform(0,1)
        y = random.uniform(0,1)
        distance = x**2 + y**2
        if distance <= 1:
            num_point_circle += 1
        num_point_total += 1
    return 4 * num_point_circle/num_point_total
n = input("Enter A Random Number")
result = estimate_pi(n)
print (result)



Aucun commentaire:

Enregistrer un commentaire