Skip to content

011 020 #41

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

Merged
merged 2 commits into from
Sep 26, 2022
Merged
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
5 changes: 3 additions & 2 deletions exercises/011-last_two_digits/README.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
6 changes: 4 additions & 2 deletions exercises/011-last_two_digits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
last_two_digits(1234)
```

## Example output:
## Example output:

+ 34
```py
34
```

## 💡 Hints:

Expand Down
8 changes: 8 additions & 0 deletions exercises/011-last_two_digits/solution.hide.py
Original file line number Diff line number Diff line change
@@ -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))
10 changes: 9 additions & 1 deletion exercises/011-last_two_digits/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions exercises/012-tens_digit/README.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ tens_digit(1234)

## Ejemplo de salida 1:

+ 3
```py
3
```

## Ejemplo de entrada 2:

Expand All @@ -22,7 +24,9 @@ tens_digit(179)

## Ejemplo de salida 2:

+ 7
```py
7
```

## 💡 Pistas:

Expand Down
10 changes: 7 additions & 3 deletions exercises/012-tens_digit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
tens_digit(1234)
```

## Example output 1:
## Example output 1:

+ 3
```py
3
```

## Example input 2:

Expand All @@ -22,7 +24,9 @@ tens_digit(179)

## Example output 2:

+ 7
```py
7
```

## 💡 Hints:

Expand Down
9 changes: 9 additions & 0 deletions exercises/012-tens_digit/solution.hide.py
Original file line number Diff line number Diff line change
@@ -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))
8 changes: 8 additions & 0 deletions exercises/012-tens_digit/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion exercises/013-sum_of_digits/README.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

## Ejemplo de salida:

+ 6
```py
6
```

## 💡 Pistas:

Expand Down
6 changes: 4 additions & 2 deletions exercises/013-sum_of_digits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

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)
```

## Example output:

+ 6
```py
6
```

## 💡 Hints:

Expand Down
11 changes: 11 additions & 0 deletions exercises/013-sum_of_digits/solution.hide.py
Original file line number Diff line number Diff line change
@@ -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))
8 changes: 8 additions & 0 deletions exercises/013-sum_of_digits/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions exercises/014-digit_after_decimal_point/solution.hide.py
Original file line number Diff line number Diff line change
@@ -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))
8 changes: 8 additions & 0 deletions exercises/014-digit_after_decimal_point/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion exercises/015-car_route/README.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion exercises/015-car_route/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions exercises/015-car_route/solution.hide.py
Original file line number Diff line number Diff line change
@@ -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())
16 changes: 14 additions & 2 deletions exercises/015-car_route/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand Down
13 changes: 13 additions & 0 deletions exercises/016-century/solution.hide.py
Original file line number Diff line number Diff line change
@@ -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))
23 changes: 18 additions & 5 deletions exercises/016-century/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

10 changes: 10 additions & 0 deletions exercises/017-total_cost/solution.hide.py
Original file line number Diff line number Diff line change
@@ -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))
20 changes: 18 additions & 2 deletions exercises/017-total_cost/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

9 changes: 9 additions & 0 deletions exercises/018-day_of_week/solution.hide.py
Original file line number Diff line number Diff line change
@@ -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))
15 changes: 13 additions & 2 deletions exercises/018-day_of_week/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

6 changes: 6 additions & 0 deletions exercises/019-digital_clock/solution.hide.py
Original file line number Diff line number Diff line change
@@ -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))
Loading