OOP Basics
OOP Basics
create a class called Calculator that takes 2 arguments and write functions for
addition, subtraction and multiplication of 2 numbers.
2. create a class called Employee with company name, first name, last name and
salary as inputs and write functions to do the following operations
1. allow the user to update name
2. create email id ([email protected])
3. update salary only if the salary is valid.
3. Create a class named CustomList with list as an input and implement the
following functions using low level interactions.
1. add a value at the end
2. get length
3. pop element
4. insert element at specific index
5. remove element from specific index
6. rotate the list for specified number of times
5. create a class called Employee with first name, last name, joining date('DD-MM-
YYYY') and salary as inputs and write functions to do the following operations
(use datetime module)
1. return the joining date in datetime object
2. return the joining date in string format (eg: 10 May 2023) - use timedelta
and strftime
3. Calculate the total year of experience of the employee upto this date
4. If the employee is having at least 1 year of experience, then hike his/her
salary by 20%
6. create a class called FileHandler with file object as input. Implement the
following functions.
1. return length of the file(number of lines)
2. return the number of blank lines in the file
3. record the data of how many times the file was opened and the date(eg: 10
May 2023) and time at which it was opened(Hour:Minute:Second) in a csv file
4. return only the nth line
5. return a list of lines from user defined start and end range
6. return last n lines
7. Two players are playing a guessing game where one player has to guess the other
player's choice, whoever takes less chance is declared the winner
(inputs: players name and list of places)
1. get a random number from player1 and return that specific indexed place.
2. get a random choice from player 2 and check how many chances will player 2
takes
till he guesses player 1 place correctly.
3. for the next turn follow step 1 and step2 for player 2
4. Compare both player1 and player2's chances taken and declare the winner
(Hint: use random module)
8. create a class named Shares and take share name, number of shares and share
prices as inputs
1. sort the shares based on share names
2. sort the shares based on share numbers
3. sort the shares based on share prices
10. create a class named ArrayClass with typecode and a sequence - use array module
1. initialize an array based on the input sequence
2. return all the available typecodes of the array in the form of list.
3. return the typecode of the initialized array
4. add the user input element to the index specified by the user.
- If the index is 0 then insert it.
- If the index is len(array)-1, then check if the element is a individual
datatype or sequence
if sequence extend it or else append it
5. reverse the array.
6. return the count of the specified element in the array.
7. remove the specific element, if the element is present at the end pop it.
8. convert the array to a list
9. convert the array to a string