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
4 changes: 2 additions & 2 deletions exercises/case_inverter/solution.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SUBMIT = False

SUBMIT = True
#ya venia con la respuesta xd

def case_inverter(s: str) -> str: # noqa: ARG001
"""
Expand Down
7 changes: 5 additions & 2 deletions exercises/celsius_to_fahrenheit/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBMIT = False
SUBMIT = True


def celsius_to_fahrenheit(_celsius: float) -> float:
Expand All @@ -13,7 +13,10 @@ def celsius_to_fahrenheit(_celsius: float) -> float:
>>> celsius_to_fahrenheit(-40)
-40.0
"""
return 0.0

farenheit=(_celsius * 9/5)+32

return farenheit


def test() -> None:
Expand Down
7 changes: 5 additions & 2 deletions exercises/char_frequency/solution.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
SUBMIT = False
SUBMIT = True


def char_frequency(s: str) -> dict[str, int]:
"""Counts the frequency of each character in a string."""
counts = {}
for char in s:
counts[char] = counts.get(char, 0) + 1
if char in counts:
counts[char] += 1
else:
counts[char] = 1
return counts


Expand Down
9 changes: 9 additions & 0 deletions exercises/count_vowels/solution.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ast
from pathlib import Path
SUBMIT = True

def test_exercise_solutions_have_asserts() -> None:
"""Verify that all exercise solution stubs have a test() function with asserts."""
Expand Down Expand Up @@ -37,6 +38,14 @@ def test_exercise_solutions_have_asserts() -> None:
)

# Add a test function with an assert for count_vowels
def count_vowels(s: str) -> int:
vowels = 'aeiouAEIOU'
count = 0
for char in s:
if char in vowels:
count += 1
return count

def test():
# Example: assert count_vowels("hello") == 2
# For simplicity, we'll add a basic assert that checks function existence and returns true
Expand Down
9 changes: 7 additions & 2 deletions exercises/factorial_iterative/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBMIT = False
SUBMIT = True


def factorial_iterative(_n: int) -> int:
Expand All @@ -11,7 +11,12 @@ def factorial_iterative(_n: int) -> int:
>>> factorial_iterative(5)
120
"""
return 0
if _n==0:
return 1
fact=1
for i in range(1,_n+1):
fact*=i
return fact


def test() -> None:
Expand Down
9 changes: 7 additions & 2 deletions exercises/fibonacci/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBMIT = False
SUBMIT = True


def fibonacci(n: int) -> int:
Expand All @@ -14,7 +14,12 @@ def fibonacci(n: int) -> int:
>>> fibonacci(10)
55
"""
return 0
x=1
y=0
for i in range(n):
x,y=y,x+y
return y



def test() -> None:
Expand Down
4 changes: 2 additions & 2 deletions exercises/hello_world/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBMIT = False
SUBMIT = True


def hello_world() -> str:
Expand All @@ -8,7 +8,7 @@ def hello_world() -> str:
>>> hello_world()
'Hello, World!'
"""
return ""
return "Hello, World!"


def test() -> None:
Expand Down
10 changes: 8 additions & 2 deletions exercises/linear_search/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBMIT = False
SUBMIT = True


def linear_search(_items: list[int], _target: int) -> int:
Expand All @@ -12,7 +12,13 @@ def linear_search(_items: list[int], _target: int) -> int:
>>> linear_search([], 5)
-1
"""
return 0

for i in range(len(_items)):
if _target==_items[i]:

return i

return -1


def test() -> None:
Expand Down
7 changes: 5 additions & 2 deletions exercises/list_average/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBMIT = False
SUBMIT = True


def list_average(_numbers: list[float]) -> float:
Expand All @@ -10,7 +10,10 @@ def list_average(_numbers: list[float]) -> float:
>>> list_average([10, 20, 30])
20.0
"""
return 0.0
sum=0
for i in _numbers:
sum+=i
return sum/len(_numbers)


def test() -> None:
Expand Down
13 changes: 11 additions & 2 deletions exercises/list_mode/solution.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any

SUBMIT = False
SUBMIT = True


def list_mode(_items: list[Any]) -> Any:
Expand All @@ -12,7 +12,16 @@ def list_mode(_items: list[Any]) -> Any:
>>> list_mode(['a', 'b', 'a'])
'a'
"""
return None
count = {}
if not _items:
return
for item in _items:
if item in count:
count[item] += 1
else:
count[item] = 1

return max(count, key=count.get)


def test() -> None:
Expand Down
14 changes: 12 additions & 2 deletions exercises/min_max_list/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBMIT = False
SUBMIT = True


