Docsity

Scripting and Programming Foundations: Q&A, Exams of Advanced Education

Toggle sidebar
bg1
Scripting and Programming -
Foundations - C173
What is an editor? - A program that allows you to write code
What is a compiler? - A program that produces other programs. The compiler does all
the work at once and then runs the new program. We're translating the code we wrote
to computer code all at once. This is often when we produce an .exe (executable) file.
What is an interpreter? - A program that runs code one line at a time. Instead of
converting all of the code at once it runs each line as it's needed. It interprets that
specific line from your code to computer code.
What is an operator and what does it do? - An operator takes two operands (values)
and does something with them. It is an object capable of manipulating a value. If it is a
comparison or logical operator it would compare to see if they are similar or dissimilar. If
it is a mathematical operator it would perform mathematical calculations.
What is an expression? - something that has a value.
What is the difference in a terminal and non-terminal expression? - A terminal is a final
value, while a non-terminal can be reduced further.
What is proper Python grammar for making an expression? - Expression → Expression
Operator Expression
The Expression non-terminal that appears on the left side can be replaced by an
Expression, followed by an Operator, followed by another Expression. For example, 1 +
1 is an Expression Operator Expression.
What is a variable? - a name that refers to a value
What are the three main types of data covered? How do you declare each one? - string
is a sequence of characters surrounded by quotes, either single or double
example: myVar = "string data"
Integer is a number - example: myVar = 33
Boolean is a true or false value - example: myVar = True
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Scripting and Programming Foundations: Q&A and more Exams Advanced Education in PDF only on Docsity!

Scripting and Programming -

Foundations - C

What is an editor? - A program that allows you to write code What is a compiler? - A program that produces other programs. The compiler does all the work at once and then runs the new program. We're translating the code we wrote to computer code all at once. This is often when we produce an .exe (executable) file. What is an interpreter? - A program that runs code one line at a time. Instead of converting all of the code at once it runs each line as it's needed. It interprets that specific line from your code to computer code. What is an operator and what does it do? - An operator takes two operands (values) and does something with them. It is an object capable of manipulating a value. If it is a comparison or logical operator it would compare to see if they are similar or dissimilar. If it is a mathematical operator it would perform mathematical calculations. What is an expression? - something that has a value. What is the difference in a terminal and non-terminal expression? - A terminal is a final value, while a non-terminal can be reduced further. What is proper Python grammar for making an expression? - Expression → Expression Operator Expression The Expression non-terminal that appears on the left side can be replaced by an Expression, followed by an Operator, followed by another Expression. For example, 1 + 1 is an Expression Operator Expression. What is a variable? - a name that refers to a value What are the three main types of data covered? How do you declare each one? - string is a sequence of characters surrounded by quotes, either single or double example: myVar = "string data" Integer is a number - example: myVar = 33 Boolean is a true or false value - example: myVar = True

What is grammar used for in programming? - In a programming language like Python, the code must match the language grammar exactly. When programming language grammar is not followed the interpreter will return a Syntax Error message. This means that the structure of the code is inconsistent with the rules of the programming language. How do you change the value of a variable with Python? - Using the = character to assign a new value x = 6 x = 9 print x # would print out 9 How to do you join multiple variables together with string data in Python? What is this called? - Using the + sign to concatenate the values What does it mean to index a string? How do you do that with Python code? - This is what we call selecting a sub-sequence of a string. You do this in Python by specifying the character you want to access by its index position. Index position begins at 0. For example, this code would print out the letter J: name = 'John' print name[0] What does it mean to slice a string? How do you do that with Python code? - Slicing is simply obtaining a subset of data from a string. You may have also heard this called string extraction. You do this in Python by specifying the index position where you want to begin and where you want to end. Everything from the starting point up until the end point will be extracted. For example, this code would print out "Jo": name = 'John' print name[0:2]

    • concatenate or add = - assignment
    • multiply
    • subtract / - divide % - Modulos, does division and returns the remainder What does the * operator do when applied to string data? - It writes out the string data multiple times. For example, print '!' * 12 would output !!!!!!!!!!!! (12 exclamation points).

