-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path018_Switch it Up!.py
67 lines (39 loc) · 1.24 KB
/
018_Switch it Up!.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
"""
Codewars Coding Challenge
Switch it Up!
When provided with a number between 0-9, return it in words.
Input :: 1
Output :: "One".
If your language supports it, try using a switch statement.
https://www.codewars.com/kata/5808dcb8f0ed42ae34000031/train/python
"""
# My Solution
def switch_it_up(number):
name_num = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]
return name_num[number]
# def switch_it_up(number):
# result = ""
# arr_number = [0,1,2,3,4,5,6,7,8,9]
# name_num = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]
# if number in arr_number:
# result = name_num[number]
# return result
# Sample test
"""
import codewars_test as test
from solution import switch_it_up
@test.describe("Fixed Tests")
def fixed_tests():
@test.it('Basic Test Cases')
def basic_test_cases():
test.assert_equals(switch_it_up(0), "Zero")
test.assert_equals(switch_it_up(9), "Nine")
"""
"""
PERFECT SOLUTION FROM CODEWARS
=1=
def switch_it_up(n):
return ['Zero','One','Two','Three','Four','Five','Six','Seven','Eight','Nine'][n]
=2=
switch_it_up=lambda x:"Zero One Two Three Four Five Six Seven Eight Nine".split()[x]
"""