Skip to content
Open
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
2 changes: 1 addition & 1 deletion PYTHON_Problems/problem_04.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Input: [4, 1, 9, 3] → Output: 9

a = list(map(int, input("Enter Your data with sapces").split()))
a = list(map(int, input("Enter Your data with spaces").split()))

print(max(a))

Expand Down
25 changes: 25 additions & 0 deletions beginner/strings/exercise_1_palindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
Title: Palindrome Checker
Level: Beginner
Task: Write a function is_palindrome(word) that returns True if word is a palindrome, False otherwise.
Examples:
is_palindrome("racecar") -> True
is_palindrome("hello") -> False
is_palindrome("madam") -> True
is_palindrome("") -> True
"""

def is_palindrome(word: str) -> bool:
return word == word[::-1]

if __name__ == "__main__":
print(is_palindrome("racecar"))
print(is_palindrome("hello"))
print(is_palindrome("madam"))
print(is_palindrome(""))


# ----------------------------------------
# Author: hygroupseries
# GitHub: https://github.com/hygroupseries
# ----------------------------------------
27 changes: 27 additions & 0 deletions beginner/strings/exercise_2_anagram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Title: Anagram Checker
Level: Beginner
Task: Write a function are_anagrams(word1, word2) that returns True if the words are anagrams, False otherwise.
Examples:
are_anagrams("listen", "silent") -> True
are_anagrams("hello", "world") -> False
are_anagrams("triangle", "integral") -> True
are_anagrams("", "") -> True
"""

def are_anagrams(word1: str, word2: str) -> bool:
word1_clean = word1.replace(" ", "").lower()
word2_clean = word2.replace(" ", "").lower()
return len(word1_clean) == len(word2_clean) and sorted(word1_clean) == sorted(word2_clean)

if __name__ == "__main__":
print(are_anagrams("listen", "silent"))
print(are_anagrams("hello", "world"))
print(are_anagrams("triangle", "integral"))
print(are_anagrams("", ""))


# ----------------------------------------
# Author: hygroupseries
# GitHub: https://github.com/hygroupseries
# ----------------------------------------
37 changes: 37 additions & 0 deletions beginner/strings/exercise_3_vowel_consonant_counter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
Title: Vowel and Consonant Counter
Level: Beginner
Task: Write a function count_vowels_consonants(text) that returns a tuple (vowel_count, consonant_count).
Examples:
count_vowels_consonants("Hello World") -> (3, 7)
count_vowels_consonants("Python Programming") -> (4, 11)
count_vowels_consonants("A E I O U") -> (5, 0)
count_vowels_consonants("") -> (0, 0)
"""

def count_vowels_consonants(text: str) -> tuple:
vowels = "aeiouAEIOU"
vowel_count = 0
consonant_count = 0

for char in text:
if char.isalpha():
if char in vowels:
vowel_count += 1
else:
consonant_count += 1

return (vowel_count, consonant_count)

if __name__ == "__main__":
print(count_vowels_consonants("Hello World"))
print(count_vowels_consonants("Python Programming"))
print(count_vowels_consonants("A E I O U"))
print(count_vowels_consonants("b c d f g"))
print(count_vowels_consonants(""))


# ----------------------------------------
# Author: hygroupseries
# GitHub: https://github.com/hygroupseries
# ----------------------------------------
33 changes: 33 additions & 0 deletions beginner/strings/exercise_4_duplicate_remover.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
Title: Remove Duplicate Characters
Level: Beginner
Task: Write a function remove_duplicates(text) that returns text with duplicate characters removed while preserving order.
Examples:
remove_duplicates("hello") -> "helo"
remove_duplicates("programming") -> "progamin"
remove_duplicates("mississippi") -> "misp"
remove_duplicates("") -> ""
"""

def remove_duplicates(text: str) -> str:
seen = set()
result = []

for char in text:
if char not in seen:
seen.add(char)
result.append(char)

return ''.join(result)

if __name__ == "__main__":
print(remove_duplicates("hello"))
print(remove_duplicates("programming"))
print(remove_duplicates("mississippi"))
print(remove_duplicates(""))


# ----------------------------------------
# Author: hygroupseries
# GitHub: https://github.com/hygroupseries
# ----------------------------------------
29 changes: 29 additions & 0 deletions beginner/strings/exercise_5_longest_word.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Title: Find Longest Word
Level: Beginner
Task: Write a function find_longest_word(sentence) that returns the longest word in the sentence.
Examples:
find_longest_word("The quick brown fox jumps") -> "quick"
find_longest_word("Python programming is fun") -> "programming"
find_longest_word("Hello world") -> "Hello"
find_longest_word("") -> ""
"""

def find_longest_word(sentence: str) -> str:
words = sentence.split()
if not words:
return ""

return max(words, key=len)

if __name__ == "__main__":
print(find_longest_word("The quick brown fox jumps"))
print(find_longest_word("Python programming is fun"))
print(find_longest_word("Hello world"))
print(find_longest_word(""))


# ----------------------------------------
# Author: hygroupseries
# GitHub: https://github.com/hygroupseries
# ----------------------------------------