Coding Exam Questions Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Printing the contents of a file containing two lines read with “readlines()” results in what?

A

[‘Line01\n’, ‘Line02’]

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

Printing the contents of a file containing two lines read in with “read()” results in what?

A

Line01\nLine02

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

Opening an existing text file with the option ‘w’ and then “write”ing some text to the file does what

A

File text_file.txt will be created if it does not exist

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

If a file is opened with the option ‘r’ but the file doesn’t exist, what is returned?

A

Error message

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

“ATGCATGC” return the results when the “GC” is replaced with “U”

A

ATUATU

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

What is the “len” of a sequence when you split “ATGCATGC” at “A”

A

3, first A results in a space.

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

stringvariable.find(‘string’) method returns what?

A

The index of the first occurrence of the substring if found or -1 if not found

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

string = [“Python”, “is”, “fun”] print(““.join(string)) returns what?

A

Python is fun - string join() method returns a string by joining all the elements of an iterable (list, string, tuple)

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

string.split() does what to this object, string = “Good Morning to you”

A

[“Good”, “Morning”, “to”, “you”] text.split() - splits string into a list of substrings at each space character, text.split(‘,’) splits at commas,

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

Class instantiation uses function notation that returns a new instance of the class. For example
tobject = Grades(1234, 5007) does what?

A

creates a new instance of the class and assigns this object to the local variable tobject.

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

How does class inheritance work?

A

Declare your class followed by parentheses and then list any classes that your class inherits from. In a function definition, parentheses after the function name represent arguments that the function accepts. In a class definition the parentheses after the class name instead represent the classes being inherited from. The second class has access to all the methods in the inherited class.

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

f1= Fraction(1,2)
f2= Fraction(2,3)
f3 = f1 + f2
print(f3.num)
returns 7, why?

A

The Fraction module is a built in class with a __add__ method which is = to the arithmetic function +
1/2 + 2/3 = 3/6+4/6=7/6
7 = num, 6 = den
f3.num calls the add function and the numerator is 7

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

If head = 0 in your Class and you instantiate the object with other variables, what does print(IList.head) return?

A

0 because the variable head = 0 in iList. Despite IList class being called in the previous line with a list of numbers which would set head to 4, that doesn’t persist because it isn’t saved when iList is called again. Rather than printing out a variable, the print command here calls the class with no input attributes so head is equal to the default value set in the class.

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

How do you call a method inside a class. ex. print(new_emp.getDept()) vs. call an attribute in a class by print(new_emp.dept)

A

We invoke a method by first typing in the name of the object we are referencing, followed by a dot (.), followed by the method with parenthesis.

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

What position does this command return in an XML file?
find(“.//country[1]”).attrib[“name”]

A

Returns the “name” attribute of the first country listed because parsing in XML starts at position 1 unlike JSON and CSV which starts at position 0.
- find(“.//country[2]”).attrib[“name”]
- finds the second country in an XML file.

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

When you open a csv file with csv.reader what is the first row read?

A

The first row is the header row

17
Q

When you open a csv file with csv.dictreader what is the first row read?

A

The first row read when opened with dictreader is the first row of data.

18
Q

print(xmlRoot.find(./country[@name=’Panama’]/rank”).text) does what?

A

Looks in country to find the attribute name which equals Panama and returns the rank text value.

19
Q

Looks in country to find the attribute name which equals Panama and returns the rank text value.

A

Finds the neighbor tag where the direction attribute value is E and returned the name attribute as cname.

20
Q

XML file positions start with which number?

A

[1] - yes it is true. XML unlike JSON start position with 1 not 0

21
Q

CSV file positions start with which number?

A

[0] - Most objects in python start position counting with [0, 1, 2, 3…]

22
Q

Learning by associating stimulus and response is called:

A

Classical Conditioning

23
Q

Computationally intractable problems are problems that are:

A

not solvable with existing computational tools

24
Q

All possible outcomes of a problem is called

A

Problem space

25
Q

Conterfactual thinking is what?

A

Thinking about alternate outcome if an event in past had been different

26
Q

Explain Type 1 vs Type 2 reasoning.

A

Use type 1 reasoning when:

-You are very experienced
-Have repeatedly seen the same pattern before.
-Need quick results
-When you are aware of possible biases and control for them.
-When the risk of not acting quickly is worse or equal to making an error.

-The problem involves a novel choice which you have never seen.
-There is a strong confirmation bias, availability bias, or other human judgement error towards the situation.
-The intuitive answer might lead you in the wrong direction.
-The problem is very complex and needs to be broken down into sub-problems.
-There is time to test hypothesis and eliminate possibilities.

27
Q

What makes a well defined problem?

A
  1. an initial/starting state
  2. a clear end or goal state
  3. a set of allowable moves or actions to change states

one where the entire problem space is mapped out, decision rules which link the conditions to actions are available. The desired results are very clear and specific outcomes.

28
Q

Define metadata with an example. Provide a healthcare use case where the metadata is used.

A

Metadata is data about data for example in healthcare, we often refer to demographics as a data grouping. Patient demographics refers to multiple data elements such as race, ethnicity, gender, age at diagnosis, income, married or not. The properties of these data elements, what each of these data elements mean, what values are allowed in the fields, whether they are binned, how the fields are defined is the metadata. The actual data would be the values for an individual patient such as white, Hispanic, 42, 50k-100k, single. In this way, the metadata defines the data that is being collected.

29
Q

Define secondary analysis of healthcare data

A

Raw data is the actual data collected on a patient while secondary analysis is data that can be derived from the primary raw data. For example if a patient is on a drug for hypertension then you know that they have hypertension, similarly for diabetes drugs, you can infer the diagnosis based on the drug prescribed. Secondary analysis is the process to derive additional data from the primary data such as the example just described using the primary data = drug prescribed to determine the secondary data = diagnosis.

30
Q

Data Acquisition is:

A

Extracting the data in a desired format

31
Q

Which of the following is not core to Data Science? Data Intelligence, Data Wrangling, Data Analysis, Data Quality

A

Data Intelligence is not core to Data Science.

32
Q

Compare two subsets of data to determine if any relationship exists, that is:

A

Data Analysis

33
Q

Checking to see if there are missing value in the blood glucose monitoring would be an example of what data science action?

A

Data Manipulation is the answer provided - perhaps because it includes data quality.

34
Q

By decreasing the time spend in ICU, evaluate the effect in cost savings is an example of what type of analysis?

A

Causative Analysis

35
Q

ATGCATGC
What is at position [-3] + [3] ?

A

TC ; counting backwards starts at -1, counting forward starts at 0

36
Q

When converting from a float to an integer what happens to a decimal like int(float(0.98))) ?

A

It becomes 0 because when converting from float to integer, the number gets truncated (decimal parts are removed). Since 0.99 losses everything to the right of the decimal all that is left is the 0