CY300 TEE

Ace your homework & exams now with Quizwiz!

What are the standard Boolean operators?

and, or, not

How can you make a deep copy of a list?

c_list = copy.deepcopy(a_list)

What is one correct way to initialize a nested list?

cols = 5 rows = 3 correct_table = [] my_row = [0] * cols for row in range (rows): correct_table.append(my_row[:])

What does a type hint look like?

def add_ten( param1:int)->int:

What does Python function definition look like?

def f(celsius_float): return celsius_float*1.8+32

What is an f string?

f"a bad approximation of pi is [23/7:.2f}"

What does Python function invocation look like?

f(C)

What does inputting a file look like in Python?

input_file = open("fileRead.txt", "r") for line in input_file: print(line) input_file.close()

What does a for loop look like?

for x in list_of_values: execute code... execute code...

What does an if statement look like?

if (condition_is_true): execute code... execute code...

How do we manually raise exceptions in Python?

if not a_str.isupper(): raise ValueError(a_str+' is not uppercase.')

What does string slicing look like?

str1 = 'hello world' str1[0:5] = 'hello' str1[2:10:3] = 'l r'

What does a string index look like?

str1 = 'hello world' str1[0] = 'h' str1[4] = 'o'

How do you reverse a string?

str1 = 'hello world' str1[::-1] = 'dlrow olleh'

What is Python exception handling format?

