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

Import Array

The document contains code snippets demonstrating various Python classes and functions, including a Student class, a method for reversing words, and a function for converting integers to Roman numerals. It also includes an implementation of the threeSum algorithm to find triplets in an array that sum to zero. Additionally, there are examples of creating instances of these classes and invoking their methods.

Uploaded by

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

Import Array

The document contains code snippets demonstrating various Python classes and functions, including a Student class, a method for reversing words, and a function for converting integers to Roman numerals. It also includes an implementation of the threeSum algorithm to find triplets in an array that sum to zero. Additionally, there are examples of creating instances of these classes and invoking their methods.

Uploaded by

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

import array while j < k:

for name in array.__dict__: if nums[i] + nums[j] + nums[k] < 0:


print(name) j += 1
………………………………………………….. elif nums[i] + nums[j] + nums[k] > 0:
class Student: k -= 1
def __init__(self, student_id, student_name, else:
class_name): result.append([nums[i], nums[j], nums[k]])
self.student_id = student_id j, k = j + 1, k - 1
self.student_name = student_name while j < k and nums[j] == nums[j - 1]:
self.class_name = class_name j += 1
student = Student('V12', 'Frank Gibson', 'V') while j < k and nums[k] == nums[k + 1]:
print(student.__dict__) k -= 1
……………………………………………………………………. i += 1
def student(student_id, student_name, student_class): while i < len(nums) - 2 and nums[i] == nums[i - 1]:
return f'Student ID: {student_id}\nStudent Name: i += 1
{student_name}\nClass: {student_class}' return result
print(student('S122', 'Wilson Medina', 'VI')) print(py_solution().threeSum([-25, -10, -7, -3, 2, 4, 8, 10]))
……………………………………………………………………………… …………………………………………………………………….
class py_solution: class Circle():
def reverse_words(self, s): def __init__(self, r):
return ' '.join(reversed(s.split())) self.radius = r
print(py_solution().reverse_words('hello .py'))
…………………………………………………………………………………… def area(self):
class py_solution: return self.radius**2*3.14
def int_to_Roman(self, num):
val = [ def perimeter(self):
1000, 900, 500, 400, return 2*self.radius*3.14
100, 90, 50, 40,
10, 9, 5, 4, NewCircle = Circle(8)
1 print(NewCircle.area())
] print(NewCircle.perimeter())
syb = [ ………………………………………………………………….
"M", "CM", "D", "CD",
"C", "XC", "L", "XL",
"X", "IX", "V", "IV",
"I"
]
roman_num = ''
i=0
while num > 0:
for _ in range(num // val[i]):
roman_num += syb[i]
num -= val[i]
i += 1
return roman_num
print(py_solution().int_to_Roman(1))
print(py_solution().int_to_Roman(4000))
………………………………………………………………………………..
class py_solution:
def threeSum(self, nums):
nums, result, i = sorted(nums), [], 0
while i < len(nums) - 2:
j, k = i + 1, len(nums) - 1

You might also like