division = lambda a ,b : a/b if b!=0 else None
def division(a, b):if b == 0:return Nonereturn a / b- division = lambda a ,b : a/b if b!=0 else None
import codewars_test as test import random # Random test cases @test.describe("Fixed tests") def fixed_tests(): test.assert_equals(division(random.randint(-1000,1000), 0), None) @test.describe("Random tests") def random_tests(): @test.it("Random tests") def random_test_cases(): for _ in range(100): a = random.randint(-1000, 1000) b = random.randint(-1000, 1000) print(a) print(b) expected = a / b test.assert_equals(division(a,b), expected) print('\n')
- import codewars_test as test
- import random
- # Random test cases
- @test.describe("Fixed tests")
- def fixed_tests():
- test.assert_equals(division(random.randint(-1000,1000), 0), None)
- @test.describe("Random tests")
- def random_tests():
- @test.it("Random tests")
- def random_test_cases():
- for _ in range(100):
- a = random.randint(-1000, 1000)
- b = random.randint(-1000, 1000)
- print(a)
- print(b)
- expected = a / b
test.assert_equals(division(a,b), expected)- test.assert_equals(division(a,b), expected)
- print('\n')
Type checking the
class SeraphKumite: """A class to experiment with changing the instance identifier.""" # Class variable serpent_soul = 0b1100001000 # 776 def __init__(seraph, n): """Initialize the instance with a value n.""" if not isinstance(n,type(seraph.serpent_soul)): raise TypeError(f"Type mismatch, error in creating the instance") seraph.n = n def rejuvenate(seraph): """Check if the instance variable n equals the class variable serpent_soul.""" return seraph.n == SeraphKumite.serpent_soul
- class SeraphKumite:
- """A class to experiment with changing the instance identifier."""
- # Class variable
- serpent_soul = 0b1100001000 # 776
- def __init__(seraph, n):
- """Initialize the instance with a value n."""
- if not isinstance(n,type(seraph.serpent_soul)):
- raise TypeError(f"Type mismatch, error in creating the instance")
- seraph.n = n
- def rejuvenate(seraph):
- """Check if the instance variable n equals the class variable serpent_soul."""
- return seraph.n == SeraphKumite.serpent_soul
import codewars_test as test from solution import SeraphKumite @test.describe("Test True") def test_group(): @test.it("test case True: number equals 776") def test_case(): test.assert_equals(SeraphKumite(776).rejuvenate(), True) test.assert_equals(SeraphKumite(0b1100001000).rejuvenate(), True) test.assert_equals(SeraphKumite(666 + 110).rejuvenate(), True) test.assert_equals(SeraphKumite(1109 - 333).rejuvenate(), True) test.assert_equals(SeraphKumite(abs(-776)).rejuvenate(), True) test.assert_equals(SeraphKumite.serpent_soul == 776, True) @test.describe("Test False") def test_group(): @test.it("test case False: numbers less than 776") def test_case(): for n in range(-776,776): test.assert_equals(SeraphKumite(n).rejuvenate(), False) @test.it("test case False: numbers greater than 776") def test_case(): for n in range(777,1776): test.assert_equals(SeraphKumite(n).rejuvenate(), False) @test.it("test case False: numeric string values") def test_case(): # 🐇🥚 Check out YouTube channel: 3121534312 sample = '3121534312 776' for s in sample: try: test.assert_equals(SeraphKumite(s).rejuvenate(), False) print(s) except TypeError: print('inside the exception') test.assert_equals(True,True)
- import codewars_test as test
- from solution import SeraphKumite
- @test.describe("Test True")
- def test_group():
- @test.it("test case True: number equals 776")
- def test_case():
- test.assert_equals(SeraphKumite(776).rejuvenate(), True)
- test.assert_equals(SeraphKumite(0b1100001000).rejuvenate(), True)
- test.assert_equals(SeraphKumite(666 + 110).rejuvenate(), True)
- test.assert_equals(SeraphKumite(1109 - 333).rejuvenate(), True)
- test.assert_equals(SeraphKumite(abs(-776)).rejuvenate(), True)
- test.assert_equals(SeraphKumite.serpent_soul == 776, True)
- @test.describe("Test False")
- def test_group():
- @test.it("test case False: numbers less than 776")
- def test_case():
- for n in range(-776,776):
- test.assert_equals(SeraphKumite(n).rejuvenate(), False)
- @test.it("test case False: numbers greater than 776")
- def test_case():
- for n in range(777,1776):
- test.assert_equals(SeraphKumite(n).rejuvenate(), False)
- @test.it("test case False: numeric string values")
- def test_case():
- # 🐇🥚 Check out YouTube channel: 3121534312
- sample = '3121534312 776'
- for s in sample:
test.assert_equals(SeraphKumite(s).rejuvenate(), False)- try:
- test.assert_equals(SeraphKumite(s).rejuvenate(), False)
- print(s)
- except TypeError:
- print('inside the exception')
- test.assert_equals(True,True)
'''
Morse Code function - remove match case and use dict for better time complexity
'''
def morse_code(msg):
output = ''
morse_dict = {
'a': '.- ',
'b': '-... ',
'c': '-.-. ',
'd': '-.. ',
'e': '. ',
'f': '..-. ',
'g': '--. ',
'h': '.... ',
'i': '.. ',
'j': '.--- ',
'k': '-.- ',
'l': '.-.. ',
'm': '-- ',
'n': '-. ',
'o': '--- ',
'p': '.--. ',
'q': '--.- ',
'r': '.-. ',
's': '... ',
't': '- ',
'u': '..- ',
'v': '...- ',
'w': '.-- ',
'x': '-..- ',
'y': '-.-- ',
'z': '--.. ',
'0': '----- ',
'1': '.---- ',
'2': '..--- ',
'3': '...-- ',
'4': '....- ',
'5': '..... ',
'6': '-.... ',
'7': '--... ',
'8': '---.. ',
'9': '----. ',
'.': '.-.-.- ',
',': '--..-- ',
"'": '.----. ',
'?': '..--.. ',
':': '---... ',
'-': '-....- ',
'/': '-..-. ',
'[': '-.--. ',
'(': '-.--. ',
']': '-.--.- ',
')': '-.--.- ',
'"': '.-..-. ',
'_': '..--.- ',
'=': '-...- ',
'+': '.-.-. ',
'@': '.--.-. ',
'!': '-.-.-- ',
' ': '/ '
}
for letter in msg:
output += output.join([morse_dict.get(letter)])
return output.rstrip()
''' Morse Code function - remove match case and use dict for better time complexity ''' def morse_code(msg): output = '' morse_dict = { 'a': '.- ', 'b': '-... ', 'c': '-.-. ', 'd': '-.. ', 'e': '. ', 'f': '..-. ', 'g': '--. ', 'h': '.... ', 'i': '.. ', 'j': '.--- ', 'k': '-.- ', 'l': '.-.. ', 'm': '-- ', 'n': '-. ', 'o': '--- ', 'p': '.--. ', 'q': '--.- ', 'r': '.-. ', 's': '... ', 't': '- ', 'u': '..- ', 'v': '...- ', 'w': '.-- ', 'x': '-..- ', 'y': '-.-- ', 'z': '--.. ', '0': '----- ', '1': '.---- ', '2': '..--- ', '3': '...-- ', '4': '....- ', '5': '..... ', '6': '-.... ', '7': '--... ', '8': '---.. ', '9': '----. ', '.': '.-.-.- ', ',': '--..-- ', "'": '.----. ', '?': '..--.. ', ':': '---... ', '-': '-....- ', '/': '-..-. ', '[': '-.--. ', '(': '-.--. ', ']': '-.--.- ', ')': '-.--.- ', '"': '.-..-. ', '_': '..--.- ', '=': '-...- ', '+': '.-.-. ', '@': '.--.-. ', '!': '-.-.-- ', ' ': '/ ' } for letter in msg: output += output.join([morse_dict.get(letter)]) return output.rstrip()
- '''
- Morse Code function - remove match case and use dict for better time complexity
- '''
- def morse_code(msg):
dot, dash = '.', '-'space = ' '- output = ''
for letter in msg:match letter:case 'a':output += ''.join([dot, dash, space])case 'b':output += ''.join([dash, dot, dot, dot, space])case 'c':output += ''.join([dash, dot, dash, dot, space])case 'd':output += ''.join([dash, dot, dot, space])case 'e':output += ''.join([dot, space])case 'f':output += ''.join([dot, dot, dash, dot, space])case 'g':output += ''.join([dash, dash, dot, space])case 'h':output += ''.join([dot, dot, dot, dot, space])case 'i':output += ''.join([dot, dot, space])case 'j':output += ''.join([dot, dash, dash, dash, space])case 'k':output += ''.join([dash, dot, dash, space])case 'l':output += ''.join([dot, dash, dot, dot, space])case 'm':output += ''.join([dash, dash, space])case 'n':output += ''.join([dash, dot, space])case 'o':output += ''.join([dash, dash, dash, space])case 'p':output += ''.join([dot, dash, dash, dot, space])case 'q':output += ''.join([dash, dash, dot, dash, space])case 'r':output += ''.join([dot, dash, dot, space])case 's':output += ''.join([dot, dot, dot, space])case 't':output += ''.join([dash, space])case 'u':output += ''.join([dot, dot, dash, space])case 'v':output += ''.join([dot, dot, dot, dash, space])case 'w':output += ''.join([dot, dash, dash, space])case 'x':output += ''.join([dash, dot, dot, dash, space])case 'y':output += ''.join([dash, dot, dash, dash, space])case 'z':output += ''.join([dash,dash, dot, dot, space])case '0':output += ''.join([dash, dash, dash, dash, dash, space])case '1':output += ''.join([dot, dash, dash, dash, dash, space])case '2':output += ''.join([dot, dot, dash, dash, dash, space])case '3':output += ''.join([dot, dot, dot, dash, dash, space])case '4':output += ''.join([dot, dot, dot, dot, dash, space])case '5':output += ''.join([dot, dot, dot, dot, dot, space])case '6':output += ''.join([dash, dot, dot, dot, dot, space])case '7':output += ''.join([dash, dash, dot, dot, dot, space])case '8':output += ''.join([dash, dash, dash, dot, dot, space])case '9':output += ''.join([dash, dash, dash, dash, dot, space])case '.':output += ''.join([dot, dash, dot, dash, dot, dash,space])case ',':output += ''.join([dash, dash, dot, dot, dash, dash])case "'":output += ''.join([dot, dash, dash, dash, dash, dot])case '?':output += ''.join([dot, dot, dash, dash, dot, dot])case ':':output += ''.join([dash, dash, dash, dot, dot, dot])case '-':output += ''.join([dash, dot, dot, dot, dot, dash,space])case '/':output += ''.join([dash, dot, dot, dash, dot, space])case '[':output += ''.join([dash, dot, dash, dash, dot,space])case '(':output += ''.join([dash, dot, dash, dash, dot,space])case ']':output += ''.join([dash, dot, dash, dash, dot, dash,space])case ')':output += ''.join([dash, dot, dash, dash, dot, dash,space])case '"':output += ''.join([dot, dash, dot, dot, dash, dot])case '_':output += ''.join([dot, dot, dash, dash, dot, dash])case '=':output += ''.join([dash, dot, dot, dot, dash, space])case '+':output += ''.join([dot, dash, dot, dash, dot, space])case '@':output += ''.join([dot, dash, dash, dot, dash, dot, space])case '!':output += ''.join([dash, dot, dash, dot, dash, dash])case ' ':output += '/ '- morse_dict = {
- 'a': '.- ',
- 'b': '-... ',
- 'c': '-.-. ',
- 'd': '-.. ',
- 'e': '. ',
- 'f': '..-. ',
- 'g': '--. ',
- 'h': '.... ',
- 'i': '.. ',
- 'j': '.--- ',
- 'k': '-.- ',
- 'l': '.-.. ',
- 'm': '-- ',
- 'n': '-. ',
- 'o': '--- ',
- 'p': '.--. ',
- 'q': '--.- ',
- 'r': '.-. ',
- 's': '... ',
- 't': '- ',
- 'u': '..- ',
- 'v': '...- ',
- 'w': '.-- ',
- 'x': '-..- ',
- 'y': '-.-- ',
- 'z': '--.. ',
- '0': '----- ',
- '1': '.---- ',
- '2': '..--- ',
- '3': '...-- ',
- '4': '....- ',
- '5': '..... ',
- '6': '-.... ',
- '7': '--... ',
- '8': '---.. ',
- '9': '----. ',
- '.': '.-.-.- ',
- ',': '--..-- ',
- "'": '.----. ',
- '?': '..--.. ',
- ':': '---... ',
- '-': '-....- ',
- '/': '-..-. ',
- '[': '-.--. ',
- '(': '-.--. ',
- ']': '-.--.- ',
- ')': '-.--.- ',
- '"': '.-..-. ',
- '_': '..--.- ',
- '=': '-...- ',
- '+': '.-.-. ',
- '@': '.--.-. ',
- '!': '-.-.-- ',
- ' ': '/ '
- }
- for letter in msg:
- output += output.join([morse_dict.get(letter)])
- return output.rstrip()
def morse_code(msg):
output = ''
morse_dict = {
'a': '.- ',
'b': '-... ',
'c': '-.-. ',
'd': '-.. ',
'e': '. ',
'f': '..-. ',
'g': '--. ',
'h': '.... ',
'i': '.. ',
'j': '.--- ',
'k': '-.- ',
'l': '.-.. ',
'm': '-- ',
'n': '-. ',
'o': '--- ',
'p': '.--. ',
'q': '--.- ',
'r': '.-. ',
's': '... ',
't': '- ',
'u': '..- ',
'v': '...- ',
'w': '.-- ',
'x': '-..- ',
'y': '-.-- ',
'z': '--.. ',
'0': '----- ',
'1': '.---- ',
'2': '..--- ',
'3': '...-- ',
'4': '....- ',
'5': '..... ',
'6': '-.... ',
'7': '--... ',
'8': '---.. ',
'9': '----. ',
'.': '.-.-.- ',
',': '--..-- ',
"'": '.----. ',
'?': '..--.. ',
':': '---... ',
'-': '-....- ',
'/': '-..-. ',
'[': '-.--. ',
'(': '-.--. ',
']': '-.--.- ',
')': '-.--.- ',
'"': '.-..-. ',
'_': '..--.- ',
'=': '-...- ',
'+': '.-.-. ',
'@': '.--.-. ',
'!': '-.-.-- ',
' ': '/ '
}
for letter in msg.lower():
output += output.join([morse_dict.get(letter)])
return output.rstrip()
import codewars_test as test from solution import morse_code # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): print(morse_code('sos')) test.assert_equals(morse_code('sos'), '... --- ...' ) print(morse_code('hello world')) test.assert_equals(morse_code('hello world'),'.... . .-.. .-.. --- / .-- --- .-. .-.. -..') print(morse_code('you passed!')) test.assert_equals(morse_code('you passed!'), '-.-- --- ..- / .--. .- ... ... . -.. -.-.--' ) print(morse_code('1+1=2')) test.assert_equals(morse_code('1+1=2'), '.---- .-.-. .---- -...- ..---' ) print(morse_code('(1+2)=5?')) test.assert_equals(morse_code('(1+2)=5?'), '-.--. .---- .-.-. ..--- -.--.- -...- ..... ..--..' ) print(morse_code('seraph776@codewarz.com')) test.assert_equals(morse_code('seraph776@codewarz.com'), '... . .-. .- .--. .... --... --... -.... .--.-. -.-. --- -.. . .-- .- .-. --.. .-.-.- -.-. --- --' ) print(morse_code('lorem ipsum is simply dummy text of the printing and typesetting industry.')) test.assert_equals(morse_code('lorem ipsum is simply dummy text of the printing and typesetting industry.'), '.-.. --- .-. . -- / .. .--. ... ..- -- / .. ... / ... .. -- .--. .-.. -.-- / -.. ..- -- -- -.-- / - . -..- - / --- ..-. / - .... . / .--. .-. .. -. - .. -. --. / .- -. -.. / - -.-- .--. . ... . - - .. -. --. / .. -. -.. ..- ... - .-. -.-- .-.-.-' )
- import codewars_test as test
- from solution import morse_code
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- print(morse_code('sos'))
- test.assert_equals(morse_code('sos'), '... --- ...' )
- print(morse_code('hello world'))
- test.assert_equals(morse_code('hello world'),'.... . .-.. .-.. --- / .-- --- .-. .-.. -..')
- print(morse_code('you passed!'))
- test.assert_equals(morse_code('you passed!'), '-.-- --- ..- / .--. .- ... ... . -.. -.-.--' )
- print(morse_code('1+1=2'))
- test.assert_equals(morse_code('1+1=2'), '.---- .-.-. .---- -...- ..---' )
- print(morse_code('(1+2)=5?'))
- test.assert_equals(morse_code('(1+2)=5?'), '-.--. .---- .-.-. ..--- -.--.- -...- ..... ..--..' )
- print(morse_code('seraph776@codewarz.com'))
- test.assert_equals(morse_code('seraph776@codewarz.com'), '... . .-. .- .--. .... --... --... -.... .--.-. -.-. --- -.. . .-- .- .-. --.. .-.-.- -.-. --- --' )
test.assert_equals(morse_code('lorem ipsum is simply dummy text of the printing and typesetting industry.'), '.-.. --- .-. . -- / .. .--. ... ..- -- / .. ... / ... .. -- .--. .-.. -.-- / -.. ..- -- -- -.-- / - . -..- - / --- ..-. / - .... . / .--. .-. .. -. - .. -. --. / .- -. -.. / - -.-- .--. . ... . - - .. -. --. / .. -. -.. ..- ... - .-. -.-- .-.-.-' )- print(morse_code('lorem ipsum is simply dummy text of the printing and typesetting industry.'))
- test.assert_equals(morse_code('lorem ipsum is simply dummy text of the printing and typesetting industry.'),
- '.-.. --- .-. . -- / .. .--. ... ..- -- / .. ... / ... .. -- .--. .-.. -.-- / -.. ..- -- -- -.-- / - . -..- - / --- ..-. / - .... . / .--. .-. .. -. - .. -. --. / .- -. -.. / - -.-- .--. . ... . - - .. -. --. / .. -. -.. ..- ... - .-. -.-- .-.-.-' )