The document outlines key concepts in computer science, including computational theory, applications, and discovery, as well as programming fundamentals like algorithms, data types, and control structures. It explains the roles of functions, libraries, and error handling in programming, along with hardware components and circuit design principles. Additionally, it covers loop structures, string manipulation, and the importance of scope in programming languages.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
3 views3 pages
Notes Exam 1
The document outlines key concepts in computer science, including computational theory, applications, and discovery, as well as programming fundamentals like algorithms, data types, and control structures. It explains the roles of functions, libraries, and error handling in programming, along with hardware components and circuit design principles. Additionally, it covers loop structures, string manipulation, and the importance of scope in programming languages.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3
CS: study of computation and computational devices.
● Computational theory – what are the possibilities and limitations of computation?
● Computational application – how can we use computation to fulfill a specific need? ● Computational discovery – given data, can we find patterns and answer questions through computation? ● Computational expression – how can computation change the way we communicate and engage with others? ● Critical computing – how does computation affect our lives, and how should it be regulated? ● Computation: algorithms and abstraction Algorithms: procedures that specify how to do a task. Standardize processes and permit comm ● Represented as program code with an input, output, and steps Abstraction: technique to make complex systems manageable by changing detail Programing languages: use diff syntax but same algorithms ● Interpreter converters text into instructions the computer runs ● Data: info that can be changed and kept track of (numbers, text, truth values) ○ Combined using operations Strings: can be repeated using mult. with an integer Errors: syntax errors show an inline arrow, for other errors, read the message ● 1. Line number 2. Error type 3. Maybe inline 4. Maybe error message ● Python first has to break your text down into tokens, then structure those tokens into a format that the computer can execute. ● Special syntax errors: indentation and incomplete ● Runtime: name, error, zero div ● An assert statement takes a Boolean expression. If the expression evaluates to True, the statement does nothing. If it evaluates to False, the program crashes. Program state: how python keeps track of data Statement: action taken by the program that can change the program state. Executes a change ● Expressions evaluates to a data value Number system: rep # with symbols Function: code construct that reps an algorithm. Core action that is repeated ● Input: displays, type, store ● Typecasting: change type of data value ● 1. Name ● 2. Argument ● 3. Return ● 4. Side effect Argument: value inside parentheses, input Returned value: what the function returns, output ● Functions evaluate to 1 return value; they are an expression, so can be nested ● Sometimes functions changes the program state: side effect Libraries: prebuilt functions Local scope: variables in function definitions (including parameters) are only accessible within that function. Global scope: variables at the global (top) level are accessible at the top-level, and by any function. Kwargs: argument associated with a specific name instead o a position in the function call. Can have default value Parameters: abstracted arguments Control flow: order statements are executed ● Redirected when function is called Conditional statement: control structure that allows you to make choices in a program. ● 1 if, 0 or more elif, 1 or 0 else ● Joined clauses are one control structure Software: the abstracted concepts of computation- how computers represent data, and how programs can manipulate data. Hardware: the actual physical components used to implement software, like the laptop components shown to the right. Half-adder: a circuit that takes two one-digit binary numbers, adds them, and outputs two digits as the result Full adder: a circuit that takes two one-digit binary numbers and a carried-in digit, adds all three, and outputs two digits as the result Inputs: X and Y are single digits of the numbers being added. C_in is the number carried from the previous addition. Outputs: Sum is the right digit of the result; C_out is the left digit, which will be carried to the next addition. N-bit adder: a circuit that takes two n-bit numbers, adds them together by chaining together n full adders, and outputs a n+1-digit result While loops: need start value, an update action, and a continuing condition. ● This changing part will be created by the loop control variable, which is updated in the loop body. We want to start the variable at x and continue while the variable is less than or equal to y. ● a control structure that lets you repeat actions while a given Boolean expression is True ● Loop control variable: a variable used to manipulate the number of times a loop iterates. Requires a start value, update action, and continuing condition. ● If we call input inside the loop body, we can get multiple inputs from the user and process them like a data stream. ● result = 0 value = input("Enter a number, or q to quit:") while value != "q": num = int(value) result = result + num value = input("Enter a number, or q to quit:") ● Loop control variable: which power of 10 is being checked Start value: 1 (100 ) Continuing condition: while the power of 10 isn't greater than the number Update action: multiply the power by 10 num = 2021 power = 1 digits = 0 while power < num: digits = digits + 1 power = power * 10 print(digits) OR num times u can divide by 10 print("Total sum:", result) For loop: a control structure that lets you repeat actions a specific number of times ● You usually use a while loop when you don’t know how many iterations are going to occur. You can always convert a for loop into a while loop but not the other way around. ● Range: a function that generates values for the loop control variable in a for loop. Can take 1-3 inputs ○ range Generates Loop Variable Values, consec. Values for the loop control var ● def isPrime(num): if num < 2: >return False <for factor in range(2, num): >if num % factor == 0: >return False <<return True ● In nested loops, the inner loop is repeated every time the outer loop takes a step Strings: real text data is modular- you can break it up into sentences, words, letters "ABC\nDEF" # '\n' = newline, or pressing enter/return "ABC\tDEF" # '\t' = tab The \ character is a special character that indicates an escape sequence. It is modified by the letter that follows it. These two symbols are treated as a single character by the interpreter. Slice: access a subsequence of a larger sequence based on a given start, end (not inclusive), and step Index: access a specific value in a sequence based on its position. Positions start at 0 and end at len(seq)-1. Non-existent indexes result in IndexError.