wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Sankes Dance

Total questions: 47

Worksheet time: 2hrs 53mins

Name
Class
Date
1.

Q: What happens if a class has two constructors with the same signature in Python?

a)

It’s okay, Python picks one randomly

b)

Error! Python only allows one constructor per class

c)

Both run simultaneously

d)

Magic happen

2.

What is the Output?

class MyClass:

@staticmethod

def add(x, y):

return x + y

print(MyClass.add(2, 3))

a)

Error (self missing)

b)

5

c)

None

d)

Requires object creation

3.

class Dog:

def speak(self):

return "Woof"

class Cat:

def speak(self):

return "Meow"

for animal in [Dog(), Cat()]:

print(animal.speak(), end=" ")

Guess the Output?

a)

Woof Meow

b)

Meow Woo

c)

Erro

d)

None

4.

What is The Output?

class Parent:

value = 100

class Child(Parent):

value = 200

c = Child()

print(c.value)

a)

100

b)

200

c)

Error

d)

None

5.

Guess the Output

class A:

def init(self):

print("A")

class B(A):

pass

obj = B()

a)

A

b)

B

c)

Error

d)

None

6.

Which of the following is true about a class in Python?

a)

A class is a blueprint for creating objects

b)

A class can’t have variables

c)

A class can’t have methods

d)

A class is executed like a function

7.

What will be the output of this code?

class Test:

pass

obj = Test()

print(type(obj))

a)

<class 'Test'>

b)

<class '__main__.Test'>

c)

Test

8.

Which statement is true about objects?

a)

Objects store data in class variables only

b)

Objects are instances of a class

c)

Objects can’t call class methods

d)

Objects can’t have unique properties

9.

Which of the following is the correct constructor in Python?

a)

__init__()

b)

__start__()

c)

__construct__()

d)

__new__()

10.

What will this code print?

class B:

def init(self, x=5):

self.x = x

obj1 = B()

obj2 = B(10)

print(obj1.x, obj2.x)

a)

5 5

b)

10 10

c)

5 10

d)

Error

11.

What will be the output of the code below?

class Test:

count = 0 # class property

def init(self, name):

self.name = name # instance property

a = Test("Alice")

b = Test("Bob")

print(a.count, b.count, a.name, b.name)

a)

0 0 Alice Bob

b)

0 0 Bob Alice

c)

Error

d)

0 1 Alice Bo

12.

Can instance properties access class properties directly?

a)

Yes, always

b)

No, never

c)

Only via self or class name

d)

Only in constructor

13.

Guess the output

class Pawan:

def attention(self):

return "Watching TV"

class Wife(Pawan):

def attention(self):

return "Complaining husband is not helping"

w = Wife()

print(w.attention())

a)

Watching TV

b)

Complaining husband is not helping

c)

Error

d)

Both

14.

What will be the Output?

class Husband:

def dinner(self):

return "Order pizza"

class Wife:

def dinner(self):

return "Cook pasta"

class Son(Husband, Wife):

pass

s = Son()

print(s.dinner())

a)

Order pizza

b)

Cook pasta

c)

Error

d)

Both

15.

What will Son print when he gives advice?

class Grandpa:

def advice(self):

return "Arrange marriage is the best! 💍"

class Father(Grandpa):

def advice(self):

return "Love marriage is the best! ❤️"

class Son(Father):

def advice(self):

return "Being single is more fun 😎"

s = Son()

print(s.advice())

a)

Arrange marriage is the best! 💍

b)

Love marriage is the best! ❤️

c)

Being single is more fun 😎

d)

Call grandma for advice 📞

16.

what will be printed?

class Husband:

def init(self):

self.__secret_snack = "Chocolates 🍫"

def reveal_snack(self):

return "My secret snack is {self.__secret_snack}"

h = Husband()

print(h.reveal_snack())

a)

My secret snack is Chocolates 🍫

b)

secret snack cannot be accessed

c)

My secret snack is {self.__secret_snack}

d)

Error

17.

If Lover class had another method @abstractmethod def gift(): and Girlfriend didn’t implement it, what happens?

a)

Error on creating object

b)

Prints default gift

c)

Works fine

d)

Runs only on weekends

18.

Why is abstraction in programming like ordering food online? 🍔📱

a)

