diff --git a/exercises/011-last_two_digits/README.es.md b/exercises/011-last_two_digits/README.es.md index 8d3f3f08..0565724b 100644 --- a/exercises/011-last_two_digits/README.es.md +++ b/exercises/011-last_two_digits/README.es.md @@ -12,8 +12,9 @@ last_two_digits(1234) ## Ejemplo de salida: -+ 34 - +```py +34 +``` ## 💡 Pistas: + Si no sabes por donde comenzar este ejercicio, por favor, revisa la teoría en esta lección: https://snakify.org/lessons/integer_float_numbers/ diff --git a/exercises/011-last_two_digits/README.md b/exercises/011-last_two_digits/README.md index 2840b6ea..e900656d 100644 --- a/exercises/011-last_two_digits/README.md +++ b/exercises/011-last_two_digits/README.md @@ -10,9 +10,11 @@ last_two_digits(1234) ``` -## Example output: +## Example output: -+ 34 +```py +34 +``` ## 💡 Hints: diff --git a/exercises/011-last_two_digits/solution.hide.py b/exercises/011-last_two_digits/solution.hide.py new file mode 100644 index 00000000..8b58b249 --- /dev/null +++ b/exercises/011-last_two_digits/solution.hide.py @@ -0,0 +1,8 @@ +#Complete the function to print the last two digits of an interger greater than 9. +def last_two_digits(num): + if num > 9: return int(str(num)[-2:]) + else: return num + + +#Invoke the function with any interger greater than 9. +print(last_two_digits(1222)) diff --git a/exercises/011-last_two_digits/test.py b/exercises/011-last_two_digits/test.py index 09533fb9..9159925a 100644 --- a/exercises/011-last_two_digits/test.py +++ b/exercises/011-last_two_digits/test.py @@ -2,8 +2,16 @@ @pytest.mark.it('The function last_two_digits must exist') def test_for_functon_existence(capsys, app): - assert callable(app.last_two_digits) + assert callable(app.last_two_digits) +@pytest.mark.it('The function must return something') +def test_for_return(capsys, app): + assert app.last_two_digits(30) != None + +@pytest.mark.it('The function must return a number') +def test_for_output_type(capsys, app): + assert type(app.last_two_digits(30)) == type(1) + @pytest.mark.it('The function last_two_digits must return only the last 2 digits of a integer greater than 9') def test_for_file_output(capsys, app): if app.last_two_digits(30) > 9: diff --git a/exercises/012-tens_digit/README.es.md b/exercises/012-tens_digit/README.es.md index 78d40f01..cebc1588 100644 --- a/exercises/012-tens_digit/README.es.md +++ b/exercises/012-tens_digit/README.es.md @@ -12,7 +12,9 @@ tens_digit(1234) ## Ejemplo de salida 1: -+ 3 +```py +3 +``` ## Ejemplo de entrada 2: @@ -22,7 +24,9 @@ tens_digit(179) ## Ejemplo de salida 2: -+ 7 +```py +7 +``` ## 💡 Pistas: diff --git a/exercises/012-tens_digit/README.md b/exercises/012-tens_digit/README.md index e45feaea..03a85a12 100644 --- a/exercises/012-tens_digit/README.md +++ b/exercises/012-tens_digit/README.md @@ -10,9 +10,11 @@ tens_digit(1234) ``` -## Example output 1: +## Example output 1: -+ 3 +```py +3 +``` ## Example input 2: @@ -22,7 +24,9 @@ tens_digit(179) ## Example output 2: -+ 7 +```py +7 +``` ## 💡 Hints: diff --git a/exercises/012-tens_digit/solution.hide.py b/exercises/012-tens_digit/solution.hide.py new file mode 100644 index 00000000..d53a9b3c --- /dev/null +++ b/exercises/012-tens_digit/solution.hide.py @@ -0,0 +1,9 @@ +#Complete the function to return the tens digit of a given interger +def tens_digit(num): + return (num // 10) % 10 + + + + +#Invoke the function with any interger. +print(tens_digit(123)) \ No newline at end of file diff --git a/exercises/012-tens_digit/test.py b/exercises/012-tens_digit/test.py index 900381b1..8d17f179 100644 --- a/exercises/012-tens_digit/test.py +++ b/exercises/012-tens_digit/test.py @@ -4,6 +4,14 @@ def test_for_functon_existence(capsys, app): assert callable(app.tens_digit) +@pytest.mark.it('The function must return something') +def test_for_return(capsys, app): + assert app.tens_digit(123) != None + +@pytest.mark.it('The function must return a number') +def test_for_output_type(capsys, app): + assert type(app.tens_digit(123)) == type(1) + @pytest.mark.it('We tried to pass 854345 as parameter and it did not return 4!') def test_for_file_output(capsys, app): assert app.tens_digit(854345) == (854345 // 10)%10 diff --git a/exercises/013-sum_of_digits/README.es.md b/exercises/013-sum_of_digits/README.es.md index 1a912606..91c3de9a 100644 --- a/exercises/013-sum_of_digits/README.es.md +++ b/exercises/013-sum_of_digits/README.es.md @@ -12,7 +12,9 @@ ## Ejemplo de salida: -+ 6 +```py +6 +``` ## 💡 Pistas: diff --git a/exercises/013-sum_of_digits/README.md b/exercises/013-sum_of_digits/README.md index d3366305..fa87c902 100644 --- a/exercises/013-sum_of_digits/README.md +++ b/exercises/013-sum_of_digits/README.md @@ -4,7 +4,7 @@ 1. Complete the `digits_sum()` function. Given a three-digit number, `digits_sum()` finds the sum of its digits. -## Example input: +## Example input: ```py digits_sum(123) @@ -12,7 +12,9 @@ digits_sum(123) ## Example output: -+ 6 +```py +6 +``` ## 💡 Hints: diff --git a/exercises/013-sum_of_digits/solution.hide.py b/exercises/013-sum_of_digits/solution.hide.py new file mode 100644 index 00000000..b7f902de --- /dev/null +++ b/exercises/013-sum_of_digits/solution.hide.py @@ -0,0 +1,11 @@ +#Complete the function "digits_sum" so that it prints the sum of a three digit number. +def digits_sum(num): + aux = 0 + for x in str(num): + aux= aux+int(x) + return aux + + +#Invoke the function with any three-digit-number +#You can try other three-digit numbers if you want +print(digits_sum(123)) \ No newline at end of file diff --git a/exercises/013-sum_of_digits/test.py b/exercises/013-sum_of_digits/test.py index 539183fe..f6044d0a 100644 --- a/exercises/013-sum_of_digits/test.py +++ b/exercises/013-sum_of_digits/test.py @@ -4,6 +4,14 @@ def test_for_functon_existence(capsys, app): assert callable(app.digits_sum) +@pytest.mark.it('The function must return something') +def test_for_return(capsys, app): + assert app.digits_sum(123) != None + +@pytest.mark.it('The function must return a number') +def test_for_output_type(capsys, app): + assert type(app.digits_sum(123)) == type(1) + @pytest.mark.it('We tried to pass 854 as parameter and it did not return 17!') def test_for_file_output(capsys, app): assert app.digits_sum(854) == (854 //100)+(854 // 10)%10+ 854%10 diff --git a/exercises/014-digit_after_decimal_point/solution.hide.py b/exercises/014-digit_after_decimal_point/solution.hide.py new file mode 100644 index 00000000..18551586 --- /dev/null +++ b/exercises/014-digit_after_decimal_point/solution.hide.py @@ -0,0 +1,10 @@ +#Complete the function to return the first digit to the right of the decimal point. +import math +def first_digit(num): + return int(str(math.floor(num*10)/10)[-1]) + + + + +#Invoke the function with a positive real number. ex. 34.33 +print(first_digit(2.6)) \ No newline at end of file diff --git a/exercises/014-digit_after_decimal_point/test.py b/exercises/014-digit_after_decimal_point/test.py index 3978a7e5..cfd402a9 100644 --- a/exercises/014-digit_after_decimal_point/test.py +++ b/exercises/014-digit_after_decimal_point/test.py @@ -4,6 +4,14 @@ def test_for_functon_existence(capsys, app): assert callable(app.first_digit) +@pytest.mark.it('The function must return something') +def test_for_return(capsys, app): + assert app.first_digit(1.2) != None + +@pytest.mark.it('The function must return a number') +def test_for_output_type(capsys, app): + assert type(app.first_digit(1.2)) == type(1) + @pytest.mark.it('We tried to pass 6.24 as parameter and it did not return 2!') def test_for_file_output(capsys, app): assert app.first_digit(6.24) == int(6.24 *10)%10 diff --git a/exercises/015-car_route/README.es.md b/exercises/015-car_route/README.es.md index 62304c25..cbb3e0de 100644 --- a/exercises/015-car_route/README.es.md +++ b/exercises/015-car_route/README.es.md @@ -9,7 +9,7 @@ Un vehículo puede cubrir una distancia de `N` kilómetros por día ¿Cuántos d ## Ejemplo de entrada: ```py -car_route(700,750) +car_route(20,40) ``` ## Ejemplo de salida: diff --git a/exercises/015-car_route/README.md b/exercises/015-car_route/README.md index c5fd74bc..9cd79eb2 100644 --- a/exercises/015-car_route/README.md +++ b/exercises/015-car_route/README.md @@ -9,7 +9,7 @@ A car can cover distance of `N` kilometers per day. How many days will it take t ## Example input: ```py -car_route(700) +car_route(20,40) ``` ## Example output: diff --git a/exercises/015-car_route/solution.hide.py b/exercises/015-car_route/solution.hide.py new file mode 100644 index 00000000..4c8450a9 --- /dev/null +++ b/exercises/015-car_route/solution.hide.py @@ -0,0 +1,9 @@ +#Complete the function to return the amount of days it will take to cover a route. +#HINT: You may need to import the math module for this exercise. +import math +def car_route(n,m): + return int(math.ceil(m/n)) + + +#Invoke the function with two intergers. +print(car_route()) \ No newline at end of file diff --git a/exercises/015-car_route/test.py b/exercises/015-car_route/test.py index ba9fc557..e4f5c309 100644 --- a/exercises/015-car_route/test.py +++ b/exercises/015-car_route/test.py @@ -12,9 +12,21 @@ def test_import_random(): def test_for_functon_existence(capsys, app): assert callable(app.car_route) -@pytest.mark.it('We tried to pass 659 and 1857 as parameter and it did not return 3!') +@pytest.mark.it('The function mus return something') +def test_function_return(capsys, app): + assert app.car_route(659, 1857) != None + +@pytest.mark.it('The function must return a number') +def test_function_return_type(capsys, app): + assert type(app.car_route(659, 1857)) == type(1) + +@pytest.mark.it('We tried to pass 20 and 40 as parameter and it did not return 2!') def test_for_file_output(capsys, app): - assert app.car_route(659, 1857) == math.ceil(1857 / 659) + assert app.car_route(20, 40) == 2 + +@pytest.mark.it('We tried to pass 20 and 900 as parameter and it did not return 45!') +def test_for_file_output2(capsys, app): + assert app.car_route(20, 900) == 45 diff --git a/exercises/016-century/solution.hide.py b/exercises/016-century/solution.hide.py new file mode 100644 index 00000000..eae36927 --- /dev/null +++ b/exercises/016-century/solution.hide.py @@ -0,0 +1,13 @@ +#Complete the function to return the respective number of the century +#HINT: You may need to import the math module. +import math +def century(year): + if year % 100 == 0: + return math.floor(year/100) + else: + return math.floor(year/100 +1) + + + +#Invoke the function with any given year. +print(century(2022)) \ No newline at end of file diff --git a/exercises/016-century/test.py b/exercises/016-century/test.py index 1be58015..f97fea1f 100644 --- a/exercises/016-century/test.py +++ b/exercises/016-century/test.py @@ -13,10 +13,23 @@ def test_import_random(): def test_for_functon_existence(capsys, app): assert callable(app.century) -@pytest.mark.it('We tried to pass 1801 as parameter and it did not return 19!') +@pytest.mark.it('The function must return something') +def test_function_return(capsys, app): + assert app.century(19001) != None + +@pytest.mark.it('The function must return a number') +def test_function_return_type(capsys, app): + assert type(app.century(19001)) == type(1) + +@pytest.mark.it('We tried to pass 2000 as parameter and it did not return 20!') def test_for_file_output(capsys, app): - if app.century(1801) % 100 == 0: - assert app.century(1801) == math.floor(1801/100) - else: - assert app.century(1801) == math.floor(1801/100 +1) + assert app.century(2000) == 20 + +@pytest.mark.it('We tried to pass 2000 as parameter and it did not return 21!') +def test_for_file_output2(capsys, app): + assert app.century(2001) == 21 + +@pytest.mark.it('We tried to pass 2000 as parameter and it did not return 21!') +def test_for_file_output3(capsys, app): + assert app.century(2101) == 22 diff --git a/exercises/017-total_cost/solution.hide.py b/exercises/017-total_cost/solution.hide.py new file mode 100644 index 00000000..48763f08 --- /dev/null +++ b/exercises/017-total_cost/solution.hide.py @@ -0,0 +1,10 @@ +#Complete the function to return the total cost in dollars and cents of N cupcakes. +#Remember you can return multiple parameters => return a, b +def total_cost(d,c,n): + return ((((d*100)+c)*n)//100, (((d*100)+c)*n)%100) + + + + +#Invoke the function with three intergers: cost(dollars and cents) & number of cupcakes. +print(total_cost(15,22,4)) diff --git a/exercises/017-total_cost/test.py b/exercises/017-total_cost/test.py index d2761324..db7473c1 100644 --- a/exercises/017-total_cost/test.py +++ b/exercises/017-total_cost/test.py @@ -6,8 +6,24 @@ def test_for_functon_existence(capsys, app): assert callable(app.total_cost) +@pytest.mark.it('The function must return something') +def test_function_return(capsys, app): + assert app.total_cost(15, 22, 4) != None + +@pytest.mark.it('The function must return a tuple') +def test_function_return_type(capsys, app): + assert type(app.total_cost(15, 22, 4)) == type((60, 88)) + +@pytest.mark.it('The function must return a tuple of numbers') +def test_function_return_type_parameters(capsys, app): + result = app.total_cost(15, 22, 4) + assert type(result[0]) == type(1) and type(result[1]) == type(1) + @pytest.mark.it('We tried to pass 15, 22, 4 as parameters and it did not return (60, 88)!') def test_for_file_output(capsys, app): - - assert app.total_cost(15, 22, 4) == ((((15*100)+22)*4)//100, (((15*100)+22)*4)%100) + assert app.total_cost(15, 22, 4) == (60, 88) + +@pytest.mark.it('We tried to pass 10, 15, 4 as parameters and it did not return (20, 30)!') +def test_for_file_output2(capsys, app): + assert app.total_cost(15, 22, 4) == (60, 88) diff --git a/exercises/018-day_of_week/solution.hide.py b/exercises/018-day_of_week/solution.hide.py new file mode 100644 index 00000000..d08fca75 --- /dev/null +++ b/exercises/018-day_of_week/solution.hide.py @@ -0,0 +1,9 @@ +#Complete the function to return the number of day of the week for k'th day of year. +def day_of_week(k): + + return (3+k)%7 + + + +#Invoke function day_of_week with an interger between 0 and 6 (number for days of week) +print(day_of_week(1)) \ No newline at end of file diff --git a/exercises/018-day_of_week/test.py b/exercises/018-day_of_week/test.py index cf633851..7d80c585 100644 --- a/exercises/018-day_of_week/test.py +++ b/exercises/018-day_of_week/test.py @@ -6,8 +6,19 @@ def test_for_functon_existence(capsys, app): assert callable(app.day_of_week) -@pytest.mark.it('Something went wrong! We tried to pass 56 as parameter and it did not return 3!Keep trying!') +@pytest.mark.it('The function must return something') +def test_function_return(capsys, app): + assert app.day_of_week(1) != None + +@pytest.mark.it('The function must return a number') +def test_function_return_type(capsys, app): + assert type(app.day_of_week(1)) == type(1) + +@pytest.mark.it('Something went wrong! We tried to pass 1 as parameter and it did not return 4! Keep trying!') def test_for_file_output(capsys, app): + assert app.day_of_week(1) == 4 - assert app.day_of_week(56) == (3+56)%7 +@pytest.mark.it('Something went wrong! We tried to pass 46 as parameter and it did not return 4! Keep trying!') +def test_for_file_output2(capsys, app): + assert app.day_of_week(46) == 0 diff --git a/exercises/019-digital_clock/solution.hide.py b/exercises/019-digital_clock/solution.hide.py new file mode 100644 index 00000000..997971b3 --- /dev/null +++ b/exercises/019-digital_clock/solution.hide.py @@ -0,0 +1,6 @@ +#Complete the function to return how many hrs and min are displayed on the 24th digital clock. +def digital_clock(n): + return ((n // 60), (n % 60)) + +#Invoke the function with any interger (seconds after midnight) +print(digital_clock(150)) diff --git a/exercises/019-digital_clock/test.py b/exercises/019-digital_clock/test.py index a91dc88c..a673e878 100644 --- a/exercises/019-digital_clock/test.py +++ b/exercises/019-digital_clock/test.py @@ -6,8 +6,19 @@ def test_for_functon_existence(capsys, app): assert callable(app.digital_clock) +@pytest.mark.it('The function must return something') +def test_function_return(capsys, app): + assert app.digital_clock(194) != None + +@pytest.mark.it('The function must return a tuple') +def test_function_return_type(capsys, app): + assert type(app.digital_clock(194)) == type((3, 14)) + @pytest.mark.it('We tried to pass 194 as parameter and it did not return (3, 14)!Keep Trying!') def test_for_file_output(capsys, app): + assert app.digital_clock(194) == (3, 14) - assert app.digital_clock(194) == ((194 // 60), (194 % 60)) +@pytest.mark.it('We tried to pass 150 as parameter and it did not return (2, 50)! Keep Trying!') +def test_for_file_output(capsys, app): + assert app.digital_clock(150) == (2,30) diff --git a/exercises/020-factorial/solution.hide.py b/exercises/020-factorial/solution.hide.py index d2a881c5..0a188d3b 100644 --- a/exercises/020-factorial/solution.hide.py +++ b/exercises/020-factorial/solution.hide.py @@ -4,4 +4,14 @@ def fact(x): return x * fact(x - 1) x=int(input()) -print fact(x) \ No newline at end of file +print (fact(x)) + + +# or + +# Your code here +import math +def factorial(num): + return math.factorial(num) + +print(factorial(8)) \ No newline at end of file diff --git a/exercises/020-factorial/test.py b/exercises/020-factorial/test.py index 1852dcb4..04c23a6c 100644 --- a/exercises/020-factorial/test.py +++ b/exercises/020-factorial/test.py @@ -9,6 +9,14 @@ def test_factorial_exists(app): except AttributeError: raise AttributeError("The function 'factorial' should exist on app.py") +@pytest.mark.it('The function must return something') +def test_function_return(capsys, app): + assert app.factorial(8) != None + +@pytest.mark.it('The function must return a tuple') +def test_function_return_type(capsys, app): + assert type(app.factorial(8)) == type(1) + @pytest.mark.it('Testing the function factorial with the number 8, it should return 40320') def test_factorial_8(app): try: