0% found this document useful (1 vote)
53 views

Module 2 - File 1-Hands-On

The document outlines 10 tasks to practice object-oriented programming concepts like functions, classes, inheritance, polymorphism, and encapsulation. It instructs the reader to create functions that calculate factorials, check strings, take user input; classes like Student and Super with methods; a lambda function; check for palindromes; practice inheritance with Modified_Super; overloaded methods; a function to sum inputs; and a class to demonstrate encapsulation. Completing these tasks will help the reader strengthen their skills in core OOP concepts through hands-on practice.

Uploaded by

amit thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
53 views

Module 2 - File 1-Hands-On

The document outlines 10 tasks to practice object-oriented programming concepts like functions, classes, inheritance, polymorphism, and encapsulation. It instructs the reader to create functions that calculate factorials, check strings, take user input; classes like Student and Super with methods; a lambda function; check for palindromes; practice inheritance with Modified_Super; overloaded methods; a function to sum inputs; and a class to demonstrate encapsulation. Completing these tasks will help the reader strengthen their skills in core OOP concepts through hands-on practice.

Uploaded by

amit thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

OOPs Concepts (Hands-on 1)

[email protected]

+91-7022374614

US: 1-800-216-8930 (Toll-Free)


Problem Statement:
You work in XYZ Corporation as a Data Analyst. Your corporation has told you to work on
functions and classes.

Tasks to be performed:

1. Create a function named ‘factor’ that can only accept 1 argument. The function should
return the factorial of that number.

2. Create a function named ‘check_string’, the function should accept a string data from the
user and the function should check if the user input contains the letter ‘s’ in it. If it contains
the letter ‘s’ then print- ‘The string is containing the letter ‘s’’, if not then print- ‘The string
doesn’t contain the letter ‘s’’.

3. Create a class named ‘student’ and inside the class, create a function named ‘fun1’- this
method should accept the user defined input and return that value.
a. Create another method named- message() and that method should print the user
defined input that we have defined in ‘fun1’.

4. Create a lambda function that should double or multiply the number (that we will be passing
in the lambda function) by 2. Store the lambda function in a variable named ‘double_num’.

5. Take the user input string and check whether that string is palindrome or not.

6. Create a class named ‘Super’ and inside that class define a user-defined function named
fun1.
a. Inside the ‘fun1’ function, pass the message “This is function 1 in the Super class.”
in the print statement.

7. Create another class named ‘Modified_Super’ and inherit this class from the Super class.
a. Inside the Modified_Super class, create a function named ‘fun1’ and pass the
following message inside the print statement: ‘This is function 1 in the Modified
Super class.’

b. Create another user-defined function named ‘fun2’ and pass the message: ‘This is
the 2nd function from the Modified Super class’ in the print statement.

c. After that, now create an object for the Modified_Super class and call the fun1().

8. Create 2 methods named ‘Hello’. In the 1st Hello method, pass only one argument and pass
this message: ‘This function only has 1 argument’. And in the 2nd Hello method, pass
two arguments and pass this message: ‘This function has 2 arguments’.
a. Try to call both the methods and analyze the output of both the methods.
9. Create a method named ‘Sum’ that can accept multiple user inputs. Now add those user-
defined input values using for loop and the function should return the addition of the numbers.

10. Create a class named ‘Encapsulation’:


a. Inside the class, first create a constructor. Inside the constructor, initialize
originalValue variable as 10.

b. After creating the constructor, define a function named ‘Value’ and this function
should return the variable that we have initialized in the constructor.

c. Now create 2nd function named setValue, and pass an argument named
‘newValue’. The task of this function will be to replace the value of the
originalValue variable by the value of the newValue variable.

You might also like