1/12
Computer science
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Formal vs Actual parameters
Formal parameters are in the sub-programs DEF line.
Actual Parameters are passed into the sub-program.
Local vs Global variables
Local are defined within the sub-program.
Global are defined in the main program.
Function vs Procedures
A function returns a value (For example:
def calc_circumference(radius):
Circumference = 2 × 3.14 * radius
return circumference)
A procedure produces an effect. (For example:
def display_welcome(name):
print( “Hello” + name))
Substrings
You can shorten strings of text using substrings. Example:
message = hello world
print(message[0:5]) = hello
This happens because the position of the string starts at 0 instead of 1 so the 5 letters would be “hello”.
converting characters to ASCII
ascii_code = ord(“A”)
converting ASCII to characters
new_char = chr(90)
Find min/max algorithm
*Find max below.
max = 0
for count in range (0,len(scores)):
…If scores[count] > scores[max]]:
……max = count
*Dots are supposed to be spaces. I have to use them so I don’t activate that fuck-ass AI.
*Same for find min just use the less than symbol (<)
Linear search
searchTerm = 80
for count in range (0,len(scores)):
If scores[count] == searchTerm:
print(searchTerm , “Found at position” , count)
print(“Search complete”)
Count occurences
search = 80
hits = 0
for count in range (0,len(Scores)):
if scores[count] == search:
hits = hits + 1
print(search , “has been found” , hits , “times.”)
Analysis
Purpose - A general description of the software.
Scope - A list of deliverables given to the client at the end of a project.
Boundries - What the program can’t do.
Scope of a variable
Section of code in which a variable is accessible/usable
Record structures
class className():
. def_init_(self):
. self. thing1 = “ “
. self. thing2 = 0.0
Writing to a file
fileWrite = open(“output.csv” , “w”)
for count in range (0, len(data)):
fileWrite.write(thing1[count] + str(thing2[count]) + “/n”)
file.close()
*The str in front of thing 2 is there because if its an integer it will try to add itself mathematically.
*The /n is there so the next write goes to a new line.