-
Notifications
You must be signed in to change notification settings - Fork 1
/
045_Capitalization and Mutability.py
68 lines (43 loc) · 1.48 KB
/
045_Capitalization and Mutability.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
Codewars Coding Challenge
Capitalization and Mutability
Your coworker was supposed to write a simple helper function to capitalize a string (that contains a single word) before they went on vacation.
Unfortunately, they have now left and the code they gave you doesn't work. Fix the helper function they wrote so that it works as intended (i.e. it must make the first character in the string upper case).
The string will always start with a letter and will never be empty.
Examples:
"hello" --> "Hello"
"Hello" --> "Hello" (the first letter was already capitalized)
"a" --> "A"
def capitalize_word (word : str) -> str:
word[0] = word[0].upper()
return word
https://www.codewars.com/kata/595970246c9b8fa0a8000086/train/python
"""
# My Solution
def capitalize_word (word : str) -> str:
return word[0].upper() + word[1:]
print(capitalize_word("hello world"))
"""
Sample Tests
import codewars_test as test
try:
from solution import capitalizeWord as capitalize_word
except ImportError:
from solution import capitalize_word
@test.describe("Fixed Tests")
def fixed_tests():
@test.it('Basic Test Cases')
def basic_test_cases():
test.assert_equals(capitalize_word('word'), 'Word')
test.assert_equals(capitalize_word('i'), 'I')
test.assert_equals(capitalize_word('glasswear'), 'Glasswear')
"""
"""
Perfect Solutions From Codewars
=1=
def capitalizeWord(word):
return word.capitalize()
=2=
def capitalizeWord(s):
return s.title()
"""