S364 Midterm

¡Supera tus tareas y exámenes ahora con Quizwiz!

To be executed, what does Python programming language use?

Interpreter

floating point

a type that represents numbers with fractional parts

argument

a value provided to a function when the function is called. This value is assigned to the corresponding parameter in the function.

Will the following code cause an error: Print("Hello world!")

True

When executing the following code, what error would be raised? x =4 x + "USA"

TypeError, because x is an integer and "USA" is a string. The data types are different

return value

the result of a function passed back to the caller

What happens when you run the following 3 codes? 1) int(True) 2)int(False) 3) int(None)

1) 1 2) 0 3) TypeError

What do you get from the following code? 10/5

2.0

What will x be after the code is executed: x = 43 x = 43 + 1

44

list

a mutable data structure with a sequence of elements

statement

a section of code that represents a command or action. So far, the statements we have seen are assignments and print expression statements.

assignment

a statement that assigns a value to a variable

What operator in Python joins strings together? For example "Hello" (operator) "World"

+

What are true between lists and tuples

- Processing tuples is faster than processing lists - lists use brackets ([]) as the boundaries of the items and tuples use parentheses as the boundaries of the items

How can you execute code in Jupyter notebook?

- Shift+Enter - Ctrl+Enter - From the menu Cell -> Run Cells

What situations are a good candidate to be handled in a try/except structure?

- Try to open a file with user provided file path but the file path is incorrect - A number expected from a user input but the user enters letters such as A, B, C

What statements are correct in describing the control flow of a try/except structure?

- When the code executes without any exception, the code block inside try is executed and code inside except is skipped and program continues - When the code execution encounters an exception, the code block inside try after the line of code that encounters the error is skipped, code inside except is executed and programs continues.

When would you use a markdown cell?

- add a title to a Jupyter notebook - add headings to sections of a jupyter notebook

What is true about and if statement?

- an if statement must have a condition - if statement is used to implement conditional flow - the code blocks in the branches must be indented (an if statement does not need to be matched with an else branch)

What are the advantages of using jupyter notebook?

- communicate and share results - code development - documentation

What are the reasons to use comments in code?

- describe or explain logic - provide information such as author, version, date of code - hide some code from the interpreter so they won't be executed

To access the first three characters in a string that's stored in a variable named message, you can use this code:

- first_three = message[:3] - first_three = message[0:3]

For sequential access of a file, what is true?

- once a piece of data is read, it cannot be read again - read the file from beginning to end, cannot skip ahead

What can variable names not include in python?

-, numbers, spaces

What is the result of 10 % 3?

1

void function

A function that doesn't return a value.

dictionary

A mapping from a set of keys to their corresponding values.

parameter

A name used inside a function to refer to the value which was passed to it as an argument.

function

A named sequence of statements that performs some useful operation. Functions may or may not take parameters and may or may not produce a result

function definition

A statement that creates a new function, specifying its name, parameters, and the statements it executes.

function call

A statement that executes a function. It consists of the function name followed by an argument list.

import statment

a statement that reads a module file and makes the module functions available

Given list1 = ["H", "e", "l", "l", "o"] what does "&".join(list1) do?

Return a string: "H&e&l&l&o"

dot notation

The syntax for calling a function in another module by specifying the module name followed by a dot (period) and the function name.

Python code is always executed from top to the bottom without any exceptions

True

set

a collection of unordered items with unique values

tuple

a immutable data structure with a sequence of elements

What is true of the following code? x = "4" x = float(x)

after the execution, x now contains 4.0

key

an object that appears in a dictionary as the first part of a key-value pair

value

an object that appears in a dictionary as the second part of a key-value pair

modulus operator

an operator, denoted with a percent sign (%), that works on integers and yields the remainder when one number is divided by another

conditonal

at the decision point, the code could go through different branches that are mutually exclusive

DateTime

contains complete date and time information

date

contains the date information including year, month, day, etc. (doesn't include time)

time

contains the time information including hour, minute, or second

TimeDelta

contains time interval or duration information. The difference between two dates or times

What word indicates that start of a function?

def

how to remove a key and its value

dictionary.pop('key') del dictionary['value']

loop

execute certain code repeatedly for a multiple number of times

Sequential

execute the code line by line in the order written (this is the default execution)

What data type does the value 5.3 have?

float

If you accidentally deleted a cell and wanted to get it back, what can you do?

in the (command) mode, use the keyboard shortcut "z"

which of the following is correct about python? - it is a high-level language - it is a machine language - it is a low-level language - it is an assembly language

it is a high level language

To determine the length of a string that's in a variable named city, you can use this code:

len(city)

Where in the computer is a variable such as "x" stored after the following Python line finishes? X = 123

main memory

function

pre-defined code module executed when needed

exception handling

purposefully designed code executed when unexpected problems occur in normal execution

What type of code will get you a set of all the values found in both set1 and set2?

set1 | set2 set1.union(set2)

What code will get you a set of all the values in set1 but not in set2 and in set2 but not in set 1? (values that are not in both sets)

set1.symmetric_difference(set2)

What is the function of the secondary memory in a computer?

store information for the long term, even beyond a power cycle

When open a file to write to it, we need to pass an argument to the mode parameter, what value should we pass to mode?

w


Conjuntos de estudio relacionados

LS 6: Merchandising Operations and the Multistep Income Statement

View Set

Chapter 19: The Cardiovascular System: Blood Vessels, Mastering A & P

View Set

How does Inheritance Work? (Exam 2)

View Set