0% found this document useful (0 votes)
67 views2 pages

Class

The document provides instructions for 12 Python class exercises including: writing classes to convert between integers and roman numerals, validate parentheses in strings, find subsets of sets, find pairs of numbers that sum to a target, find triplets that sum to zero, implement exponentiation, reverse strings word by word, get and print strings, compute areas of rectangles, and compute areas and perimeters of circles. Each exercise includes a link to an online editor to write the class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views2 pages

Class

The document provides instructions for 12 Python class exercises including: writing classes to convert between integers and roman numerals, validate parentheses in strings, find subsets of sets, find pairs of numbers that sum to a target, find triplets that sum to zero, implement exponentiation, reverse strings word by word, get and print strings, compute areas of rectangles, and compute areas and perimeters of circles. Each exercise includes a link to an online editor to write the class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

for answers visit https://www.w3resource.

com/python-exercises/class-
exercises/index.php

1. Write a Python class to convert an integer to a roman numeral. - Go to the


editor

Click me to see the solution

2. Write a Python class to convert a roman numeral to an integer. - Go to the


editor

Click me to see the solution

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. - Go to the
editor

Click me to see the solution

4. Write a Python class to get all possible unique subsets from a set of distinct
integers. - Go to the editor
Input : [4, 5, 6]
Output : [[], [6], [5], [5, 6], [4], [4, 6], [4, 5], [4, 5, 6]]

Click me to see the solution

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. - Go to the editor
Input: numbers= [10,20,10,40,50,60,70], target=50
Output: 3, 4

Click me to see the solution

6. Write a Python class to find the three elements that sum to zero from a set of n
real numbers. - Go to the editor
Input array : [-25, -10, -7, -3, 2, 4, 8, 10]
Output : [[-10, 2, 8], [-7, -3, 10]]

Click me to see the solution

7. Write a Python class to implement pow(x, n). - Go to the editor

Click me to see the solution

8. Write a Python class to reverse a string word by word. - Go to the editor


Input string : 'hello .py'
Expected Output : '.py hello'

Click me to see the solution

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. - Go to the editor
Click me to see the solution

10. Write a Python class named Rectangle constructed by a length and width and a
method which will compute the area of a rectangle. - Go to the editor
Click me to see the solution

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. - Go to the editor
Click me to see the solution

12. Write a Python class named Circle constructed by a radius and two methods which
will compute the area and the perimeter of a circle.

You might also like