Skip to content

Commit f50d989

Browse files
authored
Unified the Challenges a Bit More (#56)
* Reworked absolute value challenge * Cleaned up absolute value README * Added some test cases for the memes * Added challenge link
1 parent a9793fb commit f50d989

File tree

7 files changed

+56
-22
lines changed

7 files changed

+56
-22
lines changed

challenges/how-to-capitalize-a-string/solutions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,11 @@
55

66

77
def capitalize_1(string):
8+
"""
9+
Capitalizes a string using a combination of the upper and lower methods.
10+
11+
:author: jrg94
12+
:param string: any string
13+
:return: a string with the first character capitalized and the rest lowercased
14+
"""
815
return string[0].upper() + string[1:].lower()

challenges/how-to-capitalize-a-string/test_solutions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@
55
def test_capitalize_all_lowercase():
66
for _, value in getmembers(solutions, isfunction):
77
assert value("deku") == "Deku"
8+
9+
10+
def test_capitalize_no_alphabet():
11+
for _, value in getmembers(solutions, isfunction):
12+
assert value("1234") == "1234"
13+
14+
15+
def test_capitalize_all_caps():
16+
for _, value in getmembers(solutions, isfunction):
17+
assert value("TSUYU") == "Tsuyu"

challenges/how-to-compute-absolute-value/README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ Write a program which generates |x| plus signs if the number is positive and |x|
1010
### Expected Behavior
1111

1212
```python
13-
>>> "Enter a number": 7
14-
+++++++
15-
>>> "Enter a number": -5
16-
-----
13+
absolute_value_text(7) # returns +++++++
14+
absolute_value_text(-5) # returns -----
1715
```
1816

1917
### Example Solution

challenges/how-to-compute-absolute-value/compute-absolute-value-2.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

challenges/how-to-compute-absolute-value/compute-absolute-value.py

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Provides a series of solutions to the challenge provided at the following link:
3+
https://therenegadecoder.com/code/how-to-compute-absolute-value-in-python/#challenge
4+
"""
5+
6+
7+
def absolute_value_text_1(number: int) -> str:
8+
"""
9+
Creates correct string using arithmetic absolute value.
10+
11+
:param number: the length and type of the output string
12+
:return: a string of pluses or minuses based on the input value
13+
"""
14+
if int((number**2)**0.5) == number: # The number is positive
15+
return '+' * number
16+
else: # The number is negative
17+
return '-' * (-1 * number)
18+
19+
20+
def absolute_value_text_2(number: int) -> str:
21+
"""
22+
Creates correct string using string techniques.
23+
24+
:param number: the length and type of the output string
25+
:return: a string of pluses or minuses based on the input value
26+
"""
27+
if '-' in str(number):
28+
return '-' * (-1 * int(number))
29+
else:
30+
return '+' * int(number)

challenges/how-to-convert-an-integer-to-a-string/solutions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
def reverse(num: int) -> str:
1+
"""
2+
Provides a series of solutions to the challenge provided at the following link:
3+
https://therenegadecoder.com/code/how-to-convert-an-integer-to-a-string-in-python/#challenge
4+
"""
5+
6+
7+
def reverse_1(num: int) -> str:
28
output = ""
39
while num != 0:
410
output += num % 10

0 commit comments

Comments
 (0)