Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Challenge/convert temperature #46

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,18 @@
"source.organizeImports.ruff": "explicit"
}
},
"cSpell.words": ["doctests", "Hussaini", "Pylint"]
"cSpell.words": [
"doctests",
"Hussaini",
"Pylint"
],
"python.testing.unittestArgs": [
"-v",
"-s",
".",
"-p",
"test_*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
29 changes: 29 additions & 0 deletions solutions/count_vowels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
def count_vowels(input_string):
"""
Counts the number of vowels in a given string.

Args:
input_string (str): The string to analyze for vowels.

Returns:
int: The total number of vowels (a, e, i, o, u) in the string,
including both uppercase and lowercase vowels.

Example:
>>> count_vowels("Hello, World!")
3
>>> count_vowels("Python")
1
"""
vowels = "aeiouAEIOU" # List of vowels (both uppercase and lowercase)
count = 0
for char in input_string:
if char in vowels:
count += 1
return count


# Example usage
if __name__ == "__main__":
input_string = "Hello, how many vowels are here?"
print("Number of vowels:", count_vowels(input_string))
20 changes: 20 additions & 0 deletions solutions/temperature_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Function that converts celsius to Fahrenheit
def celsius_to_fahrenheit(celsius):
"""
Converts the inputted temperature from Celsius to Fahrenheit.

Input: Value in Celsius
Output: Value in Fahrenheit
"""
return (celsius * 9 / 5) + 32


# Get user input
celsius = float(input("Enter temperature in Celsius: "))

# Call the function and get the Fahrenheit value
fahrenheit = celsius_to_fahrenheit(celsius)

# Display the result
print(f"{celsius}°C is equal to {fahrenheit}°F.")
# Program that converts Celsius to Fahrenheit
33 changes: 33 additions & 0 deletions solutions/tests/test_count_vowels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import unittest

from ..count_vowels import count_vowels


class TestCountVowels(unittest.TestCase):
def test_empty_string(self):
"""Test that an empty string returns 0."""
self.assertEqual(count_vowels(""), 0)

def test_no_vowels(self):
"""Test a string with no vowels."""
self.assertEqual(count_vowels("bcdfghjklmnpqrstvwxyz"), 0)

def test_all_vowels(self):
"""Test a string with all vowels (lowercase and uppercase)."""
self.assertEqual(count_vowels("aeiouAEIOU"), 10)

def test_mixed_string(self):
"""Test a string with a mix of vowels and consonants."""
self.assertEqual(count_vowels("Hello, World!"), 3)

def test_numeric_and_special_characters(self):
"""Test a string with numbers and special characters."""
self.assertEqual(count_vowels("12345!@#$%^&*()"), 0)

def test_vowels_in_words(self):
"""Test a string with words containing vowels."""
self.assertEqual(count_vowels("Python programming is fun!"), 8)


if __name__ == "__main__":
unittest.main()
17 changes: 17 additions & 0 deletions solutions/tests/test_temperature_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import unittest

from ..temperature_converter import celsius_to_fahrenheit


class TestConverter(unittest.TestCase):
def test_positive_temperature(self):
self.assertEqual(celsius_to_fahrenheit(1), 33.8)

def test_negative_temperature(self):
self.assertEqual(celsius_to_fahrenheit(-1), 30.2)

def test_float_temperature(self):
self.assertEqual(celsius_to_fahrenheit(32.77), 90.986)

def test_zero_temperature(self):
self.assertEqual(celsius_to_fahrenheit(0), 32)
Loading