








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









x += c - ✔✔x = x + c a - = 3 - ✔✔a = a - 3 x *= 4 - ✔✔x = x * 4 y /= 3 - ✔✔y = y / 3 what are some different types of variables? - ✔✔Integers, Floating-Point, Strings, Booleans what is an integer? - ✔✔whole numbers, no decimals/fractions what are floating-point numbers? - ✔✔numbers with a decimal point what is boolean? - ✔✔single value either true or false what are strings? - ✔✔way of describing text (you can use either single quotes or double quotes)
float(3) - ✔✔value becomes 3. int(4.9) - ✔✔has the value 4 str(10*1.0) - ✔✔has the value '10.0' what is the boolean value of true/false? - ✔✔true is assumed to have the value 1 false is assumed to have the value 0 x = 3 y = 4 print(str(x) + ':' + str(y)) - ✔✔3: how to ask the user for input? - ✔✔x = float(input()) == - ✔✔equal to != - ✔✔inequality a = 10 b = 10
while a == 0: print("About to change a") a = 1 print("Changing a back to 0") a = 0 - ✔✔About to change a Changing a back to 0 About to change a Changing a back to 0 ... (an infinite loop) what is the for loop designed to do? - ✔✔to perform specific statements for a determined number of iterations sum = 0 for i in range(10): sum += i+ print(sum) - ✔✔ 55 what are nesting loops? - ✔✔that is when you nest one loop inside another for i in range(3): print("i is", i)
for j in range(3): print(" j is", j) break - ✔✔i is 0 j is 0 i is 1 j is 0 i is 2 j is 0 what does the "break" statement do? - ✔✔it immediately stops that iteration in the loop! for i in range(10): if i%2 == 1: continue print("i is", i) - ✔✔i is 0 i is 2 i is 4 i is 6 i is 8 grades = [87, 93, 75, 100, 82, 91, 85]
name = "Texas A&M University" print(name[6:9]) - ✔✔A&M how to create a dictionary? - ✔✔dictionary = { }
what is top-down design? - ✔✔a way of designing your program by starting with the biggest problem and breaking it down into smaller and smaller pieces that are easier to solve what is bottom-up design? - ✔✔in programming, you take simpler pieces of code and combining them to create more complex pieces of code when is it good to create a new function - ✔✔when you identify something that will be done repeatedly, create a function that will do it for you from turtle import * forward(100) left(90) forward(100) left(90) forward(100) left(90) forward(100) left(90) #To return to starting orientation input() #So that the window doesn't disappear - ✔✔(program draws a square) t.right(90) - ✔✔turtle turns right 90 degrees
how would you open a file named Results.out so that it can be written to, and assigning the designator to a variable called output_file - ✔✔output_file = open('Results.out', 'w') what is the alternative way to opening a file with an assignment and later closing? - ✔✔with =
s = "1,2,3,4" elems= s.split(',') print(elems) - ✔✔['1', '2', '3', '4'] what are functions? - ✔✔basically a section of code that gets specified separately from the rest of the code. why are functions important? - ✔✔•prevents re-writing the same code repeatedly •helps to separate parts of code •is written separately from the rest of the code form of a function call - ✔✔
defF(a): a += 1 return a a += 10 return a x = F(4) print(x) - ✔✔ 5 what are examples of a mutable data type? - ✔✔lists, dictionaries what are examples of immutable data type? - ✔✔boolean, integer, float, tuple, string types of errors - ✔✔syntax errors, run-time errors, logic errors syntax error - ✔✔an error that results when an instruction does not follow the syntax rules or grammar of the programming language. run-time errors - ✔✔error that occur when the program is being executed logic errors - ✔✔occurs when the program runs and executes, but the output is not what you wanted/expected
how to handle a run-time error - ✔✔try: except: types of built in exceptions - ✔✔TypeError, OSError, ZeroDivisionError