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()
import random
x = random.randrange(1, 101)
print(x)
55
def mycloset():
    myclothes = ["red shoes", "green pants", "tie", "belt"]
    myclothes.remove(random.choice(myclothes))
    print(myclothes)
mycloset()
['red shoes', 'green pants', 'tie']
c = random.randint(1, 3)
print(c)
if c % 2 == 1:
    print("heads")
else:
    print("tails")
2
tails
binary1 = 0
binary2 = 0
binary3 = 0
binary4 = 0
binary5 = 0
binary6 = 0
binary7 = 0
binary8 = 0
i = 0
num = random.randint(1,255)
while i < num: # very long binary converter
    if binary1 == 0: binary1 += 1 # it will go through each binary variable above
    else:                         # and check if it's a 1 or a 0. if its a 0 it becomes a 1
        binary1 = 0               # and if its a 1 it becomes a 0 and moves onto the next variable
        if binary2 == 0: binary2 += 1
        else:
            binary2 = 0
            if binary3 == 0: binary3 += 1
            else:
                binary3 = 0
                if binary4 == 0: binary4 += 1
                else: 
                    binary4 = 0
                    if binary5 == 0: binary5 += 1
                    else:
                        binary5 = 0
                        if binary6 == 0: binary6 += 1
                        else:
                            binary6 = 0
                            if binary7 == 0: binary7 += 1
                            else:
                                binary7 = 0
                                if binary8 == 0: binary8 += 1
    i += 1
print(num)
bin = [str(binary8), str(binary7), str(binary6), str(binary5), str(binary4), str(binary3), str(binary2), str(binary1)]
binary = ""  # the list above is putting each variable together and "binary" is defined for no errors
for n in bin: # this goes through the list bin[] and adds each variable to the string "binary"
    binary = binary + n
print(binary)
surv = ["drew", "dew", "der", "dre", "der", "wed", "rde", "red"]
z = 0
while z < 8: # this code uses both lists to determine who's alive and dead
    if bin[z] == "0":  # the increasing variable of a while loop is used as the index for each list
        surv[z] = [surv[z], "normal"] # if 0, the person is assigned as normal
    else:
        surv[z] = [surv[z], "zombie"] # if 1, the person is assigned as zombie
    z += 1
print(surv)
94
01011110
[['drew', 'normal'], ['dew', 'zombie'], ['der', 'normal'], ['dre', 'zombie'], ['der', 'zombie'], ['wed', 'zombie'], ['rde', 'zombie'], ['red', 'normal']]
d = random.randint(1, 6)
print(d)
3
import random
correct = 0
plck = 0
q1 = {
    "big?" : "yosh"
}
q2 = {
    "ayo the pizza here" : "ah, my ears burn"
}
q3= {
    "family guy funny moments #3" : "haha"
}
q4 = {
    "brass monkey" : "that funky monkey"
}
quesitons = [q1, q2, q3, q4, "blaknk"]
for n in quesitons:
    w = random.randrange(4)
    q = random.randrange(4)
    quesitons[4] = quesitons[w]
    quesitons[w] = quesitons[q]
    quesitons[q] = quesitons[4]
quesitons.pop(4)
for u in quesitons:
    for n, c in u.items():
        print(n)
        a = input("Write answer here")
        if a == c:
            correct += 1
            print("yea")
        else:
            print("wrong. you idiot")
print("you got " + str(correct) + "/4. good job. or bad job if you did bad")
ayo the pizza here
yea
brass monkey
wrong. you idiot
big?
yea
family guy funny moments #3
yea
you got 3/4. good job. or bad job if you did bad
import random
# I'm going to simulate the lottery
lucky = random.randint(1, 13983816) # I took the first statistic I found online. 1 in 13,983,816
pick = input("Pick Your number")
print(lucky)
print(pick)
if plck == lucky:
    print("You won! That's impossible!")
else:
    print("You lost. ")
4782034
400316
You lost. 

If you've got a keen eyesight, you might notice a certain something in this code. I'm going to eliminate the joke immedietly by saying that it's impossible to win. This is true in two ways. First, the lottery is literally impossible. I'm not saying it's rigged, it's just so extremely unlikely that the only way to properly express it is impossible. Second, it's impossible, I lied. I made this impossible as a goof. The value you input becomes pick but the code checks plck, which is a variable defined in the cell before.