Skip to content
12 changes: 10 additions & 2 deletions count_vowels.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
10 changes: 9 additions & 1 deletion factorial.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
10 changes: 9 additions & 1 deletion fibonacci.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
10 changes: 9 additions & 1 deletion fizzbuzz.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# 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".
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")
Expand Down
2 changes: 2 additions & 0 deletions hello_world.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# hello_world.py
def greet():
"""Greets Hacktoberfest with a hello!
"""
print("Hello, Hacktoberfest!")

if __name__ == "__main__":
Expand Down
10 changes: 9 additions & 1 deletion palindrome_checker.py
Original file line number Diff line number Diff line change
@@ -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__":
Expand Down
10 changes: 9 additions & 1 deletion prime_checker.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
10 changes: 9 additions & 1 deletion reverse_string.py
Original file line number Diff line number Diff line change
@@ -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__":
Expand Down
20 changes: 18 additions & 2 deletions temperature_converter.py
Original file line number Diff line number Diff line change
@@ -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__":
Expand Down