






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 - ANS-x = x + c a -= 3 - ANS-a = a - 3 x *= 4 - ANS-x = x * 4 y /= 3 - ANS-y = y / 3 what are some different types of variables? - ANS-Integers, Floating-Point, Strings, Booleans what is an integer? - ANS-whole numbers, no decimals/fractions what are floating-point numbers? - ANS-numbers with a decimal point what is boolean? - ANS-single value either true or false what are strings? - ANS-way of describing text (you can use either single quotes or double quotes)
float(3) - ANS-value becomes 3. int(4.9) - ANS-has the value 4 str(10*1.0) - ANS-has the value '10.0' what is the boolean value of true/false? - ANS-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)) - ANS-3: how to ask the user for input? - ANS-x = float(input()) == - ANS-equal to != - ANS-inequality 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) - ANS-false temperature = 100 is_hot = (temperature > 85)
sum = 0 for i in range(10): sum += i+ print(sum) - ANS- what are nesting loops? - ANS-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 - ANS-i is 0 j is 0 i is 1 j is 0 i is 2 j is 0 what does the "break" statement do? - ANS-it immediately stops that iteration in the loop! for i in range(10): if i%2 == 1: continue print("i is", i) - ANS-i is 0 i is 2 i is 4
i is 6 i is 8 grades = [87, 93, 75, 100, 82, 91, 85] grades[1] = 10 grades[2] -= 90 grades[3] = grades[1]+grades[2] print(grades[3]) - ANS-- how to find the length of a list? - ANS-print(len(x)) how do you add an element to a list? - ANS-.append(
[a:b] grades = [87, 93, 75, 100, 82, 91, 85] print(grades[0:3]) print(grades[4:5]) print(grades[-3:-1]) - ANS-[87, 93, 75] [82] [82, 91]
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 - ANS-(program draws a square) t.right(90) - ANS-turtle turns right 90 degrees t.penup() - ANS-lifts turtle pen up from canvas how is turtle motion similar in behavior to robotic controls? - ANS-just like we combine turtle motions to make more complex shapes, we can combine robot motions to create more complex actions file basics - ANS-•first "open" the file (specify how we will work with the file) •then, work with the file contents (reading/writing) •finally, "close" the file format for opening files - ANS-
w: a: r+: - ANS-•reading (we will read data from the existing file) •writing (we will write data to a new file) •appending (we will append data to an existing file) •will read from AND write to the file 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 - ANS-output_file = open('Results.out', 'w') what is the alternative way to opening a file with an assignment and later closing? - ANS-with
is assignment allowed in tuples? - ANS-no, it does not support item assignment. however, you can assign values from a tuple. len(x) - ANS-this function returns the character length of a string x how to import individual functions from a module - ANS-from
what are examples of a mutable data type? - ANS-lists, dictionaries what are examples of immutable data type? - ANS-boolean, integer, float, tuple, string types of errors - ANS-syntax errors, run-time errors, logic errors syntax error - ANS-an error that results when an instruction does not follow the syntax rules or grammar of the programming language. run-time errors - ANS-error that occur when the program is being executed logic errors - ANS-occurs when the program runs and executes, but the output is not what you wanted/expected how to handle a run-time error - ANS-try: except: types of built in exceptions - ANS-TypeError, OSError, ZeroDivisionError