From 18d4020a26a899157e5fc75d3086ac9db5eda4eb Mon Sep 17 00:00:00 2001 From: Srivaishnavi Yaddanapudi <127314796+Y-Srivaishnavi@users.noreply.github.com> Date: Sat, 26 Oct 2024 21:37:07 +0530 Subject: [PATCH 01/10] Add docstrings and type hints --- temperature_converter.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/temperature_converter.py b/temperature_converter.py index dfdde69..58286e9 100644 --- a/temperature_converter.py +++ b/temperature_converter.py @@ -1,8 +1,24 @@ # temperature_converter.py -def celsius_to_fahrenheit(c): +def celsius_to_fahrenheit(c:float)->float: + """Transform a Celsius temperature reading into its corresponding Fahrenheit value. + + Args: + c(float): The temperature in Celsius. + + Returns: + The equivalent temperature in Fahrenheit. + """ return (c * 9/5) + 32 -def fahrenheit_to_celsius(f): +def fahrenheit_to_celsius(f:float)->float: + """Transform a Fahrenheit temperature reading into its corresponding Celsius value. + + Args: + f(float): The temperature in Fahrenheit. + + Returns: + The equivalent temperature in Celsius. + """ return (f - 32) * 5/9 if __name__ == "__main__": From 12eb8aa38f3957ab9a9e348c43c57a154c2a2ded Mon Sep 17 00:00:00 2001 From: Srivaishnavi Yaddanapudi <127314796+Y-Srivaishnavi@users.noreply.github.com> Date: Sat, 26 Oct 2024 21:42:28 +0530 Subject: [PATCH 02/10] Add type hint, return type, and docstring. --- reverse_string.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/reverse_string.py b/reverse_string.py index 16803ca..9fa7c22 100644 --- a/reverse_string.py +++ b/reverse_string.py @@ -1,5 +1,13 @@ # reverse_string.py -def reverse_string(s): +def reverse_string(s:str)->str: + """Reverse a string. + + Args: + s(str): The string to be reversed. + + Returns: + The reversed string. + """ return s[::-1] if __name__ == "__main__": From d4cb38516c97ca825a920641e36643fd2d77348c Mon Sep 17 00:00:00 2001 From: Srivaishnavi Yaddanapudi <127314796+Y-Srivaishnavi@users.noreply.github.com> Date: Sat, 26 Oct 2024 21:45:32 +0530 Subject: [PATCH 03/10] Add type hint, return type, and docstring. --- prime_checker.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/prime_checker.py b/prime_checker.py index 05b3e8f..5686eb9 100644 --- a/prime_checker.py +++ b/prime_checker.py @@ -1,5 +1,13 @@ # prime_checker.py -def is_prime(n): +def is_prime(n:int)->bool: + """Checks whether a number is prime. + + Args: + n(int): The number to be checked for primality. + + Returns: + Whether the number is prime. + """ if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): From 0b852141cc8444b23f3090abfb75fce9f905bd89 Mon Sep 17 00:00:00 2001 From: Srivaishnavi Yaddanapudi <127314796+Y-Srivaishnavi@users.noreply.github.com> Date: Sat, 26 Oct 2024 21:47:28 +0530 Subject: [PATCH 04/10] Add type hint, return type, and docstring. --- palindrome_checker.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/palindrome_checker.py b/palindrome_checker.py index c0fdc30..c885233 100644 --- a/palindrome_checker.py +++ b/palindrome_checker.py @@ -1,5 +1,13 @@ # palindrome_checker.py -def is_palindrome(s): +def is_palindrome(s:str)->bool: + """Checks whether a string is a palindrome. + + Args: + s(str): The string to be checked. + + Returns: + Whether the string is a palindrome. + """ return s == s[::-1] if __name__ == "__main__": From 0e636a1031abc727f81adfcdd2f818a8029fcee9 Mon Sep 17 00:00:00 2001 From: Srivaishnavi Yaddanapudi <127314796+Y-Srivaishnavi@users.noreply.github.com> Date: Sat, 26 Oct 2024 21:48:24 +0530 Subject: [PATCH 05/10] Add docstring. --- hello_world.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hello_world.py b/hello_world.py index b44a902..c0c2d9f 100644 --- a/hello_world.py +++ b/hello_world.py @@ -1,5 +1,7 @@ # hello_world.py def greet(): + """Greets Hacktoberfest with a hello! + """ print("Hello, Hacktoberfest!") if __name__ == "__main__": From 7fcd7112e6b560d1a0ffcb25bc6d0f23fcf5b7c7 Mon Sep 17 00:00:00 2001 From: Srivaishnavi Yaddanapudi <127314796+Y-Srivaishnavi@users.noreply.github.com> Date: Sat, 26 Oct 2024 21:51:02 +0530 Subject: [PATCH 06/10] Add type hint and docstring. --- fizzbuzz.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fizzbuzz.py b/fizzbuzz.py index 3d53078..df77b49 100644 --- a/fizzbuzz.py +++ b/fizzbuzz.py @@ -1,5 +1,13 @@ # fizzbuzz.py def fizzbuzz(n): + """Prints the numbers from 1 to n. + For multiples of 3, print "Fizz" instead of the number. + For the multiples of 5, print "Buzz". + For numbers which are multiples of both 3 and 5, print "FizzBuzz".   + + Args: + n(int): The upper limit of the range. + """ for i in range(1, n + 1): if i % 3 == 0 and i % 5 == 0: print("FizzBuzz") From 60120b2cd55016f106c8d17d80261c835eb92457 Mon Sep 17 00:00:00 2001 From: Srivaishnavi Yaddanapudi <127314796+Y-Srivaishnavi@users.noreply.github.com> Date: Sat, 26 Oct 2024 21:51:21 +0530 Subject: [PATCH 07/10] Add type hint --- fizzbuzz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fizzbuzz.py b/fizzbuzz.py index df77b49..007d3e8 100644 --- a/fizzbuzz.py +++ b/fizzbuzz.py @@ -1,5 +1,5 @@ # fizzbuzz.py -def fizzbuzz(n): +def fizzbuzz(n:int): """Prints the numbers from 1 to n. For multiples of 3, print "Fizz" instead of the number. For the multiples of 5, print "Buzz". From 6ffd753e8067b1346cd74ec061b0670a7c82239c Mon Sep 17 00:00:00 2001 From: Srivaishnavi Yaddanapudi <127314796+Y-Srivaishnavi@users.noreply.github.com> Date: Sat, 26 Oct 2024 21:54:42 +0530 Subject: [PATCH 08/10] Add type hint, return type, and docstring. --- fibonacci.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fibonacci.py b/fibonacci.py index fee3de2..aa82518 100644 --- a/fibonacci.py +++ b/fibonacci.py @@ -1,5 +1,13 @@ # fibonacci.py -def fibonacci(n): +def fibonacci(n:int)->list[int]: + """Returns Fibonacci sequence of a specified length. + + Args: + n(int): The length of the sequence. + + Returns: + The Fibonacci sequence of the specified length. + """ a, b = 0, 1 sequence = [] for _ in range(n): From 9dfa4c6d6eb259b393fd83a969ec02ae7853bcaf Mon Sep 17 00:00:00 2001 From: Srivaishnavi Yaddanapudi <127314796+Y-Srivaishnavi@users.noreply.github.com> Date: Sat, 26 Oct 2024 21:56:52 +0530 Subject: [PATCH 09/10] Add type hint, return type, and docstring. --- factorial.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/factorial.py b/factorial.py index 1d04ecd..8da1da4 100644 --- a/factorial.py +++ b/factorial.py @@ -1,5 +1,13 @@ # factorial.py -def factorial(n): +def factorial(n:int)->int: + """Recursively calculate the factorial of a number. + + Args: + n(int): The number whose factorial is to be calculated. + + Returns: + The factorial of the specifed number. + """ if n == 0 or n == 1: return 1 return n * factorial(n - 1) From a3ebbd5cf0fdaf72bfb8054b7c83a948e822837c Mon Sep 17 00:00:00 2001 From: Srivaishnavi Yaddanapudi <127314796+Y-Srivaishnavi@users.noreply.github.com> Date: Sat, 26 Oct 2024 22:02:00 +0530 Subject: [PATCH 10/10] Add type hint, return type, and docstring. Change `vowels` from `str` to `set` for improved time complexity. --- count_vowels.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/count_vowels.py b/count_vowels.py index 35a479b..8b8178f 100644 --- a/count_vowels.py +++ b/count_vowels.py @@ -1,6 +1,14 @@ # count_vowels.py -def count_vowels(s): - vowels = "aeiouAEIOU" +def count_vowels(s:str)->int: + """Counts the number of vowels in a string. + + Args: + s(str): The string to be parsed for vowels. + + Returns: + The number of vowels in the specifed string. + """ + vowels = set("aeiouAEIOU") count = sum(1 for char in s if char in vowels) return count