Class 9 Reflection


In Class 9, we learned about simulations. Simulations are a digital representation of a situation in the real world. For example, there can eb simuations of driving, simulations of flying a plane, etc. For the example they provided, they created a very simple simulation of a dice roll. Using the random library, they created a procedure that would grab a random number between 1 and 6. Once the function is called, the dice is "rolled" and it will return what value you got. We also learned about how to be efficent with code, because long code can take very long to run and it may cause lag. Then, they taught us more types of sorting. there is bubble sort that runs through the list and compares adjacent elements and rearanges them. Then there's quick sort that has a pivot and it runs through the code by dividing it up and sorting through the divisions.

Homework 1:

#Enter code here
import random

def contestants():
    return random.randint(0,100)

def win():
    contestant = contestants()
    if contestant == 20 :
        print("You won $1000!")
    else :
        print("Sorry, you didn't win.")

win()

Homework 2:

#edit this code
numbers = [i for i in range(1, 99999999)]
def sum() :
    total = (len(numbers) * (numbers[0] + numbers[-1]))/2
    return total

print(sum(numbers))