From b413701d2beba086b88c80d2f3f26852c52a30be Mon Sep 17 00:00:00 2001 From: bleu-lotuz Date: Mon, 21 Oct 2024 23:11:27 -0700 Subject: [PATCH 1/3] Create pythagoras_triplet.py This is Python implementation of Pythagoras theorem algorithm. --- .../pythagoras_triplet.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Python Automation Scripts/pythagoras_triplet.py diff --git a/Python Automation Scripts/pythagoras_triplet.py b/Python Automation Scripts/pythagoras_triplet.py new file mode 100644 index 00000000..a758fc50 --- /dev/null +++ b/Python Automation Scripts/pythagoras_triplet.py @@ -0,0 +1,28 @@ +""" +This is a pure Python implementation of the Pythagoras Triplets algorithm +Run the doctests with the following command: +python3 -m doctest -v pythagoras_triplet.py +or +python -m doctest -v pythagoras_triplet.py +For manual testing run: +python3 pythagoras_triplet.py +""" + + +from math import sqrt +class pythagoras_triplet: + def pythagoras(side1 : float, side2: float) -> float: + hypotenuse = sqrt(side1**2 + side2**2) + return hypotenuse + + +if __name__ == "__main__": + import doctest + + doctest.testmod() + + side1 = float(input("Enter the side one of the right triangle")) + side2 = float(input("Enter the side two of the right triangle")) + + print("Formula of hypotenuse => sqare root of side1^2 + side2^2") + print(pythagoras_triplet.pythagoras(side1, side2)) From 60764a13d95681147ae92d11436c87ce2beeacf2 Mon Sep 17 00:00:00 2001 From: bleu-lotuz Date: Mon, 21 Oct 2024 23:21:07 -0700 Subject: [PATCH 2/3] Create palindrome.py This is a python implementation to check if the given number is a palindrome. --- Python Automation Scripts/palindrome.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Python Automation Scripts/palindrome.py diff --git a/Python Automation Scripts/palindrome.py b/Python Automation Scripts/palindrome.py new file mode 100644 index 00000000..789aabf6 --- /dev/null +++ b/Python Automation Scripts/palindrome.py @@ -0,0 +1,21 @@ +class palindrome: + def palindrome(number : int): + reverse = 0 + temp = number + while temp > 0: + remainder = temp % 10 + reverse = (reverse * 10) + remainder + temp = temp // 10 + if number == reverse: + return "Is a Palindrome" + else: + return "Not a Palindrome" + + +if __name__ == "__main__": + import doctest + + doctest.testmod() + + number = float(input("Enter the number to check if it is a palindrome")) + print(palindrome.palindrome(number)) From b88f6f3db46b3d0ce5ca60b4674e8e1fcff9573d Mon Sep 17 00:00:00 2001 From: bleu-lotuz Date: Mon, 21 Oct 2024 23:41:32 -0700 Subject: [PATCH 3/3] Create majority_element.py --- Python Automation Scripts/majority_element.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Python Automation Scripts/majority_element.py diff --git a/Python Automation Scripts/majority_element.py b/Python Automation Scripts/majority_element.py new file mode 100644 index 00000000..23255fa6 --- /dev/null +++ b/Python Automation Scripts/majority_element.py @@ -0,0 +1,38 @@ +""" +This is a pure Python implementation for leetcode problem on majority element. +""" + +class MajorityElement: + def majorityElement(nums: list[int]) -> int: + count = 0 + majority = 0 + + for i in nums: + if count == 0: + majority = i + + if i == majority: + count += 1 + else: + count -= 1 + + return majority + +if __name__ == "__main__": + import doctest + + doctest.testmod() + + # initialize to an empty list + numbers = [] + + # get the number of elements in the input list + n = int(input("Enter number of elements in the list: ")) + + # iterating till the range + for i in range(0, n): + ele = int(input("Enter next element in the list")) + numbers.append(ele) + + + print(MajorityElement.majorityElement(numbers))