Title
Scores:
- Section 1-2
- Section 3-4
- Section 5-7 - 0.8
- Section 8,10- 0.8
- Section 9,11 - 0.75
- Section 12-13 -
Algorithim: A set of commands that runs a certain piece of code repetively
sum = 0 # start with a sum of 0
for i in range (1, 6): # you will repeat the process five times for integers 1-5
sum = sum + i # add the number to your sum
print(sum)
Binary Search- Search procedure which searches the median to find a desired number
List- List of different elements in one item
my_list = [1, "Hello", 3.4]
Array- Multiple data points as one part
cars = ["Ford", "Volvo", "BMW"]
Boolean- True or false value which fullfills a certain variable
sunny = "false"
fun = "true"
print(sunny)
print(fun)
Nested Conditionals - Multiple conditional loops put inside of each other, so one loop will only run if the other loops condition is fullfilled
var = 3
if var % 2 == 1:
if var == 3:
print("Hello")
Variables - a symbolic name that is a reference or pointer to an object Link:https://realpython.com/python-variables/#:~:text=A%20Python%20variable%20is%20a,the%20object%20by%20that%20name.
Data Types - is a classification that specifies which type of value a variable has and what type of mathematical, relational or logical operations can be applied to it without causing an error.
var = 300
bar = int(300.5)
star = float(300)
tar = str(30000)
print(var)
print(bar)
print(star)
print(tar)
Simulation- run on a single computer, or a network of computers, to reproduce behavior of a system. Link: https://www.codingame.com/learn/simulation#:~:text=A%20computer%20simulation%20is%20a,and%20take%20the%20best%20decision.
import random
#Asks for user input about how many dice rolls they want
n = int(input("How many dice rolls?"))
#Function roll
def roll(n):
#Cycles through how many rolls they want
for i in range (n):
#Rolls the dice (getting a random number between 1 and 6)
x = random.randint(1,6)
#prints the roll of the dice
print("Your dice roll is", x)
roll(n)
Procedural abstraction - when we write code sections (called "procedures" or in Java, "static methods") which are generalised by having variable parameters. The idea is that we have code which can cope with a variety of different situations, depending on how its parameters are set when it is called Link: http://www.eecs.qmul.ac.uk/~mmh/AMCM048/abstraction/procedural.html#:~:text=Procedural%20abstraction%20is%20when%20we,set%20when%20it%20is%20called.
Efficiency
- Polynomial: Work is proportional to time(1:1)
- Exponential: Time is exponential to work rate(2:1)
import time
numlist = [1,3,5,7,9,11,13,15,17,19]
valuelist = [0,3,6,9,12,15,18,21]
def isvalue(value,array):
#--------------------
exists = False
while exists == False:
for i in range(len(array)):
if value == array[i]:
exists = True
if exists == False:
return exists
#--------------------
starttime = time.time()
for i in range(100000):
for i in range(len(valuelist)):
x = isvalue(valuelist[i],numlist)
endtime = time.time()
print(endtime-starttime,'seconds')
Random Function in Python - Function that can be used to choose an item from a type of data set randomly
import random
print(random.randint(0,9))
list = ["o1", "o2", "o3"]
print(random.choice(list))
string = "Prasith"
print(random.choice(string))
tuple1 = (1, 2, 3, 4, 5)
print(random.choice(tuple1))
Library - A Python library is a collection of related modules. It contains bundles of code that can be used repeatedly in different programs. Source: https://www.geeksforgeeks.org/libraries-in-python/
import math
A = 16
print(math.sqrt(A))
# Importing specific items
from math import sqrt, sin
B = 3.14
print(sin(B))