10/192 questions · Unlock full access
Q1

A developer is writing a script to process sensor data. The script receives a hexadecimal string representing a temperature reading, such as '0x1A'. The goal is to convert this string into its decimal integer equivalent. Which line of code correctly performs this conversion?

Q2

A Python script is designed to run indefinitely, polling a network service every 10 seconds. An engineer wants to ensure that if the user presses `Ctrl+C`, the script prints a friendly 'Shutting down...' message instead of crashing with a traceback. Which exception should be caught to handle this specific interruption?

Q3

What is the final value of `result` after the following code is executed? ```python items = [10, 20, 30, 40, 50] result = 0 for i in range(len(items)): if items[i] > 30: break if items[i] % 20 == 0: continue result += items[i] ```

Q4

A programmer creates a tuple containing a list. They then attempt to modify an element within that list. What is the outcome of this operation? ```python data_tuple = (1, 2, [3, 4]) data_tuple[2][0] = 99 print(data_tuple) ```

Q5

A developer needs to create a function `calculate_price` that accepts a base price and an optional discount percentage. If the discount is not provided, it should default to 10%. Which function signature correctly implements this requirement?

Q6

A data processing script needs to create a new list containing only the lengths of strings from an existing list, but only for strings that have more than 3 characters. Which of the following is the most 'Pythonic' way to achieve this using a single line of code? `words = ['cat', 'window', 'defenestrate', 'dog']`

Q7

True or False: In Python, the expression `0.1 + 0.2 == 0.3` evaluates to `True`.

Q8

A developer is writing a validation function that checks if a user's input is within a specific numerical range (inclusive). The function should return `True` if the number is between 50 and 100, inclusive. Which boolean expression correctly and most concisely implements this logic?

Q9

A script needs to iterate through a sequence of numbers from 0 to 9. During the iteration, it should print 'Found it!' and stop processing immediately when it encounters the number 7. For all other numbers before 7, it should just print the number itself. What is the expected output of a correctly written loop for this task?

Q10

A Python dictionary is used to store user preferences. A function needs to retrieve the 'theme' preference. If the 'theme' key does not exist, the function should return 'light' without causing an error and without modifying the original dictionary. Which line of code achieves this safely?