Quiz on Python Classes
We all know Python is an Object-oriented language thus, class is an integral part of its functioning. Let us now try to understand the core concepts of classes in Python with the quiz. Without wasting any further time. Let’s start the quiz. All the best!
0 of 15 Questions completed Questions: You have already completed the quiz before. Hence you can not start it again. Quiz is loading… You must sign in or sign up to start the quiz. You must first complete the following: 0 of 15 Questions answered correctly Your time: Time has elapsed You have reached 0 of 0 point(s), (0) Earned Point(s): 0 of 0, (0) What is a docstring in Python class? Attributes of any class are composed of? What happens to the namespace when we create a new class? How do we create an object of the class QuizOrbit? Which of the following is called when a class is instantiated? Find the output of the code given below? # Code snippet starts class Quizorbit: def __init__(self,org = ‘QuizOrbit’): self.org = org def greet(self,name): print(“Hello, “+name+” @ “+self.org) obj = Quizorbit(‘Quizorbit’) print(obj.greet(‘Amit’)) # Code snippet ends Find the output of the code given below? # Code snippet starts class Quizorbit: def __init__(self,org = ‘QuizOrbit’): self.org = org def greet(self,name): print(“Hello, “+name+” @ “+self.org) obj = Quizorbit(‘Quizorbit’) obj.greet(‘Amit’) # Code snippet ends Find the output of the code given below? # Code snippet starts class Quizorbit: def __init__(self,org = ‘QuizOrbit’): self.org = org def greet(self,name): print(“Hello, “+name+” @ “+self.org) obj = Quizorbit(‘Quizorbit’) del obj obj.greet() # Code snippet ends Which of the following is the reason behind the output given by the code below? # Code snippet starts class Quizorbit: def __init__(self,org = ‘QuizOrbit’): self.org = org def greet(self,name): print(“Hello, “+name+” @ “+self.org) obj = Quizorbit(‘Quizorbit’) del obj obj.greet() # Code snippet ends Find the output of the code given below? # Code snippet starts class calculator: def __init__(self,a=0,b=0): self.a = a self.b = b def add(self): return self.a+self.b def subtract(self): return abs(self.a-self.b) def multiply(self): return self.a*self.b def divide(self,a,b): return int(max(a//b,b//a)) inst = calculator(13,86) print(inst.add() , inst.multiply()) # Code snippet ends Find the output of the code given below? # Code snippet starts class calculator: def __init__(self,a=0,b=0): self.a = a self.b = b def add(self): return self.a+self.b def subtract(self): return abs(self.a-self.b) def multiply(self): return self.a*self.b def divide(self,a,b): return int(max(a//b,b//a)) inst = calculator(13,86) print(inst.add() , inst.subtract(567,987)) # Code snippet ends Find the output of the code given below? # Code snippet starts class calculator: def __init__(self,a=0,b=0): self.a = a self.b = b def add(self): return self.a+self.b def subtract(self): return abs(self.a-self.b) def multiply(self): return self.a*self.b def divide(self,a,b): return int(max(a//b,b//a)) inst = calculator(13,86) print(inst.add() , inst.divide(25,1000)) # Code snippet ends Which of the following is the detailed error thrown by the code given below? # Code snippet starts class calculator: def __init__(self,a=0,b=0): self.a = a self.b = b def add(self): return self.a+self.b def subtract(self): return abs(self.a-self.b) def multiply(self): return self.a*self.b def divide(self,a,b): return int(max(a//b,b//a)) inst = calculator(13,86) print(inst.add() , inst.subtract(25,98)) # Code snippet ends Find the output of the code given below? # Code snippet starts user = [] class adminSpace: def __init__(self,newUser=0,email=”,name=”,loggedIn=False): self.newUser = newUser self.email = email self.name = name self.loggedIn = loggedIn def createUser(self,newUser,email,name,loggedIn=True): if newUser == 1: user.append((name,email)) print(“Welcome! “+name+” Your account is created!”) else: print(“The account exists, try logging in!”) user1 = adminSpace() user1.createUser(0,’[email protected]’,’abc’) # Code snippet ends Find the output of the code given below? # Code snippet starts user = [] class adminSpace: def __init__(self,newUser=0,email=”,name=”,loggedIn=False): self.newUser = newUser self.email = email self.name = name self.loggedIn = loggedIn def createUser(self,email,name,loggedIn=True,newUser=0): if newUser == 1: user.append((name,email)) return (“Welcome! “+name+” Your account is created!”) else: return (“Account exists, try loging in!”) user1 = adminSpace() user1.createUser(‘[email protected]’,’abc’,False,1) user2 = adminSpace() user2.createUser(‘[email protected]’,’abc’,True,0) user3 = adminSpace() user3.createUser(‘[email protected]’,’abc’,1) user4 = adminSpace() user4.createUser(‘[email protected]’,’abc’,True) user5 = adminSpace() user5.createUser(‘[email protected]’,’abc’,True,1) print(len(user)) # Code snippet ends Quiz Summary
Information
Results
Results
0 Essay(s) Pending (Possible Point(s): 0) Categories
1. Question
2. Question
3. Question
4. Question
5. Question
6. Question
7. Question
8. Question
9. Question
10. Question
11. Question
12. Question
13. Question
14. Question
15. Question
Summary
We hope with the mind-boggling quiz you might have found all the concepts you need to revise related to classes. If not then you have really done a good job while learning about classes. Move ahead with the next quizzes once you are confident in classes. Happy Learning!