Docsity

Scripting and Programming Foundations: C173 - Introduction to Python, Exams of Computer Science

Toggle sidebar
bg1
1 / 15
Scripting and Programming - Foundations - C173
1.What is an editor? A program that allows you to write code
2.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.
3.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.
4.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.
5.What is an expression? something that has a value.
6.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.
7.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.
8.What is a variable? a name that refers to a value
9.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"
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Scripting and Programming Foundations: C173 - Introduction to Python and more Exams Computer Science in PDF only on Docsity!

1 / 15

Scripting and Programming - Foundations - C

1. What is an editor? A program that allows you to write code

2. 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.

3. 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.

4. 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.

5. What is an expression? something that has a value.

6. 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.

7. 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.

8. What is a variable? a name that refers to a value

9. 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"

2 / 15

10. Integer is a number: example: myVar = 33

11. Boolean is a true or false value: example: myVar = True

12. 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.

13. 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

14. How to do you join multiple variables together with string data in Python? What is

this called?: Using the + sign to concatenate the values

15. 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]

16. 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'

4 / 15 You can only access data from within a function if you return that specific data to be used outside of the function.

31. How is a while loop constructed in Python? What is its purpose? executes any

number of times, continuing as long as the test expression is True while :

32. How is an if else statement constructed in Python? What is its purpose?: - provides

a way to control what code executes based on the result of a test expression if : <block

else:

33. How are compound mathematical expressions evaluated in Python?: First perform

calculations within parentheses. Next work left to right and perform all multiplication and division. Finally, work left to right and perform all addition and subtraction

34. What is the function of parentheses, (), in programming expressions? - When we

are working with an expression, they group items within that expressions. Items within parentheses are evaluated first. For example: (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.

35. <: less than

36. >: greater than

37. <=: less than or equal to

38. >=: greater than or equal to

5 / 15

  1. ==: comparisons equality

40. 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 .

41. 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 .

42. How are elements in a list indexed? List elements are assigned an index

number starting with 0.

43. 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.

44. 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 :

45. 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

7 / 15 value red: favColors= [['jessica','red'], ['grace','yellow'], ['john','blue']] print favColors[0][1]

50. 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

51. What is an object?: Something that has its own identity and characteristics,

separate from other objects.

52. What three things describe an object in object-oriented programming

languages?: identity, attributes, and behavior

53. What is a class? How do you define a class in Python?: A class describes what

an object will be, but it isn't the object itself. A class is a blueprint, a detailed description, a definition of an object. The syntax for creating a class in Python is: class ():

54. Why would we create a class?: To create a blueprint upon which to build

multiple objects that share attributes and behaviors

55. What is the difference in an object and a class?: An object is something that has

its own identify and characteristics, separate from other objects. A class describes that object will be, but it isn't the object itself. For example, a house is an object and the blueprints used to create it would be considered the class.

56. How do you use dot notation to access an attribute of a class?: You list the

8 / 15 individual object's name that is an instance of the class, a dot, and then the attribute name. For example myClass.color would access the color associated with the object myClass.

57. What is instantiation?: Creating instances of a class

58. What is abstraction?: Focus on the essential qualities of something rather than

one specific example. For example, if I say a table you have an idea of what I mean even though I didn't say if it was wood/glass or big/small. This is the essential idea behind creating classes.

59. What is encapsulation? Surrounding something, not just to keep the contents

together, but also to protect those contents. Restricts access to the inner workings of a class or any objects based on that class; this is referred to as information hiding or data hiding.

60. What is inheritance? How does inheritance apply to working with class- es?: A

form of code reuse. We can create a new class, but instead of writing it from scratch, we can base it on an existing class. It would inherit some of the characteristics of the base class but could also have its own unique properties and methods that are not shared with the base class.

61. What is polymorphism? How does polymorphism apply to working with classes?:

Means many forms. It lets us automatically do the correct behavior even if what we're working with could take one of many different forms. The + is a great example. If we're adding two variables together with the plus sign, and these variables are integers, it will numerically add them. But if they are two strings it will concatenate them. With classes this allows us to work with objects created from different classes.

62. 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

10 / 15 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.

68. 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.

69. 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.

70. 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.

71. 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

11 / 15 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.

13 / 15 accomplish something.

80. What must be true of entities for them to be considered actors in a use case?: As

long as an entity exists outside of the described system it can interact with the system. In this case the entity can accomplish something within the system and is considered an actor.

81. What is a scenario in a use case?: This is how the actor accomplishes the

activity or goal.

82. What does a use case diagram provide? What is the purpose of creating a case

diagram?: The use case diagram allows you to look more broadly at the requirements of an application by visualizing several use cases and multiple actors at the same time.

83. What does a class diagram provide? What is the purpose of creating a class

diagram?: A class diagram is a visual representation of classes needed. Its most basic structure defines the class name, attributes that it will have, and operations, or methods. This is also where you define inheritance and polymorphism. It allows you to plan out the classes that you will create and their basic structure so that when you translate this to code you know what is needed.

84. What is a programming library? Why are libraries useful?: A programming library

is simply code that is already written, already tested, and ready for you to link to and use. These can greatly reduce the amount of time to write code.

85. What is a compiled programming language?: You write your source code and then

a compiler goes through the code and creates a separate file that contains the machine code. This separate file is an executable file because the computer can directly execute it. All of the code is converted at once and the new compiled file is no longer editable.

86. What is an interpreted programming language?: An interpreted language does

the conversion from source code to machine code on-the-fly. There is no

14 / 15 separate machine code file. The computer executes each line when it is needed. This means that all of the code is saved in a format that is editable programming language.

87. 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.

88. 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.

89. Which of these programs is object-oriented: Java, .NET & C#, Ruby, Python,

Objective-C C is not object-oriented. It is a procedural language.

90. What are each of these programming languages best used for: Objec- tive-C:

apple development

91. What are each of these programming languages best used for: Python: - cross-

platform language, used for web apps, embedded scripting language inside other applications

92. What are each of these programming languages best used for: Ruby: -

cross-platform language, used for small utilities and web apps