COMPREHENSIVE Q&A STUDY GUIDE WITH
COMPLETE SOLUTIONS
!= - ANSWER-inequality
== - ANSWER-equal to
a -= 3 - ANSWER-a = a - 3
a=0
while a == 0:
print("About to change a")
a=1
print("Changing a back to 0")
a = 0 - ANSWER-About to change a
Changing a back to 0
About to change a
Changing a back to 0
... (an infinite loop)
a = 10
b = 10
c = 20
d = ((a>b) and (b<=c)) or (not((((c<=a+b) and (a==10)) or ((b==10) and c!=10))))
print(d) - ANSWER-false
converting csv file to dataframe - ANSWER-pd.read_csv(filepath)
create numpy array - ANSWER-np.array(list, type)
defF(a):
a += 1
return a
a += 10
return a
x = F(4)
print(x) - ANSWER-5
difference between lists, tuples, and arrays - ANSWER-lists use brackets, tuples use
either parentheses or commas, arrays you can manipulate each individual character
difference btwn <string variable> = <fileID>.readline() and <string variable> =
<fileID>.read() - ANSWER-.read() will read the entire file into one single string which
could be problematic bc it can be a REALLY large string.
, .readline() will convert all the lines in the file into a list of strings and each element of the
list is a string, giving one line of the program.
different formats for reading files - ANSWER-<string variable> = <fileID>.readline()
<string variable> = <fileID>.read()
examples of built-in functions - ANSWER--print()
-input()
-float()
-open()
-len()
file basics - ANSWER-•first "open" the file (specify how we will work with the file)
•then, work with the file contents (reading/writing)
•finally, "close" the file
float(3) - ANSWER-value becomes 3.0
for i in range(10):
if i%2 == 1:
continue
print("i is", i) - ANSWER-i is 0
i is 2
i is 4
i is 6
i is 8
for i in range(3):
print("i is", i)
for j in range(3):
print(" j is", j)
break - ANSWER-i is 0
j is 0
i is 1
j is 0
i is 2
j is 0
form of a function call - ANSWER-<function name>(<arguments>)
format for defining a function - ANSWER-def <function name>(<parameters>):
<stuff to do>
format for opening files - ANSWER-<fileID> = open("<File Name>", "<designator>")