COSC code

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/107

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 2:28 AM on 6/14/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

108 Terms

1
New cards
print(x)
Prints the value of x.
2
New cards
return x
Sends x back as the function result.
3
New cards
def f(x):
Defines a function with parameter x.
4
New cards
x = 5
Assigns the value 5 to x.
5
New cards
x == 5
Checks whether x is equal to 5.
6
New cards
x != 5
Checks whether x is not equal to 5.
7
New cards
x < 5
Checks whether x is less than 5.
8
New cards
x <= 5
Checks whether x is less than or equal to 5.
9
New cards
if condition:
Runs the indented code only if condition is True.
10
New cards
elif condition:
Checks another condition if previous if/elif was False.
11
New cards
else:
Runs if all previous conditions were False.
12
New cards
while condition:
Repeats while condition is True.
13
New cards
count += 1
Increases count by 1.
14
New cards
total += value
Adds value to total.
15
New cards
for item in items:
Loops through each item in items.
16
New cards
for i in range(len(items)):
Loops through every index of items.
17
New cards
range(n)
Produces 0 up to n - 1.
18
New cards
range(a, b)
Produces a up to b - 1.
19
New cards
items[i]
Gets item at index i.
20
New cards
items[-1]
Gets the last item.
21
New cards
items[a:b]
Gets items from index a up to b - 1.
22
New cards
items[::-1]
Returns a reversed copy of the list.
23
New cards
items.append(x)
Adds x to the end of the list.
24
New cards
items.sort()
Sorts the list in place.
25
New cards
items.reverse()
Reverses the list in place and returns None.
26
New cards
items.pop()
Removes and returns the last item.
27
New cards
len(items)
Returns the number of items.
28
New cards
x in items
Checks whether x is in items.
29
New cards
result = []
Creates an empty list.
30
New cards
result = ""
Creates an empty string.
31
New cards
result += text
Adds text onto the end of result.
32
New cards
tuple_value = (x, y)
Creates a tuple containing x and y.
33
New cards
x, y = point
Unpacks a 2-item tuple into x and y.
34
New cards
open(filename)
Opens a file and returns a file object.
35
New cards
infile.read()
Reads the entire file as one string.
36
New cards
infile.close()
Closes the file.
37
New cards
text.splitlines()
Splits text into a list of lines.
38
New cards
line.split(",")
Splits a CSV line into a list of strings.
39
New cards
s.strip()
Removes whitespace from both ends.
40
New cards
s.upper()
Returns uppercase version of s.
41
New cards
s.lower()
Returns lowercase version of s.
42
New cards
s.title()
Returns title-case version of s.
43
New cards
s.startswith(prefix)
Checks whether s starts with prefix.
44
New cards
int(text)
Converts text to an integer.
45
New cards
float(text)
Converts text to a float.
46
New cards
try:
Starts a block where an error might happen.
47
New cards
except ValueError:
Runs if a ValueError occurs in the try block.
48
New cards
pass
Does nothing.
49
New cards
raise RuntimeError("message")
Creates and raises a RuntimeError.
50
New cards
d = {}
Creates an empty dictionary.
51
New cards
d[key]
Gets the value stored under key.
52
New cards
d[key] = value
Adds or updates a key-value pair.
53
New cards
key in d
Checks whether key exists in the dictionary.
54
New cards
d.get(key, default)
Gets d[key], or default if key is missing.
55
New cards
d.items()
Gives key-value pairs from the dictionary.
56
New cards
d.keys()
Gives the dictionary keys.
57
New cards
d.values()
Gives the dictionary values.
58
New cards
counts[item] = counts.get(item, 0) + 1
Counts how many times item appears.
59
New cards
if key not in d: d[key] = []
Creates an empty list for a new dictionary key.
60
New cards
d[key].append(value)
Adds value to the list stored at d[key].
61
New cards
s = set()
Creates an empty set.
62
New cards
set(items)
Creates a set of unique items from items.
63
New cards
s.add(item)
Adds item to the set.
64
New cards
item in s
Checks whether item is in the set.
65
New cards
sorted(items)
Returns a sorted list.
66
New cards
class Person:
Defines a new class/type called Person.
67
New cards
def __init__(self, ...):
Initialises a new object.
68
New cards
self.x = x
Stores x as an attribute of the object.
69
New cards
obj.x
Accesses the x attribute of obj.
70
New cards
obj.method()
Calls a method on obj.
71
New cards
def __str__(self):
Defines what print(object) shows.
72
New cards
def __repr__(self):
Defines the programmer-style representation.
73
New cards
items.sort(key=lambda x: x.name)
Sorts objects by their name attribute.
74
New cards
import numpy as np
Imports NumPy as np.
75
New cards
np.array([1, 2, 3])
Creates a NumPy array.
76
New cards
np.zeros(n)
Creates an array of n zeros.
77
New cards
np.ones(n)
Creates an array of n ones.
78
New cards
np.full(n, x)
Creates an array of n copies of x.
79
New cards
np.arange(start, stop, step)
Creates values from start up to but not including stop.
80
New cards
np.linspace(start, stop, n)
Creates n evenly spaced values including start and stop.
81
New cards
xs ** 2
Squares every value in a NumPy array.
82
New cards
np.exp(xs)
Applies exponential to every value in xs.
83
New cards
data[:, 0]
Gets column 0 from a 2D NumPy array.
84
New cards
data[0, :]
Gets row 0 from a 2D NumPy array.
85
New cards
data[:, 1:]
Gets all rows and columns from column 1 onwards.
86
New cards
data[data > 0]
Filters data to values greater than 0.
87
New cards
np.logical_and(a, b)
Combines two boolean arrays with AND.
88
New cards
np.loadtxt(filename, delimiter=",", skiprows=1)
Loads numeric CSV data into a NumPy array.
89
New cards
np.loadtxt(filename, usecols=2)
Loads only column 2.
90
New cards
np.sum(data)
Returns the sum of data.
91
New cards
np.mean(data)
Returns the average of data.
92
New cards
np.min(data)
Returns the minimum value.
93
New cards
np.max(data)
Returns the maximum value.
94
New cards
np.std(data)
Returns the standard deviation.
95
New cards
from matplotlib import pyplot as plt
Imports plotting tools.
96
New cards
axes = plt.axes()
Creates graph axes.
97
New cards
axes.plot(xs, ys)
Plots y-values against x-values.
98
New cards
axes.bar(xs, ys)
Draws a bar chart.
99
New cards
axes.hist(data, bins=bins)
Draws a histogram.
100
New cards
axes.set_title(title)
Sets the graph title.