Ryan's Midterm Study Guide Flashcards

Covers Lectures 1-7 (Variables, Conditions, Loops, Strings, Lists, and Debug)

1
Q

What are the main characteristics of an interpreted programming language? (module 1)

A

You (or any user of the code) 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; it also means that you cannot just distribute the source code as-is, because the end-user also needs the interpreter to execute it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What kind of programing language is python? (module 1)

A

Python is a high level, interpreted, object oriented programming language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Who created Python? (module 1)

A

Guido van Rossum

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Name some advantages of using an Interpreted programming language. (module 1)

A

You can run the code as soon as you complete it - there are no additional phases of translation.

The code is stored using programming language, not the machine one - this means that it can be run on computers using different machine languages; you don’t compile your code separately for each different architecture.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Name some disadvantages of using an interpreted programming language. (module 1)

A

Not as fast as a compiled program. Interpreted code runs at the speed that your computers power allows.

Both you and the end user have to use an interpreter to run your code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the goals of python as a programming language? (module 1)

A
  1. Python should be easy and intuitive to use, but still as powerful as other competing languages.
  2. Python should remain open sourced. Anybody should be allowed to contribute to its development.
  3. Python code should be understandable as plain English.
  4. Python must be suitable for everyday tasks, and allow for shorter development times.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What differentiates python from other high-level programming languages? (module 1)

A

Python is easy to learn, teach, use, understand, and obtain.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Define functions and arguments. (module 2)

A

Functions are lines in python that are made to cause an effect, or evaluate a value.

Arguments are found inside a functions parentheses. There are many different types of arguments in Python. They are necessary for functions to work.

Generally, functions in python will look something along the lines of this:

function_name(argument)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Describe the importance of using quotation marks while using the print() function. (module 2)

A

When you use quotations, the print function will print exactly what you type in between them. This creates something known as a string.

If you do not use quotation marks, the program will try to print a variable assigned to the text inputted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you separate arguments inside of a function? (module 2)

A

Inside of the brackets, you can separate arguments using commas.

ex. print(“Hello, my name is”, input)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Define literals. (module 2)

A

A literal is data whos values are determined by the literal itself.

Literals can be used to encode your data and put it directly into your code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Define integers and floats. (module 2)

A

Integers are whole numbers that do not include fractional parts. (ex. 1)

Floats (aka floating point numbers) that are able to contain fractional parts. (ex. 1.0)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are Boolean values? (module 2)

A

Boolean values are the two constant objects True and False used to represent truth values in numeric contexts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are operators? (module 2)

A

Operators are symbols in programming language which are used to operate on values.

Data and operators when put together in a line become an expression.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

List and define some basic arithmetic operators. (module 2)

A

”+” Addition
“-“ Subtraction
“*” Multiplication
“/” Division
“**” Exponent
“//” integer divisional (the result of the division will always be an integer)
“%” calculates the remainder after integer division.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are variables? (module 2)

A

Variables are like boxes that store the results of an operation. Each value consists of two parts:
A name
The value of what is placed inside of it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are the rules for naming variables? (module 2)

A

The name must be composed of upper or lower case letters.
The name must begin with a letter
The underscore character acts as a letter when naming variables
Names are case sensitive
Names of variables can not match any of Pythons built in key words.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How do you create a variable? (module 2)

A

A variable is created when you assign a value to it. You do so using the “=” assignment operator.

Ex.
var = 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Describe shortcut operators. (Module 2)

A

Shortcut operators can change variables without the need to write the entire expression out again.

For example.

Instead of writing x = x + 1
You can use a shortcut operator and compress this expression into:

x += 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How do you leave a comment in a code? (module 2)

A

This is a comment Example

You use hashtags to surround the comment. They can be left on any line as long as the hashtags are present.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Describe the input() function. (module 2)

A

The input function allows a program to take user inputted data and use it in the code. The argument in an input function is a string designed to prompt the user to input a message.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is the result of an input function? (module 2)

A

The result unless otherwise stated will always be a string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How do you convert inputs into variables? (module 2)

A

You have to indicate that the input will be a float or an integer when writing the line of code, and assign it a variable.

Example:

var = float(input(“Enter a number:”))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is the concatenation operator, and how does it function? (module 2)

A

If you place a “+” between two strings it becomes the concatenation operator.

The concatenation operator takes two strings and turns them into a single string.

25
Q

What is the replication operator, and how does it function? (module 2)

A

The replication operator is “*” when applied to a string and a number.

When a replication operator is applied, it replicates the string by the number that you use.

For example:

3 * string
Output:
stringstringstring

26
Q

What is the str() function? (module 2)

A

The str() function is used for converting a number into a string.

27
Q

What are the comparison operators, and what is their function? (module 3)

A

The equality operator is “==”, not to be confused with the assignment operator “=”.

The other comparison operators are greater than “>” less than “=” and not equal to “!=”

Comparison operators generate a true or false response based on the variables they are comparing.

28
Q

Describe “if” conditional statements. (module 3)

A

If statements generate specific results if certain conditions are met. They are based around true or false statements.

All if statements must be followed by a colon: and the set of instructions listed underneath must be indented.

29
Q

What happens if an expression does not meet the conditions of an “if” statement? (module 3)

A

Unless instructed to do otherwise, the instructions of the “if” statement will be skipped, and the code will continue.

30
Q

Describe “if-else” conditional statements. (module 3)

A

Adding “else” after an “if” conditional statement allows for additional instructions to be added if the expression does not meet the requirements of the “if” statement.

“else” statements are always on their own line, followed by a colon and then indented instructions underneath. You can not use “else” statements without a proceeding “if” statement.

31
Q

