Planning our Project
What are simulations by College Board definition?
- Simulations are abstractions that mimic more complex objects or phenomena from the real world
- Purposes include drawing inferences without the contraints of the real world
- Simulations use varying sets of values to reflect the changing state of a real phenomenon
- Often, when developing a simulation, it is necessary to remove specific details or simplify aspects
- Simulations can often contain bias based on which details or real-world elements were included/excluded
- Simulations allow the formulation of hypotheses under consideration
- Variability and randomness of the world is considered using random number generators
- Examples: rolling dice, spinners, molecular models, analyze chemicals/reactions...
import random # a module that defines a series of functions for generating or manipulating random integers
random.choice() #returns a randomly selected element from the specified sequence
random.choice(mylist) # returns random value from list
random.randint(0,10) #randomly selects an integer from given range; range in this case is from 0 to 10
random.random() #will generate a random float between 0.0 to 1.
Question: The following code simulates the feeding of 4 fish in an aquarium while the owner is on a 5-day trip:
numFish ← 4
foodPerDay ← 20
foodLeft ← 160
daysStarving ← 0
REPEAT 5 TIMES {
foodConsumed ← numFish * foodPerDay
foodLeft ← foodLeft - foodConsumed
IF (foodLeft < 0) {
daysStarving ← daysStarving + 1
}
}
- This simulation simplifies a real-world scenario into something that can be modeled in code and executed on a computer.
import random
cards = ["Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"]
suits = ["Diamonds", "Hearts", "Spades", "Clubs"]
print(random.choice(cards) + " of " + random.choice(suits))
import random
length = [0, 1, 2, 3, 4, 5]
direction = ["left", "right"]
print("The frog jumped" , random.choice(length) , "hops to the" , random.choice(direction))
Population after natural disaster
- When natural disasters occur, certain times random traits are wiped from a population
- Take for example the Galapagos finches
- When a drought hit, smaller seeds became more rare so finches with larger beaks had greater chance of survival
- this can be modeled (with lots of simplification)
- Take for example the Galapagos finches
- Additions we would add
- specific data on beak size/wing length/height
- so for certain disaster, wing legnths > 5.5 survived
- specific data on beak size/wing length/height
import random
beak = ["small-beak", "long-beak", "medium-beak"],
wing = ["small-wings", "large-wings", "medium-wings"],
height = ["short", "tall","medium"]
naturaldisaster = ["flood", "drought", "fire", "hurricane", "dustbowl"]
print("When a" , random.choice(naturaldisaster) , "hit", random.choice(height), "birds died")