From 900f7dce31e67f39c7b156cdcf5f781b916f9982 Mon Sep 17 00:00:00 2001 From: Daniel <59575049+lemoentjiez@users.noreply.github.com> Date: Tue, 27 Dec 2022 16:54:23 +0200 Subject: [PATCH] Update continuous.py --- LabPSA_3/continuous.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/LabPSA_3/continuous.py b/LabPSA_3/continuous.py index 17b4245..1d68b2c 100644 --- a/LabPSA_3/continuous.py +++ b/LabPSA_3/continuous.py @@ -13,22 +13,21 @@ def distance(a, b): return numpy.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2) -right_half, less_then_average, more_then_average, within_us = 0, 0, 0, 0 +right_half, less_than_5, more_than_5, within_range = 0, 0, 0, 0 n = 10000 for i in range(n): point = random_point() if point[0] > 0: right_half += 1 if point[2] < 5: - less_then_average += 1 + less_than_5 += 1 else: - more_then_average += 1 + more_than_5 += 1 if distance([point[0], point[1]], [0, 5]) < 5: - within_us += 1 - -print('it lands in the right half of the target: ' + str(right_half/n)) -print('its distance from the center is less than 5 inches: ' + str(less_then_average/n)) -print('its distance from the center is greater than 5 inches: ' + str(more_then_average/n)) -print('it lands within 5 inches of the point (0, 5): ' + str(within_us/n)) + within_range += 1 +print('Right-half of target: ' + str(right_half / n)) +print('Less than 5 inch from center: ' + str(less_than_5 / n)) +print('More than 5 inches from center: ' + str(more_than_5 / n)) +print('Within 5 inches from (0, 5): ' + str(within_range / n))