(5 + 3) * 8 = 64 because we do the addition first, then multiplication 5 + 3 * 8 = 29 because we do the multiplication first, then the addition. We also use parentheses in procedures to define the inputs to that procedure, which is a very different idea than when working within an expression.. < - less than

  • greater than <= - less than or equal to = - greater than or equal to == - comparisons equality How does the OR operator evaluate two operands? - If has a True value, the result is True and is not evaluated (so even if it would produce an error it does not matter). If has a False value, the result of the or is the value of . How does the AND operator evaluate two operands? - If has a False value, the result is False and is not evaluated (so even if it would produce an error it does not matter). If has a True value, the result of the and is the value of . How are elements in a list indexed? - List elements are assigned an index number starting with 0. What is mutation? Do lists support mutation? - This is the ability to change the value of something. Lists support mutation, allowing you to change the overall length as well as individual elements within the list. How is a for loop constructed in Python? What is its purpose? - A for loop provides a way to execute a block once for each element of a list. The syntax is this: for in : How do you select a sub-sequence of a list with Python? - You specify the index position to begin the selection and the index position by which to stop the selection. For example, the following code would print red and yellow because they are at position 0 and 1.The value of 2 tells us to stop the selection at position 2, but not to include it. myColors = ["red","yellow","blue","orange","green"] print myColors[0:2]

What does the pop method do to a list in Python? - By default it removes the last element from a list. It can also be used with an index number to remove a specific element that is not in last place. For example, the following code would print red, yellow, blue, and orange because pop removed green from the end of the list. myColors = ["red","yellow","blue","orange","green"] myColors.pop() print myColors How would you remove a specific element from a list? - Using the pop method and specifying that specific element's index position. For example, the following code would print red, blue, orange, green because pop removes the color yellow. myColors = ["red","yellow","blue","orange","green"] myColors.pop(1) print myColors How do you update a list item with Python? - By specifying the element that you want to update and then assigning a new value. For example, the following code would change the second element in list, from yellow to purple. myColors = ["red","yellow","blue","orange","green"] myColors[1] = "purple" print myColors If your Python list contains multiple lists, how do you locate a specific value? - By specifying the elements using index positions to first select the sub-list, then the element within the sub-list. For example, the following code would select the value red: favColors= [['jessica','red'], ['grace','yellow'], ['john','blue']] print favColors[0][1] What does the append operator do to a list? - Mutates a list by adding elements to the end of the list. The following code would print out the list of red, yellow, blue, orange, green, and purple. myColors = ["red","yellow","blue","orange","green"] myColors.append("purple") print myColors What is an object? - Something that has its own identity and characteristics, separate from other objects.

What are the differences in a hashed search and a linear search? - A linear search goes through each entry one at a time to see if the search word matches the word you are looking for. With a large index and lots of queries this will be a very slow process. A hashed search maps those entries to a number, or keyword, and places those into buckets. This way you know which bucket to start looking at for a particular entry instead of looking through all of the entries. A hashed search is much like looking at the index in the back of a book; if you are looking for "pineapples" you don't have to start at the beginning and read each entry A- P, you can jump to the words that begin with P and start looking there. In this example the letter P would be the bucket that the entry pineapple is placed in. How are buckets used in a hash table? What effect do they have on lookup speed? - Entries in a hash table are mapped to a number, which is the position in the index where you should look for the entry. A hash table has numbered bucket slots that hold entries. The entries are organized in the buckets based on their assigned keyword number. When you run a search using a hash table the keyword assigned will be used to determine which bucket the entry should be located in and begin the search there. Because the search knows where to begin looking it is much quicker to look up items. Which storage method covered in this course ensures the fastest access to data? - A hash table, or dictionary What is an algorithm? - A well-defined sequence of steps (known as a procedure) that will always finish and produce the right results. The algorithm must finish in order for us to analyze efficiency. What is the difference in a procedure and an algorithm? - A procedure and algorithm are both a set of instructions that will be executed in order. The difference is that an algorithm must return a value. A procedure, or function, that does not return a value may not be considered an algorithm. What are circular definitions? - A definition that constantly calls itself. Because it lacks a base case it has no way to stop. It is stuck in a loop with a reference pointing to another reference that never resolves. These types of definitions are largely helpful in mathematical application. What is a recursive definition? - When a function calls itself, it is recursion. If a function is calling itself, it would be stuck in a loop forever unless we have a condition that would allow the recursion to stop. A recursive definition needs to have two parts: the recursive case and the base case. The base case must be something that you already know the answer for and not need to do anything to work it out. This is what allows us to eventually stop running the definition. The recursive case is when the function is calling

