Which Python collection is an ordered, changeable sequence that suits values you may add, remove, or update?
1 Programming Foundations for Data Science Online Quiz Questions
Use this free practice quiz with 20 questions to review 1 Programming Foundations for Data Science, test your knowledge, and prepare for your next test or exam.
True or false: In Python, the value "12" has type int because it contains digits.
- A
True
- B
False
What is the built-in type name of the Python value None?
A dictionary value is retrieved by looking up a rather than by position.
A data-cleaning task needs to remove duplicate site names and check whether a site is present. Which collection is the best fit?
- A
A tuple
- B
A list
- C
A set
- D
A dictionary
Select all statements that correctly describe lists and tuples in Python.
- A
A list is ordered and changeable.
- B
A tuple is changeable after creation.
- C
A tuple is ordered and not changeable after creation.
- D
A list has no positional indexing.
True or false: In a Python condition, both zero and an empty collection are treated as false.
- A
True
- B
False
Given location = (40.7, -74.0), what numeric value does location[1] produce?
What value is assigned to label by this code when score is 75?
if score is None:
label = "missing"
elif score >= 80:
label = "high"
else:
label = "other"
- A
"missing" - B
"high" - C
"other" - D
The code raises an error because
75is notNone.
A for loop visits each in an iterable.
Select all statements that correctly describe Python functions.
- A
A parameter can provide an input to a function.
- B
A function must have a
returnstatement to run. - C
A
returnstatement can send a result back to the caller. - D
A function that reaches its end without
returnreturns0.
Inside a loop, which keyword skips the rest of the current iteration and proceeds to the next one?
- A
break - B
continue - C
return - D
elif
True or false: To avoid an endless while loop, its condition should be able to become false eventually.
- A
True
- B
False
Explain how mean_score handles missing scores and avoids division by zero when no scores are available.
How many times does the loop body run in for i in range(4):?
Given location = (40.7, -74.0), what value does location[0] return? Enter the value as a number.
What is true after these statements run?
reading = 18
reading = "unavailable"
- A
Python raises an error because a variable must keep its original type.
- B
The name
readingrefers to the string value after the second assignment. - C
The second assignment changes the string into an integer.
- D
The name
readingrefers to both values at the same time.
A program receives an external text field that may contain "27x". What should its author keep in mind before using int(field)?
- A
The conversion always succeeds because the input is a string.
- B
The conversion silently changes invalid characters to zero.
- C
The conversion may fail, so the external value should be checked before relying on it.
- D
The conversion always returns
Nonewhen the text is invalid.
What happens when break runs inside the inner loop in this nested-loop structure?
for group in groups:
for item in group:
if should_stop(item):
break
- A
The inner loop stops, and the outer loop can continue.
- B
Both loops stop immediately.
- C
Only the outer loop stops; the inner loop continues.
- D
The program skips the current iteration of both loops and resumes both.
Given score = 86 and attempts = 3, what is the result of this condition?
score >= 80 and attempts < 3
- A
The condition is true because
scoreis at least 80. - B
The condition is true because
attemptsis less than 3. - C
The condition is true because
andmeans either comparison may be true. - D
The condition is false because one of the two comparisons is false.