You see the menu (interface), not the kitchen secrets 😄

b)

You must implement your order (choose what you want)

c)

Abstract methods are like “placeholders” for the actual dish

d)

All of the above

19.

from abc import ABC, abstractmethod

class Lover(ABC):

@abstractmethod

def surprise_plan(self):

pass

class Girlfriend(Lover):

def surprise_plan(self):

return "Plan a movie night 🎬"

g = Girlfriend()

print(g.surprise_plan())

Question: What is this an example of?

a)

Encapsulation

b)

Abstraction

c)

Inheritance

d)

Overriding

20.

for i in range(3):

print(f"Husband asks: Are you hungry? {i}")

print("Wife says: I'm fine 😅")

a)

Asks 3 times, prints wife’s answer each time

b)

Prints only once

c)

Error because of f-string

d)

Wife gets angry

21.

what will be the output?

for i in range(5)

print("Husband buys snacks 🍫")

a)

Prints 5 times

b)

Error due to missing colon

c)

Prints nothing

d)

Husband forgets snacks

22.

for i in range(1, 4):

if i == 2:

break

print(f"Son eats slice {i} of cake 🍰")

Guess the Output?

a)

Slice 1, Slice 2, Slice 3

b)

Slice 1

c)

Slice 1, Slice 2

d)

Nothing

23.

def husband_says():

print("I love coding ❤️ instead of loving wife")

husband_says

guess the Output?

a)

I love coding ❤️ instead of loving wife

b)

Error/Nothing

c)

i hate Coding

d)

Husband forgets

24.

def Romeo():

print("Husband says: Let's watch movie 🍿")

def Juliet():

print("Wife says: Only if we eat popcorn 🍿")

Romeo()

Output??

a)

Prints both Romeo and Juliet lines

b)

Prints only Romeo line

c)

Error

d)

Prints nothing

25.

Which of the following functions is not a built-in functional programming tool in Python?

a)

map()

b)

filter()

c)

reduce()

d)

sorted()

26.

What is The map() function in Python

a)

Filters elements based on a condition

b)

Transforms each element using a function(apply on each element)

c)

Reduces a sequence to a single value

d)

Sorts a sequence

27.

Which import is required to use reduce() in Python?

a)

import collections

b)

import itertools

c)

from functools import reduce

d)

from operator import reduce

28.

What is the correct syntax of a lambda function?

Note:Without Storing in a variable

a)

lambda (x, y): x + y

b)

lambda x, y: x + y

c)

def lambda(x, y): return x + y

d)

def (x, y): return x + y

29.

What will the following code output?

f = lambda x: x * 2

print(f(5))

a)

5

b)

10

c)

25

d)

error

30.

Which of the following statements about lambda is TRUE?

a)

lambda can contain multiple return statements.

b)

lambda can take multiple arguments but only one expression.

c)

lambda is faster than normal functions.

d)

lambda must always be named.

31.

What does the code return?

add = lambda a, b=10: a + b

print(add(5))

a)

5

b)

10

c)

15

d)

Error

32.

Which of these is equivalent to the code below?

lambda x: x**2

a)

def square(x):

return x**2

b)

def square(x):

print(x**2)

c)

def square():

return x**2

d)

Both a & b

33.

What will be the output?

nums = [1, 2, 3, 4]

print(list(map(lambda x: x+1, nums)))

a)

[1, 2, 3, 4]

b)

[2, 3, 4, 5]

c)

[0, 1, 2, 3]

d)

Error

34.

Which is NOT true about lambda functions?

a)

They can be used inside map(), filter(), and reduce().

b)

They are anonymous functions.

c)

They can have multiple expressions.

d)

They can be assigned to variables.

35.

Who will buy ice cream for Trainer?

from functools import reduce

students = ["Priyanshu", "Kishore", "Neha", "Vaishnavi"]

icecream = reduce(lambda a, b: a if a < b else b, students)

print(icecream, "will buy ice cream 🍦😂")

a)

Priyanshu will buy ice cream 🍦😂

b)

Kishore will buy ice cream 🍦😂

c)

Neha will buy ice cream 🍦😂

d)

Vaishnavi will buy ice cream 🍦😂

36.

Secret Spy Student

students = ["Tom", "Jerry", "Doreamon", "sinchan"]

spy = [name[::-1] for name in students]

