
































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A foundational introduction to programming essentials in python, covering key concepts such as language fundamentals, data types, operators, and basic programming constructs. It explores the differences between high-level programming languages and machine language, delves into the concepts of compilation and interpretation, and introduces the python interpreter. The document also covers basic data types like integers, floats, and booleans, along with operators for performing mathematical operations. It provides a clear explanation of variables, identifiers, and assignment operators, laying the groundwork for writing simple python programs.
Typology: Exams
1 / 40
This page cannot be seen from the preview
Don't miss anything!

































language - Answer means/tool for expressing and recoding thoughts computer's language? - Answer machine language natural languages - Answer languages where new words are created every day and old words disappear 4 aspects of a language - Answer alphabet, lexis, syntax, semantics alphabet - Answer set of symbols used to build words of a certain language lexis - Answer aka a dictionary or a set of words the language offers its users syntax - Answer a set of rules (formal or informal) used to determine if a certain string of words forms a valid sentence semantics - Answer a set of rules determine if a certain phrase makes sense (I ate a donut vs a donut ate me) Instruction List (IL) - Answer a complete set of known commands; the alphabet of the machine language (they vary by size and what they contain) source code - Answer a program written in a high-level programming language (in contrast to the machine code executed by computers) source file - Answer contains source code
two different ways of transforming a program from a high-level programming language into machine language - Answer compilation and interpretation compilation - Answer source program is translated once (must be repeated each time you modify the source code) by getting a file containing the machine code; now you can distribute the file worldwide. The program that performs this translation is called a compiler or translator interpretation - Answer a user can translate the source program each time it has to be run; the program performing this kind of transformation is called an interpreter, as it interprets the code every time it is intended to be executed compilation advantages - Answer -Execution of the translated code is usually faster -Only the user has to have the compiler, end user may use code without it -Translated code is stored using machine language - because machine language is hard to understand, this makes your own inventions/programming tricks likely to remain secret compilation disadvantages - Answer -Compilation itself maybe be very time consuming; you might not be able to run code immediately after any change -You have to have as many compilers as hardware platforms you want your code to be run on interpretation advantages - Answer -You can run the code as soon as you complete it; no additional phases of translation -Code is stored using programming language, not the machine one, which means it can be run on computers using different machine languages -You dont compile your code separately for each different architecture
Error Codes - Answer traceback, location of the error (Python shows the place where it first notices the effects of the error, not necessarily the error itself), content of the erroneous line, name of the error What kind of language is Python? - Answer a high-level programming language (not a machine language or a natural language) interpreter - Answer A computer program that directly executes instructions written in a programming language literal - Answer data whose values are determined by the literal itself and are used to encode data and put them into your code (123 is literally one hundred and twenty-three while C can = anything, so 123 is literal but C is not) two types of numbers - Answer integers and floats type () - Answer determines the kind, range, and application of the numeric value octal value prefix - Answer integer preceded by an 0o; must contain digits taken from 0....8 range only hexadecimal value prefix - Answer 0x (16 as its base) escape character - Answer \ (backslash); signifies that the character after the \ has a different meaning binary system - Answer is a system of numbers that employs 2 as the base. Therefore, a binary number is made up of 0s and 1s only, e.g., 1010 is 10 in decimal.
Integers (or simply ints) - Answer Integers (or simply ints) are one of the numerical types supported by Python. They are numbers written without a fractional component, e.g., 256, or -1 (negative integers). Floating-point numbers (or simply floats) - Answer Floating-point numbers (or simply floats) are another one of the numerical types supported by Python. They are numbers that contain (or are able to contain) a fractional component, e.g., 1.27. Boolean values - Answer are the two constant objects True and False used to represent truth values (in numeric contexts 1 is True, while 0 is False. Classify these literals ("1.5", 2.0, 528, False) - Answer string, numerical literal float, numerical literal int, boolean literal operator - Answer Operators are special symbols or keywords which are able to operate on the values and perform (mathematical) operations, e.g., the *operator multiplies two values: x * y.
-Evaluate a value or some values (the square root of a value)That is, a function may have an effect or a result components of functions - Answer an effect, a result, an argument within () newline - Answer empty line of code newline character - Answer \n positional arguments - Answer meaning of the argument is dictated by tis position (the second argument comes after the first and so on) keyword arguments - Answer meaning of arguments is taken not from location (position) but from the special word (keyword) used to identify them; has to be after the last positional argument; consist of 3 elements - 1. the keyword identifying hte argument 2. an = sign 3. a value assigned to that argument keyword arguments - Answer end= sep= (choose what you separate everything by) print () - Answer a built-in function that prints/outputs a specified message to the screen/consolewindow variable - Answer a named location reserved to store values in the memory. A variable is created or initialized automatically when you assign a value to it for the first time (length = 5)
identifier - Answer a variable's unique name; A legal identifier name must be a non-empty sequence of characters, must begin with the underscore(_), or a letter, and it cannot be a Python keyword. The first character may be followed by underscores, letters, and digits. Identifiers in Python are case-sensitive. assignment operator - Answer = (assigns the value of the right argument to the left) compound assignment operators - Answer shortcut operators that modify values assigned to variables j=j+2k ...j +=2k round () - Answer rounds the outputted result to the number of decimal places specified in the parenthesis, and return a float round(miles_to_kilometers,1) comment - Answer a remark inserted into the program, which is omitted at runtime (begins with a #) input () - Answer Able to read data enter by the user and to return the same data to the running program; program then can manipulate the data, making the code truly interactive deaf program - Answer a program which doesn't get a user's input int () - Answer takes one argument (eg a string, int(string)) and tries to convert it to an integer; if it fails, the whole program will fail too
= - Answer greater than or equal to operator. the non-strict variant of > < - Answer the less than operator <= - Answer less than or equal to operator. the non-strict variant of < priority table - Answer 1. +, - (unary)
-else says what to do if the condition specified for the if is not met nesting - Answer every else refers to the if which lies at the same indentation level elif statement - Answer a conditional statement that: -checks more than just one condition -stops when the first statement which is true is found; "otherwise" cascade - Answer the way to assemble subsequent if-elif-else statements -else can only exist if there is an if -else is the last branch of the cascade -else is optional pseudocode - Answer Shorthand notation for programming which uses a combination of informal programming structures and verbal descriptions of code. loop - Answer performing a certain part of the code more than once max () - Answer built in function that finds the max of the variables in the parenthesis min () - Answer built in function that finds the min of the variables in the parenthesis <, <=, >, >= - Answer comparison or relational operators (they compare values)
else clauses with while and for loops - Answer are always executed after the loop finishes its execution, as long as the loop has not been terminated by a 'break' if versus while statements - Answer if performs statements only once; the while statement is repeated as long as the condition evaluates to True loop's body - Answer an instruction or set of instructions executed inside the while loop; should aim to change the condition's value or else it could run indefinitely endless (infinite) loop - Answer a sequence of instructions in a program which repeat indefinitely another way to write number % 2 == 1 - Answer number % 2: another way to write while number != 0 - Answer while number: counter variable - Answer tells how many times to run a loop how many times will this code run counter = 5 while counter != 0 print("blah") counter -= 1 - Answer 5 times
range() - Answer generates a sequence of numbers. It accepts integers and returns range objects. starts from 0 and ends one value before the value of its argument Syntax of the range function - Answer range(start, stop, step) where start specifies the start of the sequence (0 by default), stop specifies the end of the sequence (it is not included), and step specifies the increment (1 by default) output? for i in range(6,1,-2) - Answer 6,4, Syntactic candy (or sugar): - Answer additions to code which dont improve the language's expressive power, but simplify the developer's work output? for i in range(5): print(i) else: print("else:", i) - Answer 0 1 2 3 4 Else: 4 output? i = 111 for i in range(2, 1): print(i)
& - Answer bitwise conjunction operator; requires two 1's to provide 1 as the result; "and" | - Answer bitwise disjunction operator; requires at least one 1 to provide 1 as the result; "or" ^ - Answer bitwise exclusive or (xor); requires exactly one 1 to provide 1 as the result ~ - Answer bitwise negation logical vs. bitwise operators - Answer -logical operators do not penetrate into the bit level of its argument; they're only interested in the final integer value -Bitwise operators are stricter: they deal with every bit separately bit mask - Answer a sequence of zeros and ones, whose task is to grab the value or to change the selected bits shifting - Answer only applied to integer values and single bits shift operators - Answer << and >>; The left argument of these operators is an integer value whose bits are shifted. The right argument determines the size of the shift. (Not commutative) Commutative operations - Answer a × b = b × a (doesn't matter the order you put the variables in)
a one bit shift to the left/right - Answer 2, / a two, three, four bit shift to the left/right - Answer 4,8, /4, /8, / Scalar - Answer variable that stores exactly one given value at a time Multi-value - Answer variables that can hold more than one value at a time what index does an item stored at the beginning of a list have? - Answer 0 Index - Answer the value inside the brackets which selects an element of the list by its position; can be any expression Indexing - Answer operation of selecting an element from the list len() - Answer takes the list's name as an argument and returns the number of elements currently stored inside the list del - Answer an instruction, not a function, that removes elements from a list, thus decreasing the list length del numbers[1] - Answer delete the element that is numbered 1 in a list called numbers numbers[-1] - Answer goes to the last position in the last
Swapping values in Python - Answer use commas to delineate variables to be switched Variable1 = 1 /Variable2 = 2 /Variable1, Variable2 = Variable2, Variable Syntax to create an empty list - Answer myList = [] list - Answer a type of data in Python used to store multiple objects. It is an ordered and mutable collection of comma-separated items between square brackets for j in myList - Answer j is the control variable of the loop, where the in keyword introduces a syntax element describing the range of possible values being assigned to j bubble sort - Answer compares adjacent elements, using swapping to achieve a goal sort() - Answer a method that sorts lists as fast as possible Reverse() - Answer a method that reverses a list Slice - Answer an element of Python syntax that allows you to make a brand new copy of a list or parts of a list [ : ] - Answer copies a list's entire contents, not the list's name [start : end] - Answer start is the * start is the index of the first element included in the slice; end is the index of the first element not included in the slice
elem in mylist/elem not in mylist - Answer The first of them (in) checks if a given element (its left argument) is currently stored somewhere inside the list (the right argument) - the operator returns True in this case; The second (not in) checks if a given element (its left argument) is absent in a list - the operator returns True in this case. myList = [1, 2, 3, 4, 5].....del myList[0:2] - output? - Answer [3, 4, 5] Array - Answer list in a list List comprehension - Answer a list that is created on-the-fly during program execution, and is not described statically; row = [WHITE_PAWN for i in range(8)] Matrix - Answer two-dimensional array; board = [[EMPTY for i in range(8)] for j in range(8)] how to find an element of a matrix - Answer use coordinates, a vertical one (row number), a horizontal one (column number) decomposition - Answer when a coder divides the code into well isolated pieces, encoding each of them in the form of a separate function Syntax of defining a function - Answer def functionName(optional parameters): functionBody two rules for functions - Answer 1. You mustn't invoke a function which is not known at the moment of invocation. 2. You mustn't have a function and a variable of the same name