Intro to Computer Science Midterm (Python).pdf, Exams of Biology

Intro to Computer Science Midterm (Python).pdf

Typology: Exams

2025/2026

Available from 10/28/2025

guaranteed-success
guaranteed-success 🇺🇸

3

(2)

3.8K documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Intro to Computer Science Midterm (Python).pdf and more Exams Biology in PDF only on Docsity!

Intro to Computer Science Midterm (Python) an expression a combination of values and operations that creates a new value that we call a return value indentation whitespace required for grouping keywords, operators, punctuators/delimiters types of python elements not allowed to be used as or in variable names code that does not return a value but ignored in both expressions and statements statement does perform some task . : what type of control statement is a while loop H ue : used for repetition? : what type of control statement is a for loop H . . : used for iteration? module ! contains a set of python commands ! space, tab, return, linefeed, formfeed, , : and vertical tab whitespace what is the benefit of indentation? readability keywords special words in python that indicate } commands to the python interpreter list of keywords and, as, assert, break, exec, is, try, del, elif, else, except, in, return, true, from, global, if, import, raise, def, false, not, or, pass, print, continue, for, none, while, with, yeiled, class, finally, lambda special tokens that implies some operation operators (+,-.,%, 4/1, %, <<, >>, and many more) sequences of characters and tokens language elements that are special in python punctuators/delimiters separate different elements in python statements and expressions P110,:.'=;"#\@ literals a notation for representing a fixed value that cannot be changed in the program ex. integers, floats, strings, booleans rules for naming variables -must begin with letter or underscore -numerals not allowed as beginning : -multiple words linked using underscore : -after first letter, any combination is okay except keywords, delimiters/punctuators or operators expression) is true for loop implements iteration (examining all elements of a collection to perform operations on each element) process of a while loop 1. program enters the while loop and evaluates the boolean exp. 2. if the boolean exp. is true, then the associated while suite is executed 3. at the end of the loop, control flows back to the top, where the boolean is reevaluated. 4. if the boolean is false, then the loop is broken and skipped. a single object that contains multiple collection elements that are associated with the collection object (ex. a string) a collection where there is an order sequence associated with the elements (ex. also a string) set collection that is not a sequence, ! order is not important . collection that can be examined by a iterable for loop (ex. range) what is the value of the boolean value True? what is the value of the boolean value False? is an empty object considered to be True or False? False basic boolean operators and, or, not what does the not operator do? it flips the value of the Boolean operand (converts True to False and vice versa) what does the and operator require to be True? both values (ex. p and q) must be True for the whole expression to be True what does the or operator require to be True? only one value (ex. p or q) must be True for the whole expression to be True boolean translation of "Punch Bill or William" "Punch" and ("Bill" or "William") is an else statement required if you have an elif statement? no relational operator used to check if is two variable names refer to the same object -can be used to immediately exit the execution of the current loop break -useful for stopping computation when the answer has been found if variables have capital letters, what are they usually? constants is there a maximum length for variable names? no what two values are needed to specify a range? the beginning index of the range and the end index of the range, separated by a colon (:) what is the function used to count the : number of characters in a string? len() how do you copy a string? name1 = "Monty" name2 = name’ [:] name2 "Monty" what does for char do to strings? it assigns each individual element of a string to the variable char example of for char for char in "Hi mom": print(char, type (char)) H i m ° m what can strings be multiplied by? integers (ex. x = "Bob" 5, NOT x = "Bob" 5.0, 1.5, etc. concatenation (+) used with at least two string objects, creates a new string object ex. str] = "Hi" str2 =" : str3 = "mom" str1 + str2 + str3 "Hi mom" checks the type of any object type function ex. int type for integers, str type for | strings useful for checking membership in a in operator : collection, returns True or False ex. "a" in "abcd" comparison operators example "abc" < "cde" #difference at index 0 True can you change a particular character in a string? no, strings are immutable ex. str1 = "Hello" str1[0] = "J" ERROR how do you change a string if strings are immutable? you must create a new string through slicing ex. str1 = "Hello" str1 = "J" + str1[1]] str] i Jello" ! asmall program that performs a function specific task t ex. len() variation on a function, is used in method conjunction with a particular object (using dot notation) f floating point : @ floating point expontential ! string.punctuation t string.digits list of predefined strings H : string.whitespace string.ascii_lowercase how do you import predefined import the string module strings? { (import(string)) str1 = "Chapman" For char in index, char in { enumerate(string): print (index, char) are ith enumerate example i s = "Mississippi" how do you reverse a string (through } . ' s[:-1] formatting)? | “ippississiM" what is the formula for basic string {[align][minimum_width][.precision] formatting? | [descriptor}} what does print("X[: | X12.346 Y <10.3f}Y" format(12.345678))?