Things I love:
This is one of my paintings.
My sample script is something that was used in Data Driven Decision Making (with Dan Runfola) and I modified to support the help command line argument.
#Last edit: 10-7-19
#Required imports
import random
import math
#FUNCTIONS
#Help function from Davis's music randomizer
def show_help():
"""
Name: show_help
Inputs: None
Outputs: None
Features: Prints the help text when user uses the '-h' command flag
"""
= ( "-h, --help Enter a whole number!\n")
help_txt print(help_txt)
#VARIABLES
#total darts thrown
= input('How many darts would you like to throw?')
n if n == '-h' or n == '--help':
show_help()else:
try:
= int(n)
total if total < 0:
print('You must must throw a positive number of darts.')
#Number of darts that land inside (initializing the list)
= 0
inside #Total number of darts to throw (gotten from input)
# total = n
#Define the length of a side of the square
= 10
length #Define the size of the circle, originating from the center of the square
= 5.0
circle_radius
#Iterate for the number of darts
for i in range(0, total):
= random.uniform(0, length)
x = random.uniform(0, length)
y #test if the dart is inside or outside
#(ie, is the distance from the center of the square less than the circle radius?)
if math.sqrt((x**2) + (y**2)) < circle_radius*2:
+= 1
inside
print("Percent of Darts Inside:")
print((inside / total)* length**2)
except ValueError:
print('Bad!')