Bar Graph:
import matplotlib.pyplot as plt
fig = plt.figure(figsize = (5, 5))
barlist=plt.bar(['green', 'pink', 'yellow', 'purple'], [4, 22, 19, 5,])
barlist[0].set_color('lime')
barlist[1].set_color('fuchsia')
barlist[2].set_color('yellow')
barlist[3].set_color('purple')
plt.xlabel("Color Bin")
plt.ylabel("Number of Times Landed")
plt.title("Plinko Probability")
plt.show()
Plinko_Iterations:
import random
def plinko(iterations):
green = 0
pink = 0
yellow = 0
purple = 0
for i in range(iterations):
path = ""
value = 0
for j in range(1, 10):
num = random.randint(1, 2)
if num == 1:
bounce = "left, "
value = value - 1
elif num == 2:
bounce = "right, "
value = value + 1
path += bounce
if value < -6:
green += 1
print(path)
print("Your path leads to the green bin!")
elif value < 0:
pink += 1
print(path)
print("Your path leads to the pink bin!")
elif value < 6:
yellow += 1
print(path)
print("Your path leads to the yellow bin!")
else:
purple += 1
print(path)
print("Your path leads to the purple bin!")
print('\nResults:\nGreen:', green, '\nPink:', pink,'\nYellow:', yellow, '\nPurple:', purple)
return
plinko(40)
Plinko:
import random
path = ""
value = 0
for i in range(1, 10):
num = random.randint(1, 2)
if num == 1:
bounce = "left, "
value = value - 1
elif num == 2:
bounce = "right, "
value = value + 1
path += bounce
print(path)
if value < -6:
print("Your path leads to the green bin!")
elif value < 0:
print("Your path leads to the pink bin!")
elif value < 6:
print("Your path leads to the yellow bin!")
else:
print("Your path leads to the purple bin!")
Keplers_Law:
#Importing our libraries:
import numpy as np
import matplotlib.pyplot as plt
#Making a list of planet names and arrays of our data:
planet_name = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn"]
orbital_period = np.array([87.77, 224.70, 365.25, 686.95, 4332.62, 10759.2])
semimajor_axis = np.array([58e6, 108e6, 149e6, 228e6, 778e6, 1427e6])
#Plotting our data as is:
plt.scatter(orbital_period, semimajor_axis)
plt.plot(orbital_period, semimajor_axis)
#Convert orbital period units from days to years & semimajor axis units from km to AU (astronomical units)
#p_years = orbital_period / 365.25
#print(p_years)
#a_AU = semimajor_axis / 149e6
#print(a_AU)
#Plotting Kepler's 3rd Law:
#p_squared = p_years**2
#a_cubed = a_AU**3
#plt.scatter(p_squared, a_cubed)
#plt.plot(p_squared, a_cubed)
#Rescaling our plot axes to logarithmic:
#plt.xscale("log")
#plt.yscale("log")
#Titling our plot and labeling our axes:
#plt.title("Kepler's 3rd Law")
#plt.xlabel("Orbital Period squared (year^2)")
#plt.ylabel("Semi-Major Axis cubed (AU^3)")
#Annotating our data points:
#for i in range(len(p_squared)):
# plt.annotate(planet_name[i], (p_squared[i], a_cubed[i]))
plt.show()