0% found this document useful (0 votes)
238 views

Python Exercise

The document contains instructions for writing 16 Python classes to perform various tasks: 1) Convert integers to roman numerals and vice versa 2) Check validity of parentheses, brackets, braces strings 3) Find all subsets of a set of integers 4) Find pair of elements that sum to a target from an array 5) Find triplets summing to zero from a set 6) Implement exponentiation 7) Reverse a string by word 8) Get and print a string in upper case 9) Calculate rectangle area from length and width 10) Calculate circle area and perimeter from radius 11) Get class name of an instance 12) Create Circle class with radius and area/circumference methods

Uploaded by

gurjotstg
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
238 views

Python Exercise

The document contains instructions for writing 16 Python classes to perform various tasks: 1) Convert integers to roman numerals and vice versa 2) Check validity of parentheses, brackets, braces strings 3) Find all subsets of a set of integers 4) Find pair of elements that sum to a target from an array 5) Find triplets summing to zero from a set 6) Implement exponentiation 7) Reverse a string by word 8) Get and print a string in upper case 9) Calculate rectangle area from length and width 10) Calculate circle area and perimeter from radius 11) Get class name of an instance 12) Create Circle class with radius and area/circumference methods

Uploaded by

gurjotstg
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Python exercise (classes and objects)

1. Write a Python class to convert an integer to a roman numeral. –


2. Write a Python class to convert a roman numeral to an integer. - 
3. Write a Python class to find validity of a string of parentheses, '(', ')', '{', '}', '[' and ']. These
brackets must be close in the correct order, for example "()" and "()[]{}" are valid but "[)", "({[)]"
and "{{{" are invalid. - 
4. Write a Python class to get all possible unique subsets from a set of distinct integers. Input :
[4, 5, 6] Output : [[], [6], [5], [5, 6], [4], [4, 6], [4, 5], [4, 5, 6]]
5. Write a Python class to find a pair of elements (indices of the two numbers) from a given
array whose sum equals a specific target number.
Input: numbers= [10,20,10,40,50,60,70], target=50 Output: 3, 4
6. Write a Python class to find the three elements that sum to zero from a set of n real
numbers. -  Input array : [-25, -10, -7, -3, 2, 4, 8, 10]
Output : [[-10, 2, 8], [-7, -3, 10]]
7. Write a Python class to implement pow(x, n).
8. Write a Python class to reverse a string word by word. -  Input string : 'hello .py'
Expected Output : '.py hello'
9. Write a Python class which has two methods get_String and print_String. get_String accept a
string from the user and print_String print the string in upper case.
10. Write a Python class named Rectangle constructed by a length and width and a method
which will compute the area of a rectangle.
11. Write a Python class named Circle constructed by a radius and two methods which will
compute the area and the perimeter of a circle. - 
12. Write a Python program to get the class name of an instance in Python. 
13. Create a Cricle class and intialize it with radius. Make two methods getArea and
getCircumference inside this class.

14. Create a Temprature class. Make two methods :


1. convertFahrenheit - It will take celsius and will print it into Fahrenheit.
2. convertCelsius - It will take Fahrenheit and will convert it into Celsius.

15. Create a Student class and initialize it with name and roll number. Make methods to :
1. Display - It should display all informations of the student.
2. setAge - It should assign age to student
3. setMarks - It should assign marks to the student.

16. Create a Time class and initialize it with hours and minutes.
1. Make a method addTime which should take two time object and add them. E.g.- (2 hour and
50 min)+(1 hr and 20 min) is (4 hr and 10 min)
2. Make a method displayTime which should print the time.
3. Make a method DisplayMinute which should display the total minutes in the Time. E.g.- (1 hr
2 min) should display 62 minute.

You might also like