Quiz Home
Python_i_quiz1 Quiz
1: What is the output of the code snippet?
numbers = [1, 2, 3, 4, 5]
squared = [x ** 2 for x in numbers]
print(squared)

  [1, 4, 9, 16, 25]
  [2, 4, 6, 8, 10]
  [1, 2, 3, 4, 5]
  [1, 8, 27, 64, 125]



2: Does this function correctly identify prime numbers?
def check_prime(num):
    for i in range(2, num):
        if num % i == 0:
            return False
    return True

print(check_prime(11))

  True
  False



3: What is the output of this code?
try:
    x = 1 / 0
except ZeroDivisionError:
    print("Cannot divide by zero")
finally:
    print("This is always executed")

  Cannot divide by zero
  This is always executed
  Cannot divide by zero\nThis is always executed
  Error



4: What is the output of the lambda function?
x = lambda a, b: a * b
print(x(5, 6))

  11
  30
  5
  None



5: What will be the output of this regular expression match?
import re
pattern = re.compile('^[a-zA-Z]+$')
result = pattern.match('Python3')
print(result is not None)

  True
  False



6: How does the join method work in this example?
list = ['a', 'b', 'c', 'd']
print(''.join(list))

  abcd
  ['a', 'b', 'c', 'd']
  a-b-c-d
  Error



7: What does this code snippet output?
import json

person = '{"name": "John", "age": 30, "city": "New York"}'
person_dict = json.loads(person)

print(person_dict['age'])

  John
  30
  New York
  {"name": "John", "age": 30, "city": "New York"}



8: What is the purpose of the decorator in this code?
def decorator(func):
    def inner():
        print("Before function call")
        func()
        print("After function call")
    return inner

@decorator
def say_hello():
    print("Hello")

say_hello()

  To print messages before and after the function call
  To modify the function output
  To repeat the function twice
  To catch any errors in the function



9: What concept is demonstrated by `__secret_count` in this code?
class MyClass:
    __secret_count = 0

    def count(self):
        self.__secret_count += 1
        print(self.__secret_count)

counter = MyClass()
counter.count()
counter.count()
print(counter.__secret_count)

  Inheritance
  Polymorphism
  Encapsulation
  Exception Handling



10: What does the reduce function do in this code?
from functools import reduce

numbers = [1, 2, 3, 4]
result = reduce(lambda a, b: a * b, numbers)
print(result)

  It finds the largest number in the list
  It multiplies all numbers in the list together
  It adds all numbers in the list together
  It counts the elements in the list