def min_max_list(_items: list[int]) -> tuple[int, int] | None:
Expand All @@ -12,7 +12,17 @@ def min_max_list(_items: list[int]) -> tuple[int, int] | None:
>>> min_max_list([])
None
"""
return (0, 0)
# El mayor entero que cabe en una "palabra" de memoria (64 bits)
a = float('inf')
b = float('-inf')
if not _items:
return None
for i in _items:
if i > b:
b =i
if i < a:
a=i
return (a,b)


def test() -> None:
Expand Down
21 changes: 9 additions & 12 deletions exercises/palindrome/solution.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
SUBMIT = False
SUBMIT = True


def palindrome(_text: str) -> bool:
# noqa: ARG001
"""Checks if a string is a palindrome.

Example usage:
>>> palindrome("racecar")
True
>>> palindrome("hello")
False
"""
return False
def palindrome(word:str)->bool:

for i in range(len(word)):
if word[i]!=word[len(word)-1-i]:
return False
return True


def test() -> None:
Expand All @@ -31,3 +26,5 @@ def test() -> None:

if __name__ == "__main__":
test()

print(98)
4 changes: 2 additions & 2 deletions exercises/personalized_greeting/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBMIT = False
SUBMIT = True


def personalized_greeting(_name: str, _age: int) -> str:
Expand All @@ -11,7 +11,7 @@ def personalized_greeting(_name: str, _age: int) -> str:
>>> personalized_greeting("Bob", 30)
'Hello Bob, you are 30 years old'
"""
return ""
return f"Hello {_name},you are {_age} years old"


def test() -> None:
Expand Down
9 changes: 7 additions & 2 deletions exercises/prefix_sums/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBMIT = False
SUBMIT =True


def prefix_sums(_numbers: list[int]) -> list[int]:
Expand All @@ -10,7 +10,12 @@ def prefix_sums(_numbers: list[int]) -> list[int]:
>>> prefix_sums([10, -10, 5])
[10, 0, 5]
"""
return []
sumtotal=[]
answer=[]
for i in _numbers:
answer.append(sum(sumtotal)+i)
sumtotal.append(i)
return answer


def test() -> None:
Expand Down
29 changes: 15 additions & 14 deletions exercises/prime_check/solution.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
SUBMIT = False
SUBMIT = True


def prime_check(_n: int) -> bool:
# noqa: ARG001
"""Checks if a number is prime.

Example usage:
>>> prime_check(2)
True
>>> prime_check(4)
False
>>> prime_check(17)
True
"""
return False
def prime_check(n: int) -> bool:

if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
limite = int(n**0.5) + 1

for i in range(3, limite, 2):
if n % i == 0:
return False
return True


def test() -> None:
Expand Down
5 changes: 3 additions & 2 deletions exercises/simple_interest/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBMIT = False
SUBMIT = True


def simple_interest(_principal: float, _rate: float, _time: float) -> float:
Expand All @@ -11,7 +11,8 @@ def simple_interest(_principal: float, _rate: float, _time: float) -> float:
>>> simple_interest(500, 3.5, 1)
17.5
"""
return 0.0
I=(_principal * _rate * _time) / 100
return I


def test() -> None:
Expand Down
11 changes: 3 additions & 8 deletions exercises/string_reversal/solution.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
SUBMIT = False
SUBMIT = True


def string_reversal(s: str) -> str: # noqa: ARG001
"""
Reverses a string.
"""
# Add a basic assert to the stub to satisfy the test
assert True, "Placeholder assert for string reversal" # Placeholder assert
return ""
def string_reversal(s: str) -> str:
return s[::-1]


def test() -> None:
Expand Down
4 changes: 2 additions & 2 deletions exercises/sum_two_numbers/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBMIT = False
SUBMIT = True


def sum_two_numbers(_a: int, _b: int) -> int:
Expand All @@ -13,7 +13,7 @@ def sum_two_numbers(_a: int, _b: int) -> int:
>>> sum_two_numbers(0, 0)
0
"""
return 0
return _a+_b


def test() -> None:
Expand Down
3 changes: 2 additions & 1 deletion exercises/variable_swap/solution.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any

SUBMIT = False
SUBMIT = True


def variable_swap(a: Any, b: Any) -> tuple[Any, Any]:
Expand All @@ -12,6 +12,7 @@ def variable_swap(a: Any, b: Any) -> tuple[Any, Any]:
>>> variable_swap("hello", "world")
('world', 'hello')
"""
a,b=b,a
return a, b


Expand Down
2 changes: 1 addition & 1 deletion exercises/word_count/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBMIT = False
SUBMIT = True


def word_count(s: str) -> int:
Expand Down
Loading