try: print('In try suite.') print('3/0 is: ', 3/0) except ZeroDivisionError: print('In except suite.") print("Cannot divide by zero!")

What are the standard control statements?

Break: ends code as is Continue: continues to next iteration of loop Else: Provides alternate route Pass: Used as a placeholder when code being created

What is a computer?

Something that does computation.

What does sort method do?

Sorts sequence ascending by default (reverse=True will convert to descending)

What are the three classes of errors?

Syntactic - use of programming language Runtime - syntactically correct, but ask for an impossible task Design - everything else, wrong results

What functions and methods work on dictionaries?

Standard functions and operators that work on collections tend to work on dictionaries (min(), max(), len(), in) To access collections from dictionaries items (), keys(), values() Removing elements: pop() Shallow copy method: copy()

How many bytes are in a kilobyte?

1024

How many kilobytes are in a megabyte?

1024

How many bytes are in a word?

4 bytes (32 bit systems) or 8 bytes (64 bit systems)

How many bits are in a byte?

8

What are common comparative operators?

< less than > greater than <= less than or equal >= greater than or equal == equal to != not equal to

What is a dictionary?

A collection object To access a value in a dictionary, use the key (can be any immutable object)

What is a transistor?

A electronic 'gate' that either blocks or allows the flow of current.

What does the join function do?

Takes a list of strings and combines them together based upon delimiter used

What is object oriented programming?

A general approach to programming that grew out of a need to handle the increasing complexity of programming. Program is a set of objects where each object can interact to accomplish the program goals. Attributes: stored data (properties) Method: a function defined for a specific data type (behaviors)

What is a type hint?

A mechanism for annotating the types of variables, function parameters, and return values within code.

What is code?

A sequence of stored instructions.

What is Rule 5 of programming?

Test your code often, and thoroughly!

What are the purposes of functions?

Abstraction Re-usability Ease of Testing

What does the extend method do?

Adds specified elements individually to end of list

What does the append method do?

Adds the specified element to the end of the list

What is programming Rule 7?

All input is evil until proven otherwise

What does the input() function return?

Allows the user to provide an input into the program. Always returned as string.

What is a program?

An implementation of a particular algorithm.

What is Pseudocode?

An informal high-level description of a computer program

What is an algorithm?

An ordered set of unambiguous, executable steps defining a terminating process.

How do you create a tuple with one element?

(1,)

What operators can the string class utilize?

+, *, == (all comparison operators) str1*2 = 'hello worldhello world' str2 = 'goodbye' str1+str2 = 'hello worldgoodbye'

What five steps does a computer follow to execute operations?

1. Fetch Instruction 2. Decode Instruction 3. Execute Operation 4. Store Result 5. Repeat

What are the general steps of data preparation?

1. Identify and understand the problem 2. Describe and evaluate the data 3. Prepare the data 4. Create and train a model on the prepared data 5. Evaluate the model 6. Deploy the model

What is the problem solving methodology utilized in this class?

1. Understand the Problem 2. Devise a Plan 3. Carry out the Plan 4. Check and Interpret

What are the list() and tuple() methods used for?

Casting objects to lists or tuples

What does the assert() expression do?

Check for a condition that must be true to continue, if untrue will provide string for return assert k > 0, "k must be greater than 0"

What is the range() function?

Contains three parameters: start, end, step start specifies the starting value end specifies the ending value (not inclusive) step specifies the increment amount

What do we look to test for in Python?

Correctness Completeness Security Interface Load Resources Responsiveness

What does the zip function do?

Creates pairs for dictionary usage, can allow for dictionary reversal

What are Python tuples?

Defined by a sequence of elements, separated by commas: 1,2,3 Can be surrounded by parentheses: (1,2,3) Any list operation, function, or method that does not violate immutability will work on tuples (count(), len(), index(), min, max)

What are the qualities of a 'good' algorithm?

Detailed Effective Specific as to its behavior General Purpose

What does the function in return?

Determines if a string is a part of a larger string

What are the three characteristics of object oriented programming?

Encapsulation - hide implementation details of functions/methods Polymorphism Inheritance

What does the ** operator return?

Exponential operation

What does the // return?

Floor division (division without remainder)

What does the seek() method do?

Go to a particular line of the program

What are type hint purposes?

Improved Code Readability Early Error Detection Enhanced Tooling and IDE Support

What does insert method do?

Inserts specified element (2 parameter) at the specified position (1 parameter)

What does the function len() return?

Length of the input string

What are Python lists?

Lists are collection data types. A list is a sequence of elements separated by commas that are contained in a single set of brackets. Lists can: contain elements of all the same type contain elements of different types contain other lists

What is computation?

Manipulation of data by either humans or machines.

What is the __main__ module in Python?

Name of the environment where the top-level code is run

What are common error messages?

NameError: name is not in the namespace (scope) ValueError: Conversion error TypeError: Operation on two different types not permitted IndexError: String or list index out of range SyntaxError: Invalid syntax

What does Python pass?

Object references, everything in Python is an object, so every value passed is a reference to an object.

What are the open() and close() methods used for in Python?

Opening and closing files

What does tell() method do?

Output where in the file the program is

What is the Python order of operations

Parentheses, Exponent, Multiplication, Addition, Relational/Comparison, Logical (not), Logical (and), Logical (or)

What are functions that do not return any results?

Procedures

What are the components of a computer?

Processor Algorithmic and Logic United (ALU) -> Main Memory Random Access Memory (RAM) -> Disk, Inputs (Keyboard, Mouse), Outputs (Monitor, Printer), Network

What does the __doc__ method do?

Provides additional information about a given function.

What does the ord function return?

Provides the UTF-8 encoding for any English character

What does the chr function return?

Provides the corresponding English character to any UTF-8 number

What are the three features of a program?

Readability Robustness Correctness

What does the pop method do?

Removes element at specified position (option, default is last item in sequence)

What does the remove method do?

Removes first instance of given element in sequence

What does a function do in Python?

Represents a single operation to be performed Takes zero or more arguments as input Returns one value (potentially a compound object) as output

What does the type() operator do?

Return the type of variable contained.

What is a KeyError?

Returned when user attempts to access a key that doesn't exist

What does the index method do?

Returns first occurrence of given value in sequence (beginning at 0)

What does the count method do?

Returns number of elements with specified value

What does the % operator return?

Returns the remainder if division operation were performed

What does reverse method do?

Reverses the sorting order of elements

What does the split function do?

Separates a string into a list of elements based upon the delimiter

How do we initialize a set?

Sets use {} like dictionaries set() creates an empty set Set items are unique and they have no keys/indices. Items may be any immutable type and in any order.

What is string indexing?

The ability to access each character in a string individually (indexed from 0 to n-1, where n is length of string)

What is function scope?

The set of program statements over which a variable exists, and/or can be used.

What does the / operator return?

True division (with remainder), always returns float

What does the int() function return?

Truncates given number to integer (no rounding)

How are letters represented in binary?

UTF-8 Unicode shows mapping to English characters, symbols, and control characters.

What are three methods of testing?

Unit Testing: Test components Integration Testing: Test components together System Testing: Tests the entire system to determine if it solves the problem

What is the "with" of opening files?

Uses with method in order to avoid step of having to manually close files (preferred)

How can you make a shallow copy of a list?

Utilizing the slicing operator a_list = [1,2,3] b_list = a_list[:]

What are sets?

mutable, unordered objects, used commonly for representing mathematical relationships or anytime you need to ensure your collection only contains unique values

What does file writing look like in Python?

out_file = open("fileWrite.txt", "w") out_file.write("output stuff") outfile.close()

What is an alternate method to write to files in Python?

out_file = open("fileWrite.txt", "w") print("first line", file=out_file) out_file.close()

How would a dictionary initialization look like?

phone_book = {} phone_book["Bill"] = '555-2123'

What are the different codes for file usage in Python

r - read only w - write only, clears file contents a - write only, existing data unchanged (appended) r+ - read and write (overwrites from files beginning) w+ read and write (clears the files contents) a+ read and write (files contents left intact and read and write at files end)

What does a while loop look like?

while (condition_is_true): execute code... execute code...

What does the with method of file input look like in Python?

with open("histogram.txt","w") as out_file: statement statement


Related study sets

Marketing 3343 Final Exam Review -Murdock 252-

View Set

Soil 3:Weathering, Soil, and Mass Movements

View Set

Chapter 5: Innovation and Entrepreneurship

View Set

Small Test - Economics EOC (GSE) UPDATED Domain: International Economics

View Set