Exit Chapter 06 ยท ๐Ÿ”ข Data Handling โ€” Quiz

Playing as a guest? to earn XP and track your progress.

Question 1 of 58 0 correct so far

๐Ÿ”ข Data Handling Quiz

Q1.

What does a data type tell Python?

Explanation

A data type tells Python what kind of value is held and which operations are allowed; type() shows it.

Q2.

Which are Python's four numeric types?

Explanation

Python's numbers are int, bool, float and complex.

Q3.

Which statement about Python integers is correct?

Explanation

Python integers have unlimited precision; for example 2 ** 100 is printed in full.

Q4.

What is the output of print(True + True)?

Explanation

bool is a sub-type of int where True = 1, so True + True = 2.

Q5.

What does bool(0), bool(15), bool("") return?

Explanation

0 and the empty string are falsy; 15 is truthy.

Q6.

What is the value of the float literal 1.75E1?

Explanation

Exponent form means mantissa ร— 10^exponent: 1.75 ร— 10ยน = 17.5.

Q7.

Why does 0.1 + 0.2 give 0.30000000000000004 in Python?

Explanation

Floats are approximate (about 15 significant digits); integers are always exact.

Q8.

For z = 3 + 4j, what do z.real and z.imag return?

Explanation

Both parts of a complex number are returned as floats: 3.0 and 4.0.

Q9.

Which letter does Python use for the imaginary unit of a complex number?

Explanation

Python writes complex numbers as a + bj, using j (not i).

Q10.

For a string of length n, what is the range of valid backward indices?

Explanation

Forward indices go from 0 to n-1 and backward indices from -1 to -n.

Q11.

In the string "SCHOOL", what are the forward and backward indices of the letter 'H'?

Explanation

S=0, C=1, H=2 forwards; backwards L=-1, O=-2, O=-3, H=-4.

Q12.

Accessing an index outside a string's valid range raises:

Explanation

An out-of-range index gives an IndexError, for example "abc"[5].

Q13.

Which statement about lists and tuples is correct?

Explanation

Lists (square brackets) can be changed; tuples (round brackets) cannot.

Q14.

How are the values in a dictionary accessed?

Explanation

A dictionary stores key:value pairs in { }, and values are looked up by key, e.g. student["name"].

Q15.

What is the type of the value None?

Explanation

None represents 'no value' and its type is NoneType.

Q16.

Which statement about None is correct?

Explanation

None is not 0, False or "". Writing none (lowercase) gives a NameError.

Q17.

Which group contains only mutable types?

Explanation

Only list, dictionary and set are mutable (the 'LDS' trick); int, float, bool, complex, str and tuple are immutable.

Q18.

Every Python object has which three things?

Explanation

Every object has an identity (id), a type (type()) and a value.

Q19.

After a = 10 and then a = a + 5, what happens to id(a)?

Explanation

int is immutable, so Python creates a new object 15 and a now points to it; the id changes.

Q20.

After marks = [70, 80, 90] and marks[0] = 100, what happens to id(marks)?

Explanation

Lists are mutable, so they are modified in place and keep the same id.

Q21.

What is the output of print(10 / 2)?

Explanation

True division / always returns a float, even when the division is exact.

Q22.

