In Python, are count and Count two different variable names?
2 Programming Foundations for Data Analysis Online Quiz Questions
Use this free practice quiz with 20 questions to review 2 Programming Foundations for Data Analysis, test your knowledge, and prepare for your next test or exam.
Which Python keyword begins a function definition?
A loop repeats as long as its condition remains true.
What value is assigned to status when this code runs?
reading = 100
if reading < 0:
status = "check: negative reading"
elif reading > 100:
status = "check: unusually high reading"
else:
status = "within expected range"
- A
check: negative reading
- B
within expected range
- C
check: unusually high reading
A data-analysis program should automatically treat every unusual reading as erroneous, without considering context.
- A
True
- B
False
A list contains the readings [4, -2, 8]. A program retains readings greater than or equal to zero and calculates the mean of the retained values. What is that mean?
Given the code below, what value does first_reading contain after the assignment?
readings = [12.4, 15.0, 13.6]
first_reading = readings[0]
readings.append(14.2)
- A
15.0
- B
13.6
- C
12.4
- D
14.2
What does this expression return if the dictionary has no region key?
station = {"name": "North"}
station.get("region", "unknown")
- A
It raises a
KeyErrorbecause the key is absent. - B
It returns
unknown. - C
It adds the key
regionwith the valueunknownto the dictionary.
Select all statements that accurately describe Python collections.
- A
A list is an ordered, changeable sequence.
- B
A tuple is an ordered, unchangeable sequence.
- C
A dictionary associates keys with values.
- D
A set holds distinct values.
- E
A set is an ordered sequence that permits repeated values.
Select all statements that correctly describe Python loops or safe practices when processing collections.
- A
A
forloop can process items in a collection in turn. - B
range()can generate a sequence of integers. - C
A
whileloop repeats as long as its condition remains true. - D
A loop variable can take the next item in the collection on each pass.
- E
It is generally clearer and safer to change a collection while iterating over that same collection.
In this function, what value is returned when values is an empty list?
def mean(values):
if len(values) == 0:
return
return sum(values) / len(values)
Suppose an analysis processes readings that may be negative. Explain how a loop, a conditional, a separate list, and a mean-calculating function can work together to produce the mean of nonnegative readings. Why should excluded readings be preserved or recorded?
What is the type of the value returned by float("12.4")?
- A
str - B
float - C
int - D
bool
A program finds a reading above 100. Based on the guidance for interpreting unusual values, should it automatically conclude that the reading is wrong?
- A
True
- B
False
The dictionary station has no "region" key. What does station.get("region", "unknown") return?
- A
station["region"]returns"unknown"if the key is missing. - B
station.get("region", "unknown")returns"unknown"if the key is missing. - C
station.get("region", "unknown")adds the key with value"unknown"to the dictionary. - D
station.get("region", "unknown")raises aKeyErrorif the key is missing.
In Python, what index accesses the third item in a list?
- A
1
- B
2
- C
3
- D
4
You need to store distinct values and do not need duplicates. Which Python collection best fits this purpose?
- A
A list
- B
A tuple
- C
A set
- D
A dictionary
Given the Python statements below, what is the value of total after both statements run?
total = 3
total = total + 1
- A
It checks whether
totalandtotal + 1are equal. - B
It updates
totalfrom 3 to 4. - C
It raises a
NameErrorbecausetotalhas not been defined. - D
It changes
totalto the text value"4".
Using the mean function below, what numerical value is returned by mean([2, 4, 6])?
def mean(values):
if len(values) == 0:
return None
return sum(values) / len(values)
Given is_ready = False and status = "False", what is the Python type of the value assigned to is_ready?