print("Secret codes:", spy)

a)

Secret codes: ['Tom', 'Jerry', 'Doreamon', 'sinchan']

b)

Secret codes: ['moT', 'yrreJ', 'nomaeroD', 'nahcnis']

c)

Secret codes: ['mTo', 'Jyer', 'Doreamon', 'snachin']

d)

Secret codes: ['TomJerryDoreamonSinchan']

37.

Who will wash the dishes? 🍽️

students = ["Hitaishi", "Shusanth", "Pawan", "Priyanshu", "Kishore", "Harsha"]

result = [name for name in students if len(name) % 2 == 0]

print(result)


Who are they?

a)

['Hitaishi', 'Pawan', 'Harsha']

b)

['Shusanth', 'Priyanshu', 'Kishore']

c)

['Hitaishi', 'Shusanth', 'Priyanshu', 'Kishore']

d)

['Harsha', 'Priyanshu']

38.

Your class went out for pizza. Everyone ate, but now you must decide who will pay the bill.

Here’s the rule:

  • Use reduce() to find the student with the longest name.

  • That unlucky student will pay the bill. 😜

from functools import reduce

students = ["Neha", "Keethana", "Vaishnavi", "Nayana", "Shruti", "Shusanth Yadav"]

payer = reduce(lambda a, b: a if len(a) > len(b) else b, students)

print(payer, "will pay the pizza bill 🍕")

a)

Neha

b)

Keethana

c)

Shusanth Yadav

d)

Vaishnavi

e)

Nayana

39.

What will the following dictionary comprehension produce?

d = {x: 'Even' if x % 2 == 0 else 'Odd' for x in range(1, 6)}

print(d)

a)

{1: 'Odd', 2: 'Even', 3: 'Odd', 4: 'Even', 5: 'Odd'}

b)

{1: 'Even', 2: 'Odd', 3: 'Even', 4: 'Odd', 5: 'Even'}

c)

[1: 'Odd', 2: 'Even', 3: 'Odd', 4: 'Even', 5: 'Odd']

d)

Error

40.

What will be the output of the following code?

from functools import reduce

nums = [1, 2, 3, 4]

result = reduce(lambda x, y: x + y, nums)

print(result)

a)

10

b)

[1, 2, 3, 4]

c)

24

d)

TypeError

41.

What will be the output of the following code?

nums = [1, 2, 3]

result = map(lambda x: x**2, nums)

print(list(result))

a)

[1, 2, 3]

b)

[2, 4, 6]

c)

[1, 4, 9]

d)

Error

42.

def surprise(func):

def wrapper(*args):

print("Gift delivered 🎁")

return wrapper

@surprise

def birthday(name):

print(f"Happy Birthday {name} 🎂")

birthday("Nobita")

what Happens?

a)

Gift delivered 🎁
Happy Birthday Nobita 🎂

b)

Only Gift delivered 🎁

c)

Error

d)

Nothing

43.

def snacks():

for i in ["🍫", "🍪", "🍩"]:

yield i

s = snacks

print(next(s))

what Will happen?

a)

🍫

b)

🍪

c)

Error

d)

Nothing

44.

def husband_messages():

messages = ["I love puppy ❤️", "Dinner is ready 🍲", "Let's watch movie 🎬"]

for msg in messages:

yield msg

msg_gen = husband_messages()

print(next(msg_gen))

print(next(msg_gen))

print(next(msg_gen))

print(next(msg_gen))

what will happen?

a)

Prints all messages plus error on last call ✅

b)

Only first 2 messages

c)

Prints nothing

d)

Error immediately

45.

What is a Python decorator?

a)

A function that takes another function as an argument and returns a new function.

(adding new features)

b)

A special type of loop that automatically iterates over a sequence.

c)

A variable that stores multiple functions at once.

d)

A built-in method to convert a function into a class.

46.

Which statement about generators is FALSE?

a)

Generators are memory efficient because they yield values one at a time.

b)

Generators can be iterated only once.

c)

Generators automatically store all generated values in a list.

d)

You can use next() to get the next value from a generator.

47.

What is a generator in Python?

a)

A function that returns a list of all values at once

b)

A function that uses yield to produce values one at a time.

c)

A loop that can run infinitely without stopping.

d)

A decorator that modifies a function’s output.