itself to run again. The recursive case is defined in terms of itself, but in terms of a smaller version of itself, as progress must be made towards the base case. When would you use recursion? - To allow us to define infinitely many things using a few simple rules. A simple definition can be used to expand on something much more complex. This involves breaking a problem down into smaller and smaller subproblems until you get to a small enough problem that it can be solved trivially. For example, you could define ancestory = person 1 + ancestors. If you are person 1, your ancestors would be your parents, but they are not your only ancestors. Your parents have parents, but those are still your ancestors. Your grandparents had parents, and so on. A very simple definition can execute with multiple layers and a much more complex value. What three rules must a recursive algorithm obey? - It must have a base case which allows it to eventually end. It must change its state and move towards the base case. It must call itself recursively. What do we mean when we talk about the cost of an algorithm? - An algorithm's cost is related to the resources that it requires to execute. The primary way cost is discussed is related to the size of the input. Larger inputs usually mean more resources, so this is the main factor that determines the speed. Ultimately this determines the amount of time it takes the algorithm to execute and the amount of memory required to run it. The process of calculating this is called algorithm analysis. What are the two most important factors that affect the cost of an algorithm? - Time and memory. Time is the more important factor. How do you prioritize case (best case, worst case, average case) when analyzing algorithms? - You would look at them in this order: Worst case, average case, best case. The worst case is the most important because this will give you a better understanding of why the time scales as it does. What is time.clock used for? - To check when an algorithm begins and when it ends so that we can determine the run time. This performs benchmarking, which is simply assessing the relative performance of an object. What is UML? - Unified Modeling Language. This is a graphical notation specifically for drawing diagrams of an object-oriented system. What are the 5 steps in the UML design process? In which steps do use case, use case diagrams, and class diagrams take place? - 1.Gather Requirements

  1. Describe the Application (use case and use case diagram)
  2. Identify the main objects

What is the main difference in compiled and interpreted code? - The main difference is when the code is converted to machine language. A compiled language converts all of the code at one time, before the code is run by the machine, and saves this into a new file. That new file is now machine code, and is not editable. An interpreted language still needs to convert to machine language in order for the computer to understand it, but it does this at the time that the code is executed. The original programming language is preserved, so it is editable. What does it mean if a programming language is object oriented? - An object oriented programming language that is organized around objects or classes, rather than "actions". Object-oriented programming takes the view that what we really care about are the objects we want to manipulate rather than the logic required to manipulate them. Which of these programs is object-oriented: - Java, .NET & C#, Ruby, Python, Objective-C C is not object-oriented. It is a procedural language. What are each of these programming languages best used for: Objective-C - apple development What are each of these programming languages best used for: Python - cross-platform language, used for web apps, embedded scripting language inside other applications What are each of these programming languages best used for: Ruby - cross-platform language, used for small utilities and web apps What are each of these programming languages best used for: .Net C# - windows platforms (desktop, mobile, or web) What are each of these programming languages best used for: Java - cross-platform language, used for desktop applications and android mobile applications What are each of these programming languages best used for: C - games, utilities, embedded systems, operating systems