• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Functions and oops

Question 1

Q1-def square(x):
   return x * x

result = square(3)
What is the value of result after executing the code?

  • A) 3

  • B) 6

  • C) 9

  • D) 12

Question 2

Q2-def add_numbers(a, b):
   return a + b

result = add_numbers(4, 7)
What is the value of result after executing the code?

  • A) 11

  • B) 14

  • C) 47

  • D) 28

Question 3

Q3-import random

num_list = [1, 2, 3, 4, 5]
selected_num = random.choice(num_list)
What does the above code do?

  • A) Sorts the list in ascending order

  • B) Picks a random number from the list

  • C) Reverses the order of the list

  • D) Checks if all elements in the list are equal

Question 4

Q4-from math import sqrt

result = sqrt(16)
What is the value of result after executing the code?

  • A) 4

  • B) 8

  • C) 2

  • D) 16

Question 5

Q5-class Car:
   def __init__(self, make, model):
       self.make = make
       self.model = model

car1 = Car("Toyota", "Camry")
What is car1 in the above code?

  • A) A function

  • B) A module

  • C) An instance of the Car class

  • D) A global variable

Question 6

Q6-class Circle:
   def __init__(self, radius):
       self.radius = radius

   def calculate_area(self):
       return 3.14 * self.radius * self.radius

circle1 = Circle(5)
area = circle1.calculate_area()
What does the area variable represent in the above code?

  • A) The circumference of the circle

  • B) The radius of the circle

  • C) The diameter of the circle

  • D) The area of the circle

Question 7

Q7-numbers = [1, 2, 3, 4, 5]

result = sum(numbers)
What does the above code do?

  • A) Finds the product of all numbers in the list

  • B) Calculates the average of the numbers in the list

  • C) Computes the sum of all numbers in the list

  • D) Returns the maximum value in the list

Question 8

Q8-import datetime

current_time = datetime.datetime.now()
What is current_time in the above code?

  • A) A string containing the current date and time

  • B) An integer representing the current timestamp

  • C) An instance of the datetime class with the current date and time

  • D) A module containing various date and time functions

Question 9

Q9-from math import pi

class Circle:
   def __init__(self, radius):
       self.radius = radius

   def calculate_area(self):
       return pi * self.radius * self.radius

circle1 = Circle(6)
area = circle1.calculate_area()
What is the area variable in the above code?

  • A) The radius of the circle

  • B) The diameter of the circle

  • C) The circumference of the circle

  • D) The area of the circle

Question 10

Q10-import random

class Dice:
   def __init__(self):
       self.value = None

   def roll(self):
       self.value = random.randint(1, 6)

my_dice = Dice()
my_dice.roll()
What does the roll method in the above code do?

  • A) Prints the current value of the dice

  • B) Sets the value of the dice to a random number between 1 and 6

  • C) Checks if the dice is fair

  • D) Initializes the value of the dice to 1

There are 10 questions to complete.

Last Updated :
Take a part in the ongoing discussion