Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Python Programming Fundamentals: A Comprehensive Guide to Basic Concepts and Syntax, Exams of Computer Engineering and Programming

A comprehensive introduction to fundamental python programming concepts, covering essential elements like variables, data types, operators, expressions, control flow structures (loops and conditional statements), functions, and lists. It explains key concepts with clear examples and addresses common programming challenges, making it a valuable resource for beginners learning python.

Typology: Exams

2024/2025

Available from 03/05/2025

Examprof
Examprof 🇺🇸

4.1

(24)

2.8K documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
What is an editor? - ANSWER A program that allows you to write code
What is a compiler? - ANSWER 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? - ANSWER 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? - ANSWER 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? - ANSWER something that has a value.
What is the difference in a terminal and non-terminal expression? - ANSWER A terminal is a final value,
while a non-terminal can be reduced further.
What is proper Python grammar for making an expression? - ANSWER 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.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Python Programming Fundamentals: A Comprehensive Guide to Basic Concepts and Syntax and more Exams Computer Engineering and Programming in PDF only on Docsity!

What is an editor? - ANSWER A program that allows you to write code

What is a compiler? - ANSWER 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? - ANSWER 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? - ANSWER 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? - ANSWER something that has a value.

What is the difference in a terminal and non-terminal expression? - ANSWER A terminal is a final value, while a non-terminal can be reduced further.

What is proper Python grammar for making an expression? - ANSWER 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? - ANSWER a name that refers to a value

What are the three main types of data covered? How do you declare each one? - ANSWER string is a sequence of characters surrounded by quotes, either single or double

example: myVar = "string data"

Integer is a number - ANSWER example: myVar = 33

Boolean is a true or false value - ANSWER example: myVar = True

What is grammar used for in programming? - ANSWER 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? - ANSWER 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? - ANSWER Using the + sign to concatenate the values

What does it mean to index a string? How do you do that with Python code? - ANSWER 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:

What is the difference in a procedure and a function? - ANSWER A procedure and a function in python are the same so there is no difference. They both take inputs and may or may not return outputs.

What is a parameter? - ANSWER Input to a procedure or function

What is the difference in an input, an operand, and a parameter? - ANSWER Nothing! They are all different names used to describe inputs to a procedure.

What are the advantages of using a function? - ANSWER Functions can be used multiple times. They provide a modular piece of code that only has to be written once and then can be called upon multiple times within the program.

When does a function execute? - ANSWER When you explicitly ask it to execute by calling the function and passing in any parameters. We refer to this as invoking or calling the function.

How do you define outputs for a function? - ANSWER Using the return keyword you can define what data will be returned or output when the procedure or function runs. You can only access data from within a function if you return that specific data to be used outside of the function.

How is a while loop constructed in Python? What is its purpose? - ANSWER executes any number of times, continuing as long as the test expression is True

while :

How is an if else statement constructed in Python? What is its purpose? - ANSWER provides a way to control what code executes based on the result of a test expression

if :

else:

How are compound mathematical expressions evaluated in Python? - ANSWER 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

What is the function of parentheses, (), in programming expressions? - ANSWER 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..

< - ANSWER less than

  • ANSWER greater than

<= - ANSWER less than or equal to

= - ANSWER greater than or equal to

== - ANSWER comparisons equality

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? - ANSWER 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? - ANSWER 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? - ANSWER 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? - ANSWER 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? - ANSWER Something that has its own identity and characteristics, separate from other objects.

What three things describe an object in object-oriented programming languages? - ANSWER identity, attributes, and behavior

What is a class? How do you define a class in Python? - ANSWER 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 ():

Why would we create a class? - ANSWER To create a blueprint upon which to build multiple objects that share attributes and behaviors

What is the difference in an object and a class? - ANSWER 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.

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? - ANSWER 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? - ANSWER A hash table, or dictionary

What is an algorithm? - ANSWER 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? - ANSWER 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? - ANSWER 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? - ANSWER 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? - ANSWER 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 sub problems until you get to a small enough problem that it can be solved trivially. For example, you could define ancestor = 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? - ANSWER 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? - ANSWER 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? - ANSWER Time and memory. Time is the more important factor.

How do you prioritize case (best case, worst case, average case) when analyzing algorithms? - ANSWER 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? - ANSWER 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 does a use case diagram provide? What is the purpose of creating a case diagram? - ANSWER 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.

What does a class diagram provide? What is the purpose of creating a class diagram? - ANSWER 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.

What is a programming library? Why are libraries useful? - ANSWER 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.

What is a compiled programming language? - ANSWER 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.

What is an interpreted programming language? - ANSWER An interpreted language does the conversion from source code to machine code on-the-fly. There is no 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.

What is the main difference in compiled and interpreted code? - ANSWER 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? - ANSWER 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: - ANSWER Java, .NET & C#, Ruby, Python, and Objective-C

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

What are each of these programming languages best used for: Objective-C - ANSWER apple development

What are each of these programming languages best used for: Python - ANSWER cross-platform language, used for web apps, embedded scripting language inside other applications

What are each of these programming languages best used for: Ruby - ANSWER cross-platform language, used for small utilities and web apps

What are each of these programming languages best used for: .Net C# - ANSWER windows platforms (desktop, mobile, or web)

What are each of these programming languages best used for: Java - ANSWER cross-platform language, used for desktop applications and android mobile applications

What are each of these programming languages best used for: C - ANSWER games, utilities, embedded systems, operating systems