Describe “elif” conditional statements. (module 3)

A

“elif” statements allow for additional instructions to be executed if certain conditions are met.

“if-else” statements are black and white, one or the other. “elif” statements allow you to assign instructions for multiple scenarios.

32
Q

What is the “while” conditional statement, and how does it differentiate from the “if” statement? (module 3)

A

The “while” statement functions the same as the “if” statement, however it will create a loop and repeat as long as the condition is true.

33
Q

What is an infinite loop? (module 3)

A

An infinite loop is one where the condition is never broken. It will continue repeating until the code is stopped.

34
Q

What is a counter variable? (module 3)

A

A counter variable is a variable you assign with the desired number of loops.

35
Q

Describe the use of “for” when it comes to loops. (module 3)

A

“for” loops browse large collections of data item by item. Instead of having to program a while conditional statement to use a counter variable, for loops do it all automatically.

for x in range (10)
“for” is the keyword.
‘x” is the control variable. This variable automatically counts the loops turns.
“in” in adds the range of possible values to be assigned to the control variable.
“range()” The range function is designed to generate all desired values for the control variable. The key word is the desired amount of turns for the loop to complete. In this specific example, it will start on loop 0 and finish on loop 10.

36
Q

“for” loop example. (module 3)

A

for x in range (10)
“for” is the keyword.
‘x” is the control variable. This variable automatically counts the loops turns.
“in” in adds the range of possible values to be assigned to the control variable.
“range()” The range function is designed to generate all desired values for the control variable. The key word is the desired amount of turns for the loop to complete. In this specific example, it will start on loop 0 and finish on loop 9. The range function will only accept and generate integers.

37
Q

`What do the break and continue statements do? (module 3)

A

“break” unconditionally and immediately stops a loop. The program then executes the next instructions.

“continue” behaves as if the program has suddenly reached the end of the body; the next turn is started and the condition expression is tested immediately.

38
Q

Define the start, stop and step parameters for the range() function. (module 3)

A

“start” is the optional integer that defines the start of the sequence. set to 0 by default.
“stop” is the optional parameter that defines the end of the sequence.
“step” is the optional parameter that signifies the difference between numbers in a sequence, set to 1 by default.

39
Q

What are lists? (module 3)

A

Lists are collections of elements. They are also known as multi value variables, as they are variables that hold more than 1 element in them. Lists are identified by the [ ] square brackets surrounding them.

40
Q

What does the len() function do? (module 3)

A

The len() function checks a list’s current length. It takes the list’s name as an argument and then counts the elements inside of it.

41
Q

What does the del() instruction do? (module 3)

A

del() removes a specified element, or range of elements, from a list.

42
Q

What happens if you use negative integers when printing list elements? (module 3)

A

The list will print in reverse order. For example:

list = [1, 2, 3, 4]
print (list [-1])

output
4

43
Q

What is the difference between functions and methods? (module 3)

A

A function doesn’t belong to any data, but it uses data to function. It may take in data, or generate new data to formulate a result.

A method is a type of function, however it also changes the state of a selected entity.

A method belongs to the data it works for, a function is owned by the whole code.

44
Q

What does the append method do to a list? (module 3)

A

The append method glues a new element to the end of a list.

45
Q

What does the insert method do to a list? (module 3)

A

The insert method adds an element to a specified area anywhere inside of a list.

46
Q

What is a bubble sort? (module 3)

A

A bubble sort is when a list of elements is sorted from lowest to highest. The highest number floats to the top of the list like a bubble, which is where the name comes from.

47
Q

What is the function of the sort() and reverse() methods? (module 3)

A

The sort method sorts the elements of the list based on their size.

The reverse method reverses the order of the elements in a list.

48
Q

What is slicing? (module 3)

A

Slicing is the process of making a copy of a list, or part of a list.

new_list = list [start:end]
Inside the brackets you would indicate where the beginning and end of the slice is, based off elements in the source list. If you leave the start portion empty, It will copy the entire list. If you leave the end portion empty, it will copy the list from where you indicate in the start of the slice, to the end of the original list.

49
Q

What are the functions of the “in” and “not in” operators? (module 3)

A

“in” and “not in” operators search a list and determine if it contains a specific element. These operators generate a true or false response based off of if the element is contained inside the list.

50
Q

What are matrices? (module 3)

A

A matrix is a two-dimensional array of lists, similar to a chess board.

51
Q

What is ASCII? (book 2 module 2)

A

ASCII (American Standard Code for Information Interchange) is one of the ways a computer understands inputted code. It takes English characters and converts them into numbers that can be understood by the computer.

52
Q

What is a code print? (book 2 module 2)

A

A code print is a number which is converted into a character.

53
Q

Describe strings. (book 2 module 2)

A

Strings are immutable sequences in Python. They always begin with either an apostrophe or quotation marks. Strings can span multiple lines.

54
Q

What is the function of the ord() operation? (book 2 module 2)

A

The ord() operation gives the ASCII code point value for a single character string.

55
Q

What does the term immutable mean? (book 2 module 2)

A

Immutable means that the similarities between strings and lists are limited.

This includes the fact that elements can not be deleted from a string using the del operator. It only can be used to remove an entire string. Also the append method will not work for strings, as they can not be expanded in any way.

56
Q

What is the function of min() and max() operators? (book 2 module 2)

A

The min() operator finds the element in a string with the lowest value.

The max() operator finds the element in a string with the largest value.

57
Q

What does the index() method do? (book 2 module 2)

A

The index() method searches a sequence from the beginning to find the first element that matches the value specified in the argument. `

58
Q

What does the list() function do? (book 2 module 2)

A

The list() function takes all characters from a string, and puts them into a list.