What is the output of print(17 // 5, 17 % 5)?

Explanation

17 // 5 is the floor quotient, 3; 17 % 5 is the remainder, 2.

Q23.

What is the output of print(-22 // 5, -22 % 5)?

Explanation

-22 / 5 = -4.4, which floors to -5; then -5 ร— 5 = -25, and -22 - (-25) = 3.

Q24.

What is the output of print(17.0 // 5)?

Explanation

Floor division with a float operand gives a float result: 3.0.

Q25.

What is the output of print(2 ** 3 ** 2)?

Explanation

** is right-associative, so 2 ** 3 ** 2 = 2 ** (3 ** 2) = 2 ** 9 = 512.

Q26.

What is the output of print(2 ** 2 ** 3)?

Explanation

Right-associative: 2 ** (2 ** 3) = 2 ** 8 = 256.

Q27.

What is the output of print(-2 ** 2)?

Explanation

** has higher precedence than unary minus, so it is -(2 ** 2) = -4.

Q28.

What is the output of print(3 * "ab" + "c")?

Explanation

3 * "ab" gives "ababab", then + "c" gives "abababc".

Q29.

What does print("Zoo" < "apple") display?

Explanation

Strings are compared character by character using Unicode values; 'Z' (90) is less than 'a' (97).

Q30.

The chained comparison 1 < 5 < 10 is equivalent to:

Explanation

Python evaluates a chained comparison as 1 < 5 and 5 < 10, which is True.

Q31.

Why is 'if a = 5:' wrong?

Explanation

= is assignment and == is comparison; if a = 5: is a SyntaxError.

Q32.

For a = [1, 2, 3], b = [1, 2, 3] and c = a, which result is correct?

Explanation

a == b is True (same values) but a is b is False (different objects); c points to the same object as a, so a is c is True.

Q33.

What is the difference between == and is?

Explanation

== compares values, while is compares identity (the same id()).

Q34.

Which of these values is falsy in Python?

Explanation

Falsy values include 0, 0.0, 0j, "", [], (), {}, None and False; " ", [0] and -1 are truthy.

Q35.

What is the output of print(0 or 7)?

Explanation

x or y returns y when x is falsy; 0 is falsy, so it returns 7.

Q36.

What is the output of print(5 or 7)?

Explanation

x or y returns x if x is truthy; 5 is truthy, so it returns 5 without checking 7.

Q37.

What is the output of print(5 and 7)?

Explanation

x and y returns y when x is truthy, so 5 and 7 gives 7.

Q38.

What is the output of print(0 and 5, 3 or 0, not 0)?

Explanation

0 and 5 returns 0 (falsy first operand); 3 or 0 returns 3; not always returns a Boolean, so not 0 is True.

Q39.

What is printed after this code?

x = 10 x += 5 x *= 2 x //= 4 print(x)

Explanation

x becomes 15, then 30, then 30 // 4 = 7.

Q40.

What happens when you write x++ in Python?

Explanation

Python has no ++ or -- operators; use x += 1.

Q41.

What does print("a" in "Python") display?

Explanation

"Python" contains no lowercase 'a', so the result is False (whereas "th" in "Python" is True).

Q42.

Which operator has the HIGHEST precedence (after parentheses)?

Explanation

The order is ( ) โ†’ ** โ†’ unary +/- โ†’ * / // % โ†’ + - โ†’ relational โ†’ not โ†’ and โ†’ or.

Q43.

Which logical operator has the LOWEST precedence?

Explanation

or has the lowest precedence of the operators listed.

Q44.

What is the value of 12 + 3 * 2 ** 2 // 5 - 1?

Explanation

2 ** 2 = 4; 3 * 4 = 12; 12 // 5 = 2; 12 + 2 - 1 = 13.

Q45.

What is the value of 20 // 3 + 2 ** 3 % 5?

Explanation

2 ** 3 = 8; 20 // 3 = 6; 8 % 5 = 3; 6 + 3 = 9.

Q46.

What is the value of not 5 > 3 or 4 < 2?

Explanation

The relational operators come first: not True or False โ†’ False or False โ†’ False.

Q47.

What is the value of 20 / 4 * 2?

Explanation

Same-precedence operators are evaluated left to right: (20 / 4) * 2 = 5.0 * 2 = 10.0.

Q48.

What is the value of 5 + 3 * 2 ** 2 - 8 / 4?

Explanation

2 ** 2 = 4; 3 * 4 = 12; 8 / 4 = 2.0; 5 + 12 - 2.0 = 15.0.

Q49.

Implicit type conversion (coercion) is performed by:

Explanation

Coercion happens automatically in the order bool โ†’ int โ†’ float โ†’ complex, so no data is lost.

Q50.

What is the output of print(True + 3.5)?

Explanation

True is converted to 1, then 1.0, so the result is 4.5.

Q51.

What does int(7.9) return?

Explanation

int() cuts off the decimal part โ€” it truncates rather than rounds.

Q52.

What does int("3.5") give?

Explanation

A string with a decimal point cannot be converted directly to int. Use int(float("3.5")), which gives 3.

Q53.

What is the output of print(int(7.99) + float("2"))?

Explanation

int(7.99) = 7 and float("2") = 2.0; 7 + 2.0 = 9.0.

Q54.

Which Python expression correctly represents โˆš(bยฒ โˆ’ 4ac)?

Explanation

Use math.sqrt() with ** for the power and * for each multiplication.

Q55.

Which type of error is 10 / 0?

Explanation

Dividing by zero raises a ZeroDivisionError while the program is running.

Q56.

Writing avg = a + b / 2 instead of avg = (a + b) / 2 is an example of:

Explanation

The program runs but gives the wrong result because of faulty logic.

Q57.

Which error occurs when a variable is used before it has been defined?

Explanation

Using an undefined name, such as print(total) before total is assigned, raises a NameError.

Q58.

int("hello") raises which error?

Explanation

The type (str) is acceptable to int(), but the value is invalid, so a ValueError is raised.